3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_MATRIX_H_
9 #define MSP_GL_MATRIX_H_
35 Matrix(const float *);
36 Matrix(const double *);
41 const double *data() const { return matrix; }
43 void multiply(const Matrix &);
44 void translate(double, double, double);
45 void translate(const Vector3 &t) { translate(t.x, t.y, t.z); }
46 void rotate(double, double, double, double);
47 void rotate(double a, const Vector3 &x) { rotate(a, x.x, x.y, x.z); }
48 void rotate_deg(double, double, double, double);
49 void rotate_deg(double a, const Vector3 & x) { rotate_deg(a, x.x, x.y, x.z); }
51 void scale(double, double, double);
53 Matrix operator*(const Matrix &) const;
54 Matrix &operator*=(const Matrix &);
55 Vector4 operator*(const Vector4 &) const;
56 double operator[](unsigned) const;
58 static Matrix translation(double, double, double);
59 static Matrix translation(const Vector3 &t) { return translation(t.x, t.y, t.z); }
60 static Matrix rotation(double, double, double, double);
61 static Matrix rotation(double a, const Vector3 &x) { return rotation(a, x.x, x.y, x.z); }
62 static Matrix rotation_deg(double, double, double, double);
63 static Matrix rotation_deg(double a, const Vector3 &x) { return rotation_deg(a, x.x, x.y, x.z); }
64 static Matrix scaling(double);
65 static Matrix scaling(double, double, double);
67 static Matrix ortho(double, double, double, double, double, double);
68 static Matrix ortho_centered(double, double);
69 static Matrix ortho_bottomleft(double, double);
70 static Matrix ortho_topleft(double, double);
71 static Matrix frustum(double, double, double, double, double, double);
72 static Matrix frustum_centered(double, double, double, double);
73 static Matrix perspective(double, double, double, double);
85 Push(MatrixStack &s): stack(s) { stack.push(); }
86 ~Push() { stack.pop(); }
91 std::list<Matrix> matrices;
93 static GLenum current_mode;
95 MatrixStack(const MatrixStack &);
96 MatrixStack &operator=(const MatrixStack &);
101 const Matrix &top() const;
102 void load(const Matrix &);
103 void multiply(const Matrix &);
107 virtual void update();
110 MatrixStack &operator=(const Matrix &);
111 MatrixStack &operator*=(const Matrix &);
113 static MatrixStack &modelview();
114 static MatrixStack &projection();
118 /* The stuff below is deprecated and preserved (for now) only for compatibility
119 with existing applications */
123 MODELVIEW = GL_MODELVIEW,
124 PROJECTION = GL_PROJECTION,
128 void matrix_mode(MatrixMode);
129 void load_identity();
130 void load_matrix(const float *);
131 void load_matrix(const double *);
132 void mult_matrix(const float *);
133 void mult_matrix(const double *);
137 /// RAII object - pushes matrix when constructed and pops when destroyed
140 PushMatrix() { push_matrix(); }
141 ~PushMatrix() { pop_matrix(); }
144 void translate(float, float, float);
145 void rotate(float, float, float, float);
146 void scale(float, float, float);
147 void scale_uniform(float);