Unofficial OpenGL Software Development Kit: C:/Projects/distro/glsdk_0_5_1/glutil/include/glutil/MatrixStack.h Source File

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MatrixStack.h
Go to the documentation of this file.
1
2 #ifndef MATRIX_STACK_UTIL_H
3 #define MATRIX_STACK_UTIL_H
4
10 #include <stack>
11 #include <vector>
12 #include <glm/glm.hpp>
13 #include <glm/gtc/type_ptr.hpp>
14
15 namespace glutil
16 {
19
43 class MatrixStack
44 {
45 public:
47 MatrixStack()
48 : m_currMatrix(1)
49 {}
50
52 explicit MatrixStack(const glm::mat4 &initialMatrix)
53 : m_currMatrix(initialMatrix)
54 {}
55
61
62
64 void Push()
65 {
66 m_stack.push(m_currMatrix);
67 }
68
70 void Pop()
71 {
72 m_currMatrix = m_stack.top();
73 m_stack.pop();
74 }
75
81 void Reset() { m_currMatrix = m_stack.top(); }
82
84 const glm::mat4 &Top() const
85 {
86 return m_currMatrix;
87 }
89
98
99
101 void Rotate(const glm::vec3 axis, float angDegCCW);
102
104 void RotateRadians(const glm::vec3 axis, float angRadCCW);
105
107 void RotateX(float angDegCCW);
109 void RotateY(float angDegCCW);
111 void RotateZ(float angDegCCW);
113
119
120
122 void Scale(const glm::vec3 &scaleVec);
124 void Scale(float scaleX, float scaleY, float scaleZ) {Scale(glm::vec3(scaleX, scaleY, scaleZ));}
126 void Scale(float uniformScale) {Scale(glm::vec3(uniformScale));}
128
134
135
137 void Translate(const glm::vec3 &offsetVec);
139 void Translate(float transX, float transY, float transZ) {Translate(glm::vec3(transX, transY, transZ));}
141
148
149
159 void LookAt(const glm::vec3 &cameraPos, const glm::vec3 &lookatPos, const glm::vec3 &upDir);
161
173
174
186 void Perspective(float degFOV, float aspectRatio, float zNear, float zFar);
187
198 void Orthographic(float left, float right, float bottom, float top, float zNear = -1.0f, float zFar = 1.0f);
199
216 void PixelPerfectOrtho(glm::ivec2 size, glm::vec2 depthRange, bool isTopLeft = true);
218
225
226
228 void ApplyMatrix(const glm::mat4 &theMatrix);
230 MatrixStack &operator*=(const glm::mat4 &theMatrix) {ApplyMatrix(theMatrix); return *this;}
232
239
240
242 void SetMatrix(const glm::mat4 &theMatrix);
244 void SetIdentity();
246
247 private:
248 std::stack<glm::mat4, std::vector<glm::mat4> > m_stack;
249 glm::mat4 m_currMatrix;
250 };
251
264 class PushStack
265 {
266 public:
268 PushStack(MatrixStack &stack)
269 : m_stack(stack)
270 {
271 m_stack.Push();
272 }
273
275 ~PushStack()
276 {
277 m_stack.Pop();
278 }
279
285 void ResetStack()
286 {
287 m_stack.Reset();
288 }
289
290 private:
291 MatrixStack &m_stack;
292
293 PushStack(const PushStack &);
294 PushStack &operator=(const PushStack&);
295 };
297 }
298
299
300
301 #endif //MATRIX_STACK_UTIL_H