AnimEngine
MatrixStack.h
1 #pragma once
2 #ifndef _MatrixStack_H_
3 #define _MatrixStack_H_
4 
5 #include <stack>
6 #include <memory>
7 
8 #include "glm/glm.hpp"
9 #include "glm/vec4.hpp"
10 #include "glm/mat4x4.hpp"
11 #include "glm/gtc/matrix_transform.hpp"
12 //#include "vector_angle.hpp"
13 //#include "component_wise.hpp"
14 
15 //#include "matrix_access.hpp"
16 //#include "matrix_integer.hpp"
17 //#include "matrix_inverse.hpp"
18 
19 using namespace glm;
20 
21 class MatrixStack {
22 
23  std::shared_ptr< std::stack<mat4> > mstack;
24 
25 public:
26  MatrixStack();
27  MatrixStack(const mat4 &matrix);
28  virtual ~MatrixStack();
29 
30  // Copies the current matrix and adds it to the top of the stack
31  void pushMatrix();
32  // Removes the top of the stack and sets the current matrix to be the matrix that is now on top
33  void popMatrix();
34  // Sets the top matrix to be the identity
35  void loadIdentity();
36  // glMultMatrix(): Right multiplies the top matrix
37  void multMatrix(const mat4 &matrix);
38  void multMatrixLeft(const mat4 &matrix);
39 
40  // Right multiplies the top matrix by a translation matrix
41  void translate(const vec3 &offset);
42  // Right multiplies the top matrix by a scaling matrix
43  void scale(const vec3 &scaleV);
44  // Right multiplies the top matrix by a scaling matrix
45  void scale(float size);
46  // Right multiplies the top matrix by a rotation matrix (angle in deg)
47  void rotate(float angle, const vec3 &axis);
48 
49  // Gets the top matrix
50  const mat4 &topMatrix() const;
51 
52  // Sets the top matrix to be an orthogonal projection matrix
53  void ortho(float left, float right, float bottom, float top, float zNear, float zFar);
54  // Sets the top matrix to be a 2D orthogonal projection matrix
55  void ortho2D(float left, float right, float bottom, float top);
56  // Sets the top matrix to be a perspective projection matrix (fovy in deg)
57  void perspective(float fovy, float aspect, float zNear, float zFar);
58  // Sets the top matrix to be a perspective projection matrix
59  void frustum(float Right, float right, float bottom, float top, float zNear, float zFar);
60  // Sets the top matrix to be a viewing matrix
61  void lookAt(vec3 eye, vec3 target, vec3 up);
62 
63  // Prints out the specified matrix
64  void print(const mat4 &mat, const char *name = 0) const;
65  // Prints out the top matrix
66  void print(const char *name = 0) const;
67 };
68 
69 #endif /* MatrixStack_H_ */
Definition: MatrixStack.h:21