1 #ifndef MSP_GL_MATRIX_H_
2 #define MSP_GL_MATRIX_H_
5 #include <msp/geometry/angle.h>
6 #include <msp/linal/squarematrix.h>
13 class Matrix: public LinAl::SquareMatrix<float, 4>
16 typedef LinAl::SquareMatrix<float, 4> Base;
17 typedef Geometry::Angle<float> Angle;
21 Matrix(const float *);
22 Matrix(const LinAl::Matrix<float, 4, 4> &);
24 const float *data() const { return &Base::operator()(0, 0); }
26 void multiply(const Matrix &);
27 void translate(float x, float y, float z) { translate(Vector3(x, y, z)); }
28 void translate(const Vector3 &);
29 void rotate(const Angle &a, float x, float y, float z) { rotate(a, Vector3(x, y, z)); }
30 void rotate(const Angle &, const Vector3 &);
31 void rotate(float a, float x, float y, float z) { rotate(Angle::from_radians(a), Vector3(x, y, z)); }
32 void rotate(float a, const Vector3 &x) { rotate(Angle::from_radians(a), x); }
33 void rotate_deg(float a, float x, float y, float z) { rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
34 void rotate_deg(float a, const Vector3 & x) { rotate(Angle::from_degrees(a), x); }
35 void scale(float s) { scale(Vector3(s, s, s)); }
36 void scale(float x, float y, float z) { scale(Vector3(x, y, z)); }
37 void scale(const Vector3 &);
39 Matrix operator*(const Matrix &) const;
40 Matrix &operator*=(const Matrix &);
41 Vector4 operator*(const Vector4 &) const;
42 Vector3 operator*(const Vector3 &) const;
43 float operator[](unsigned) const;
45 static Matrix translation(float x, float y, float z) { return translation(Vector3(x, y, z)); }
46 static Matrix translation(const Vector3 &);
47 static Matrix rotation(const Angle &a, float x, float y, float z) { return rotation(a, Vector3(x, y, z)); }
48 static Matrix rotation(const Angle &, const Vector3 &);
49 static Matrix rotation(float a, float x, float y, float z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
50 static Matrix rotation(float a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
51 static Matrix rotation_deg(float a, float x, float y, float z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
52 static Matrix rotation_deg(float a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
53 static Matrix scaling(float s) { return scaling(Vector3(s, s, s)); }
54 static Matrix scaling(float x, float y, float z) { return scaling(Vector3(x, y, z)); }
55 static Matrix scaling(const Vector3 &);
57 static Matrix ortho(float, float, float, float, float, float);
58 static Matrix ortho_centered(float, float);
59 static Matrix ortho_bottomleft(float, float);
60 static Matrix ortho_topleft(float, float);
61 static Matrix frustum(float, float, float, float, float, float);
62 static Matrix frustum_centered(float, float, float, float);
63 static Matrix perspective(const Angle &, float, float, float);
75 Push(MatrixStack &s): stack(s) { stack.push(); }
76 ~Push() { stack.pop(); }
81 std::vector<Matrix> matrices;
83 static GLenum current_mode;
85 MatrixStack(const MatrixStack &);
86 MatrixStack &operator=(const MatrixStack &);
91 const Matrix &top() const;
92 void load(const Matrix &);
93 void multiply(const Matrix &);
97 virtual void update();
100 MatrixStack &operator=(const Matrix &);
101 MatrixStack &operator*=(const Matrix &);
103 static MatrixStack &modelview();
104 static MatrixStack &projection();