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 &, const Vector3 &);
31 void rotate(double a, double x, double y, double z) { rotate(Angle::from_radians(a), Vector3(x, y, z)); }
32 void rotate(double a, const Vector3 &x) { rotate(Angle::from_radians(a), x); }
33 void rotate_deg(double a, double x, double y, double z) { rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
34 void rotate_deg(double a, const Vector3 & x) { rotate(Angle::from_degrees(a), x); }
35 void scale(double s) { scale(Vector3(s, s, s)); }
36 void scale(double x, double y, double 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 double operator[](unsigned) const;
45 static Matrix translation(double x, double y, double z) { return translation(Vector3(x, y, z)); }
46 static Matrix translation(const Vector3 &);
47 static Matrix rotation(const Angle &a, const Vector3 &);
48 static Matrix rotation(double a, double x, double y, double z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
49 static Matrix rotation(double a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
50 static Matrix rotation_deg(double a, double x, double y, double z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
51 static Matrix rotation_deg(double a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
52 static Matrix scaling(double s) { return scaling(Vector3(s, s, s)); }
53 static Matrix scaling(double x, double y, double z) { return scaling(Vector3(x, y, z)); }
54 static Matrix scaling(const Vector3 &);
56 static Matrix ortho(double, double, double, double, double, double);
57 static Matrix ortho_centered(double, double);
58 static Matrix ortho_bottomleft(double, double);
59 static Matrix ortho_topleft(double, double);
60 static Matrix frustum(double, double, double, double, double, double);
61 static Matrix frustum_centered(double, double, double, double);
62 static Matrix perspective(double, double, double, double);
74 Push(MatrixStack &s): stack(s) { stack.push(); }
75 ~Push() { stack.pop(); }
80 std::vector<Matrix> matrices;
82 static GLenum current_mode;
84 MatrixStack(const MatrixStack &);
85 MatrixStack &operator=(const MatrixStack &);
90 const Matrix &top() const;
91 void load(const Matrix &);
92 void multiply(const Matrix &);
96 virtual void update();
99 MatrixStack &operator=(const Matrix &);
100 MatrixStack &operator*=(const Matrix &);
102 static MatrixStack &modelview();
103 static MatrixStack &projection();