2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of the n3dmath2 library.
6 The n3dmath2 library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 The n3dmath2 library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the n3dmath2 library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _N3DMATH2_MAT_HPP_
22 #define _N3DMATH2_MAT_HPP_
24 #include "n3dmath2.hpp"
31 static Matrix3x3 identity_matrix;
34 Matrix3x3( scalar_t m11, scalar_t m12, scalar_t m13,
35 scalar_t m21, scalar_t m22, scalar_t m23,
36 scalar_t m31, scalar_t m32, scalar_t m33);
38 Matrix3x3(const Matrix4x4 &mat4x4);
40 // binary operations matrix (op) matrix
41 friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
42 friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
43 friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
45 friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
46 friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
47 friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
49 // binary operations matrix (op) scalar and scalar (op) matrix
50 friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
51 friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
53 friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
55 inline scalar_t *operator [](int index);
56 inline const scalar_t *operator [](int index) const;
58 inline void reset_identity();
60 void translate(const Vector2 &trans);
61 void set_translation(const Vector2 &trans);
63 void rotate(scalar_t angle); // 2d rotation
64 void rotate(const Vector3 &euler_angles); // 3d rotation with euler angles
65 void rotate(const Vector3 &axis, scalar_t angle); // 3d axis/angle rotation
66 void set_rotation(scalar_t angle);
67 void set_rotation(const Vector3 &euler_angles);
68 void set_rotation(const Vector3 &axis, scalar_t angle);
70 void scale(const Vector3 &scale_vec);
71 void set_scaling(const Vector3 &scale_vec);
73 void set_column_vector(const Vector3 &vec, unsigned int col_index);
74 void set_row_vector(const Vector3 &vec, unsigned int row_index);
75 Vector3 get_column_vector(unsigned int col_index) const;
76 Vector3 get_row_vector(unsigned int row_index) const;
79 Matrix3x3 transposed() const;
80 scalar_t determinant() const;
81 Matrix3x3 inverse() const;
83 friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
90 mutable float *glmatrix;
93 static Matrix4x4 identity_matrix;
96 Matrix4x4( scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
97 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
98 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
99 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
101 Matrix4x4(const Matrix3x3 &mat3x3);
104 // binary operations matrix (op) matrix
105 friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
106 friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
107 friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
109 friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
110 friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
111 friend void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
113 // binary operations matrix (op) scalar and scalar (op) matrix
114 friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
115 friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
117 friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
119 inline scalar_t *operator [](int index);
120 inline const scalar_t *operator [](int index) const;
122 inline void reset_identity();
124 void translate(const Vector3 &trans);
125 void set_translation(const Vector3 &trans);
127 void rotate(const Vector3 &euler_angles); // 3d rotation with euler angles
128 void rotate(const Vector3 &axis, scalar_t angle); // 3d axis/angle rotation
129 void set_rotation(const Vector3 &euler_angles);
130 void set_rotation(const Vector3 &axis, scalar_t angle);
132 void scale(const Vector4 &scale_vec);
133 void set_scaling(const Vector4 &scale_vec);
135 void set_column_vector(const Vector4 &vec, unsigned int col_index);
136 void set_row_vector(const Vector4 &vec, unsigned int row_index);
137 Vector4 get_column_vector(unsigned int col_index) const;
138 Vector4 get_row_vector(unsigned int row_index) const;
141 Matrix4x4 transposed() const;
142 scalar_t determinant() const;
143 Matrix4x4 adjoint() const;
144 Matrix4x4 inverse() const;
146 const scalar_t *opengl_matrix() const;
148 friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
151 #include "n3dmath2_mat.inl"
153 #endif // _N3DMATH2_MAT_HPP_