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<double, 4>
16 typedef LinAl::SquareMatrix<double, 4> Base;
17 typedef Geometry::Angle<double> Angle;
21 Matrix(const float *);
22 Matrix(const double *);
23 Matrix(const LinAl::Matrix<double, 4, 4> &);
25 const double *data() const { return &Base::operator()(0, 0); }
27 void multiply(const Matrix &);
28 void translate(double x, double y, double z) { translate(Vector3(x, y, z)); }
29 void translate(const Vector3 &);
30 void rotate(const Angle &a, double x, double y, double z) { rotate(a, Vector3(x, y, z)); }
31 void rotate(const Angle &, const Vector3 &);
32 void rotate(double a, double x, double y, double z) { rotate(Angle::from_radians(a), Vector3(x, y, z)); }
33 void rotate(double a, const Vector3 &x) { rotate(Angle::from_radians(a), x); }
34 void rotate_deg(double a, double x, double y, double z) { rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
35 void rotate_deg(double a, const Vector3 & x) { rotate(Angle::from_degrees(a), x); }
36 void scale(double s) { scale(Vector3(s, s, s)); }
37 void scale(double x, double y, double z) { scale(Vector3(x, y, z)); }
38 void scale(const Vector3 &);
40 Matrix operator*(const Matrix &) const;
41 Matrix &operator*=(const Matrix &);
42 Vector4 operator*(const Vector4 &) const;
43 Vector3 operator*(const Vector3 &) const;
44 double operator[](unsigned) const;
46 static Matrix translation(double x, double y, double z) { return translation(Vector3(x, y, z)); }
47 static Matrix translation(const Vector3 &);
48 static Matrix rotation(const Angle &a, double x, double y, double z) { return rotation(a, Vector3(x, y, z)); }
49 static Matrix rotation(const Angle &, const Vector3 &);
50 static Matrix rotation(double a, double x, double y, double z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
51 static Matrix rotation(double a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
52 static Matrix rotation_deg(double a, double x, double y, double z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
53 static Matrix rotation_deg(double a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
54 static Matrix scaling(double s) { return scaling(Vector3(s, s, s)); }
55 static Matrix scaling(double x, double y, double z) { return scaling(Vector3(x, y, z)); }
56 static Matrix scaling(const Vector3 &);
58 static Matrix ortho(double, double, double, double, double, double);
59 static Matrix ortho_centered(double, double);
60 static Matrix ortho_bottomleft(double, double);
61 static Matrix ortho_topleft(double, double);
62 static Matrix frustum(double, double, double, double, double, double);
63 static Matrix frustum_centered(double, double, double, double);
64 static Matrix perspective(const Angle &, double, double, double);
76 Push(MatrixStack &s): stack(s) { stack.push(); }
77 ~Push() { stack.pop(); }
82 std::vector<Matrix> matrices;
84 static GLenum current_mode;
86 MatrixStack(const MatrixStack &);
87 MatrixStack &operator=(const MatrixStack &);
92 const Matrix &top() const;
93 void load(const Matrix &);
94 void multiply(const Matrix &);
98 virtual void update();
101 MatrixStack &operator=(const Matrix &);
102 MatrixStack &operator*=(const Matrix &);
104 static MatrixStack &modelview();
105 static MatrixStack &projection();