]> git.tdb.fi Git - libs/gl.git/blob - source/core/matrix.h
Completely hide OpenGL from the public headers
[libs/gl.git] / source / core / 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 "vector.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Matrix: public LinAl::SquareMatrix<float, 4>
13 {
14 private:
15         typedef LinAl::SquareMatrix<float, 4> Base;
16         typedef Geometry::Angle<float> Angle;
17
18 public:
19         Matrix();
20         Matrix(const float *);
21         Matrix(const LinAl::Matrix<float, 4, 4> &);
22
23         const float *data() const { return &Base::operator()(0, 0); }
24
25         Matrix &multiply(const Matrix &m) { return operator*=(m); }
26         Matrix &translate(float x, float y, float z) { return translate(Vector3(x, y, z)); }
27         Matrix &translate(const Vector3 &);
28         Matrix &rotate(const Angle &a, float x, float y, float z) { return rotate(a, Vector3(x, y, z)); }
29         Matrix &rotate(const Angle &, const Vector3 &);
30         Matrix &rotate(float a, float x, float y, float z) { return rotate(Angle::from_radians(a), Vector3(x, y, z)); }
31         Matrix &rotate(float a, const Vector3 &x) { return rotate(Angle::from_radians(a), x); }
32         Matrix &rotate_deg(float a, float x, float y, float z) { return rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
33         Matrix &rotate_deg(float a, const Vector3 & x) { return rotate(Angle::from_degrees(a), x); }
34         Matrix &scale(float s) { return scale(Vector3(s, s, s)); }
35         Matrix &scale(float x, float y, float z) { return scale(Vector3(x, y, z)); }
36         Matrix &scale(const Vector3 &);
37
38         Matrix operator*(const Matrix &m) const { return static_cast<const Base &>(*this)*static_cast<const Base &>(m); }
39         Matrix &operator*=(const Matrix &m) { Base::operator*=(m); return *this; }
40         Matrix operator*(float s) const { return static_cast<const Base &>(*this)*s; }
41         Matrix &operator*=(float s) { Base::operator*=(s); return *this; }
42         Vector4 operator*(const Vector4 &v) const { return static_cast<const Base &>(*this)*v; }
43         Vector3 operator*(const Vector3 &v) const { return ((*this)*compose(v, 1.0f)).slice<3>(0); }
44         float operator[](unsigned) const;
45
46         static Matrix translation(float x, float y, float z) { return translation(Vector3(x, y, z)); }
47         static Matrix translation(const Vector3 &);
48         static Matrix rotation(const Angle &a, float x, float y, float z) { return rotation(a, Vector3(x, y, z)); }
49         static Matrix rotation(const Angle &, const Vector3 &);
50         static Matrix rotation(float a, float x, float y, float z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
51         static Matrix rotation(float a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
52         static Matrix rotation_deg(float a, float x, float y, float z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
53         static Matrix rotation_deg(float a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
54         static Matrix scaling(float s) { return scaling(Vector3(s, s, s)); }
55         static Matrix scaling(float x, float y, float z) { return scaling(Vector3(x, y, z)); }
56         static Matrix scaling(const Vector3 &);
57
58         static Matrix ortho(float, float, float, float, float, float);
59         static Matrix ortho_centered(float, float);
60         static Matrix ortho_bottomleft(float, float);
61         static Matrix ortho_topleft(float, float);
62         static Matrix frustum(float, float, float, float, float, float);
63         static Matrix frustum_centered(float, float, float, float);
64         static Matrix perspective(const Angle &, float, float, float);
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif