From af7bdaa10ee71a319dc55c3c7556fa43a95c9dc9 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 2 Apr 2019 21:45:33 +0800 Subject: *misc --- source/modules/asura-core/graphics/matrix_stack.h | 82 +++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 source/modules/asura-core/graphics/matrix_stack.h (limited to 'source/modules/asura-core/graphics/matrix_stack.h') diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h new file mode 100644 index 0000000..1923b30 --- /dev/null +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -0,0 +1,82 @@ +#ifndef __ASURA_MATRIX_STACK_H__ +#define __ASURA_MATRIX_STACK_H__ + +#include +#include + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// 栈的矩阵深度。 + /// +#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB + + /// + /// 保存栈状态,用来恢复之前的状态。栈中的一个矩阵stack[i]的值是stack[0]*..*stack[i-1] + /// 的值,并附加一系列transform。 + /// + /// TODO: template MatrixStack + /// + class MatrixStack + { + public: + + MatrixStack(); + ~MatrixStack(); + + /// + /// 对栈顶元素的操作只能通过以下函数实现 + /// + void LoadIdentity(); + bool Push(); + bool Pop(); + + AEMath::Matrix44& GetTop(); + void GetTop(asura_out AEMath::Matrix44& mat44); + + void LoadMatrix(const AEMath::Matrix44& mat44); + void MultMatrix(const AEMath::Matrix44& mat44); + + /// + /// 仿射变换 + /// + void Rotate(float angle, float x, float y, float z); + void Translate(float x, float y, float z); + void Scale(float x, float y, float z); + + /// + /// 投影变换 + /// + void Ortho(float left, float right, float bottom, float top, float near, float far); + //void Perspective(float fov, float aspect, float near, float far); + //void Frustum(float left, float right, float top, float bottom, float near, float far); + //void LookAt(float x, float y, float z, float cx, float cy, float cz, float ux, float uy, float uz); + + /// + /// 获得栈顶的索引,范围在0~ASURA_MAX_MATRIX_STACK_DEPTH-1 + /// + uint GetTopIndex(); + + /// + /// 获得最大栈容量,即ASURA_MAX_MATRIX_STACK_DEPTH + /// + uint GetCapacity(); + + private: + + AEMath::Matrix44 mStack[ASURA_MAX_MATRIX_STACK_DEPTH]; + + /// + /// 栈顶索引,0~ASURA_MAX_MATRIX_STACK_DEPTH-1 + /// + uint8 top; + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0