volmetrics

view src/matrix.h @ 4:1fbbe10c8e08

quick backup
author Eleni Maria Stea <elene.mst@gmail.com>
date Sat, 11 Jan 2014 23:49:58 +0200
parents
children
line source
1 #ifndef MATRIX_H_
2 #define MATRIX_H_
4 #include <iostream>
5 #include "vector.h"
7 class Matrix4x4 {
8 public:
9 float m[4][4];
11 static Matrix4x4 identity;
13 Matrix4x4();
14 Matrix4x4( float m11, float m12, float m13, float m14,
15 float m21, float m22, float m23, float m24,
16 float m31, float m32, float m33, float m34,
17 float m41, float m42, float m43, float m44);
19 /* binary operations matrix (op) matrix */
20 friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
21 friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
22 friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
24 friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
25 friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
26 friend inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
28 /* binary operations matrix (op) scalar and scalar (op) matrix */
29 friend Matrix4x4 operator *(const Matrix4x4 &mat, float scalar);
30 friend Matrix4x4 operator *(float scalar, const Matrix4x4 &mat);
32 friend void operator *=(Matrix4x4 &mat, float scalar);
34 inline float *operator [](int index);
35 inline const float *operator [](int index) const;
37 inline void reset_identity();
39 void translate(const Vector3 &trans);
40 void set_translation(const Vector3 &trans);
42 void rotate(const Vector3 &euler); /* 3d rotation with euler angles */
43 void rotate(const Vector3 &axis, float angle); /* 3d axis/angle rotation */
44 void set_rotation(const Vector3 &euler_angles);
45 void set_rotation(const Vector3 &axis, float angle);
47 void scale(const Vector3 &scale_vec);
48 void set_scaling(const Vector3 &scale_vec);
50 void set_column_vector(const Vector3 &vec, unsigned int col_index);
51 void set_row_vector(const Vector3 &vec, unsigned int row_index);
52 Vector3 get_column_vector(unsigned int col_index) const;
53 Vector3 get_row_vector(unsigned int row_index) const;
55 void transpose();
56 Matrix4x4 transposed() const;
57 float determinant() const;
58 Matrix4x4 adjoint() const;
59 Matrix4x4 inverse() const;
60 };
62 /* binary operations matrix (op) matrix */
63 Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
64 Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
65 Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
67 void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
68 void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
69 inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
71 /* binary operations matrix (op) scalar and scalar (op) matrix */
72 Matrix4x4 operator *(const Matrix4x4 &mat, float scalar);
73 Matrix4x4 operator *(float scalar, const Matrix4x4 &mat);
75 void operator *=(Matrix4x4 &mat, float scalar);
77 std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
80 #endif