]> git.tdb.fi Git - libs/gl.git/blob - source/matrix.h
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / matrix.h
1 #ifndef MSP_GL_MATRIX_H_
2 #define MSP_GL_MATRIX_H_
3
4 #include <vector>
5 #include <msp/geometry/angle.h>
6 #include <msp/linal/squarematrix.h>
7 #include "gl.h"
8 #include "vector.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Matrix: public LinAl::SquareMatrix<float, 4>
14 {
15 private:
16         typedef LinAl::SquareMatrix<float, 4> Base;
17         typedef Geometry::Angle<float> Angle;
18
19 public:
20         Matrix();
21         Matrix(const float *);
22         Matrix(const LinAl::Matrix<float, 4, 4> &);
23
24         const float *data() const { return &Base::operator()(0, 0); }
25
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 &);
38
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         Matrix operator*(float s) const { return static_cast<const Base &>(*this)*s; }
42         Matrix &operator*=(float s) { Base::operator*=(s); return *this; }
43         Vector4 operator*(const Vector4 &v) const { return static_cast<const Base &>(*this)*v; }
44         Vector3 operator*(const Vector3 &v) const { return ((*this)*compose(v, 1.0f)).slice<3>(0); }
45         float operator[](unsigned) const;
46
47         static Matrix translation(float x, float y, float z) { return translation(Vector3(x, y, z)); }
48         static Matrix translation(const Vector3 &);
49         static Matrix rotation(const Angle &a, float x, float y, float z) { return rotation(a, Vector3(x, y, z)); }
50         static Matrix rotation(const Angle &, const Vector3 &);
51         static Matrix rotation(float a, float x, float y, float z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
52         static Matrix rotation(float a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
53         static Matrix rotation_deg(float a, float x, float y, float z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
54         static Matrix rotation_deg(float a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
55         static Matrix scaling(float s) { return scaling(Vector3(s, s, s)); }
56         static Matrix scaling(float x, float y, float z) { return scaling(Vector3(x, y, z)); }
57         static Matrix scaling(const Vector3 &);
58
59         static Matrix ortho(float, float, float, float, float, float);
60         static Matrix ortho_centered(float, float);
61         static Matrix ortho_bottomleft(float, float);
62         static Matrix ortho_topleft(float, float);
63         static Matrix frustum(float, float, float, float, float, float);
64         static Matrix frustum_centered(float, float, float, float);
65         static Matrix perspective(const Angle &, float, float, float);
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif