2 This file is part of XRay, a photorealistic 3D rendering library.
3 Copyright (C) 2005 John Tsiombikas
5 XRay is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 XRay is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with XRay; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * @author John Tsiombikas
32 #include "vmath_types.h"
40 static Matrix3x3 identity_matrix;
43 Matrix3x3( scalar_t m11, scalar_t m12, scalar_t m13,
44 scalar_t m21, scalar_t m22, scalar_t m23,
45 scalar_t m31, scalar_t m32, scalar_t m33);
47 Matrix3x3(const Matrix4x4 &mat4x4);
49 // binary operations matrix (op) matrix
50 friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
51 friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
52 friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
54 friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
55 friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
56 friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
58 // binary operations matrix (op) scalar and scalar (op) matrix
59 friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
60 friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
62 friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
64 inline scalar_t *operator [](int index);
65 inline const scalar_t *operator [](int index) const;
67 inline void reset_identity();
69 void translate(const Vector2 &trans);
70 void set_translation(const Vector2 &trans);
72 void rotate(scalar_t angle); // 2d rotation
73 void rotate(const Vector3 &euler_angles); // 3d rotation with euler angles
74 void rotate(const Vector3 &axis, scalar_t angle); // 3d axis/angle rotation
75 void set_rotation(scalar_t angle);
76 void set_rotation(const Vector3 &euler_angles);
77 void set_rotation(const Vector3 &axis, scalar_t angle);
79 void scale(const Vector3 &scale_vec);
80 void set_scaling(const Vector3 &scale_vec);
82 void set_column_vector(const Vector3 &vec, unsigned int col_index);
83 void set_row_vector(const Vector3 &vec, unsigned int row_index);
84 Vector3 get_column_vector(unsigned int col_index) const;
85 Vector3 get_row_vector(unsigned int row_index) const;
88 Matrix3x3 transposed() const;
89 scalar_t determinant() const;
90 Matrix3x3 inverse() const;
92 friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
99 mutable float *glmatrix;
102 static Matrix4x4 identity_matrix;
105 Matrix4x4( scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
106 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
107 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
108 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
110 Matrix4x4(const Matrix3x3 &mat3x3);
113 // binary operations matrix (op) matrix
114 friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
115 friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
116 friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
118 friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
119 friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
120 friend void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
122 // binary operations matrix (op) scalar and scalar (op) matrix
123 friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
124 friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
126 friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
128 inline scalar_t *operator [](int index);
129 inline const scalar_t *operator [](int index) const;
131 inline void reset_identity();
133 void translate(const Vector3 &trans);
134 void set_translation(const Vector3 &trans);
136 void rotate(const Vector3 &euler_angles); // 3d rotation with euler angles
137 void rotate(const Vector3 &axis, scalar_t angle); // 3d axis/angle rotation
138 void set_rotation(const Vector3 &euler_angles);
139 void set_rotation(const Vector3 &axis, scalar_t angle);
141 void scale(const Vector4 &scale_vec);
142 void set_scaling(const Vector4 &scale_vec);
144 void set_column_vector(const Vector4 &vec, unsigned int col_index);
145 void set_row_vector(const Vector4 &vec, unsigned int row_index);
146 Vector4 get_column_vector(unsigned int col_index) const;
147 Vector4 get_row_vector(unsigned int row_index) const;
150 Matrix4x4 transposed() const;
151 scalar_t determinant() const;
152 Matrix4x4 adjoint() const;
153 Matrix4x4 inverse() const;
155 const scalar_t *opengl_matrix() const;
157 friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
160 #include "matrix.inl"
162 #endif // MATRIX_HPP_