Ocular Engine
MatrixStack.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_MATRIX_STACK__H__
19 #define __H__OCULAR_MATH_MATRIX_STACK__H__
20 
21 #include "Matrix4x4.hpp"
22 #include "Exceptions/Exception.hpp"
23 #include <stack>
24 
25 //------------------------------------------------------------------------------------------
26 
31 namespace Ocular
32 {
37  namespace Math
38  {
43  {
44  public:
45 
46  MatrixStack()
47  {
48 
49  }
50 
51  ~MatrixStack()
52  {
53 
54  }
55 
56  //------------------------------------------------------------------------------
57 
61  void loadIdentity()
62  {
63  m_Stack.push(Matrix4x4());
64  }
65 
75  void combine(Matrix4x4 const matrix)
76  {
77  if(empty())
78  {
79  m_Stack.push(matrix);
80  }
81  else
82  {
83  Matrix4x4 top;
84  pop(&top);
85 
86  top *= matrix;
87 
88  m_Stack.push(top);
89  }
90  }
91 
98  void push(Matrix4x4 const matrix)
99  {
100  m_Stack.push(matrix);
101  }
102 
110  bool pop(Matrix4x4* matrix)
111  {
112  bool result = false;
113 
114  if(!empty())
115  {
116  if(matrix != nullptr)
117  {
118  *matrix = m_Stack.top();
119  }
120 
121  m_Stack.pop();
122  result = true;
123  }
124 
125  return result;
126  }
127 
134  bool peek(Matrix4x4* matrix)
135  {
136  bool result = false;
137 
138  if(!empty())
139  {
140  if(matrix != nullptr)
141  {
142  *matrix = m_Stack.top();
143  }
144 
145  result = true;
146  }
147 
148  return result;
149  }
150 
154  bool empty()
155  {
156  return m_Stack.empty();
157  }
158 
162  unsigned size()
163  {
164  return static_cast<unsigned>(m_Stack.size());
165  }
166 
170  void clear()
171  {
172  while(!m_Stack.empty())
173  {
174  m_Stack.pop();
175  }
176  }
177 
178  protected:
179 
180  private:
181 
182  std::stack<Matrix4x4> m_Stack;
183  };
184  }
188 }
193 //------------------------------------------------------------------------------------------
194 
195 #endif
void combine(Matrix4x4 const matrix)
Definition: MatrixStack.hpp:75
unsigned size()
Definition: MatrixStack.hpp:162
void push(Matrix4x4 const matrix)
Definition: MatrixStack.hpp:98
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
bool empty()
Definition: MatrixStack.hpp:154
void loadIdentity()
Definition: MatrixStack.hpp:61
bool pop(Matrix4x4 *matrix)
Definition: MatrixStack.hpp:110
void clear()
Definition: MatrixStack.hpp:170
Definition: MatrixStack.hpp:42
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
bool peek(Matrix4x4 *matrix)
Definition: MatrixStack.hpp:134