From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-core/Graphics/MatrixStack.cpp | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 source/modules/asura-core/Graphics/MatrixStack.cpp (limited to 'source/modules/asura-core/Graphics/MatrixStack.cpp') diff --git a/source/modules/asura-core/Graphics/MatrixStack.cpp b/source/modules/asura-core/Graphics/MatrixStack.cpp new file mode 100644 index 0000000..987d29c --- /dev/null +++ b/source/modules/asura-core/Graphics/MatrixStack.cpp @@ -0,0 +1,75 @@ +#include "MatrixStack.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +MatrixStack::MatrixStack() + : top(0) +{ + // 栈的最下面初始就是栈顶,并用此保证栈永远非空(即可以取值) + m_Stack[top].SetIdentity(); +} + +MatrixStack::~MatrixStack() +{ +} + +void MatrixStack::LoadIdentity() +{ + m_Stack[top].SetIdentity(); +} + +bool MatrixStack::Push() +{ + if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) + return false; + ++top; + m_Stack[top] = m_Stack[top - 1]; + return true; +} + +bool MatrixStack::Pop() +{ + if (top == 0) + return false; + --top; + return true; +} + +AEMath::Matrix44& MatrixStack::GetTop() +{ + return m_Stack[top]; +} + +uint MatrixStack::GetTopIndex() +{ + return top; +} + +uint MatrixStack::GetCapacity() +{ + return ASURA_MAX_MATRIX_STACK_DEPTH; +} + +void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) +{ + m_Stack[this->top].Ortho(left, right, bottom, top, near, far); +} + +void MatrixStack::Rotate(float angle) +{ + m_Stack[top].Rotate(angle); +} + +void MatrixStack::Translate(float x, float y) +{ + m_Stack[top].Translate(x, y); +} + +void MatrixStack::Scale(float x, float y) +{ + m_Stack[top].Scale(x, y); +} + +namespace_end +namespace_end \ No newline at end of file -- cgit v1.1-26-g67d0