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 Matrix &multiply(const Matrix &m) { return operator*=(m); }
27 Matrix &translate(float x, float y, float z) { return translate(Vector3(x, y, z)); }
28 Matrix &translate(const Vector3 &);
29 Matrix &rotate(const Angle &a, float x, float y, float z) { return rotate(a, Vector3(x, y, z)); }
30 Matrix &rotate(const Angle &, const Vector3 &);
31 Matrix &rotate(float a, float x, float y, float z) { return rotate(Angle::from_radians(a), Vector3(x, y, z)); }
32 Matrix &rotate(float a, const Vector3 &x) { return rotate(Angle::from_radians(a), x); }
33 Matrix &rotate_deg(float a, float x, float y, float z) { return rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
34 Matrix &rotate_deg(float a, const Vector3 & x) { return rotate(Angle::from_degrees(a), x); }
35 Matrix &scale(float s) { return scale(Vector3(s, s, s)); }
36 Matrix &scale(float x, float y, float z) { return scale(Vector3(x, y, z)); }
37 Matrix &scale(const Vector3 &);
39 Matrix operator*(const Matrix &m) const { return static_cast<const Base &>(*this)*static_cast<const Base &>(m); }
40 Matrix &operator*=(const Matrix &m) { Base::operator*=(m); return *this; }
41 Vector4 operator*(const Vector4 &v) const { return static_cast<const Base &>(*this)*v; }
42 Vector3 operator*(const Vector3 &v) const { return ((*this)*compose(v, 1.0f)).slice<3>(0); }
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);