graphene

view src/gmath/matrix.h @ 6:9fbbc96e6fbe

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 31 Jul 2015 04:59:28 +0300
parents d71b4e899e08
children
line source
1 #ifndef GMATH_MATRIX_H_
2 #define GMATH_MATRIX_H_
4 #include <string.h>
5 #include "vector.h"
7 namespace gph {
9 class Matrix4x4 {
10 private:
11 float m[4][4];
13 public:
14 static Matrix4x4 identity;
16 Matrix4x4()
17 {
18 memcpy((float*)m, (const float*)identity.m, 16 * sizeof(float));
19 }
21 Matrix4x4(const float *m)
22 {
23 memcpy((float*)this->m, (const float*)m, 16 * sizeof(float));
24 }
26 Matrix4x4(float m00, float m01, float m02, float m03,
27 float m10, float m11, float m12, float m13,
28 float m20, float m21, float m22, float m23,
29 float m30, float m31, float m32, float m33)
30 {
31 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; m[0][3] = m03;
32 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; m[1][3] = m13;
33 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; m[2][3] = m23;
34 m[3][0] = m30; m[3][1] = m31; m[3][2] = m32; m[3][3] = m33;
35 }
37 Matrix4x4(const Vector4 &v0, const Vector4 &v1, const Vector4 &v2, const Vector4 &v3)
38 {
39 m[0][0] = v0.x; m[0][1] = v0.y; m[0][2] = v0.z; m[0][3] = v0.w;
40 m[1][0] = v1.x; m[1][1] = v1.y; m[1][2] = v1.z; m[1][3] = v1.w;
41 m[2][0] = v2.x; m[2][1] = v2.y; m[2][2] = v2.z; m[2][3] = v2.w;
42 m[3][0] = v3.x; m[3][1] = v3.y; m[3][2] = v3.z; m[3][3] = v3.w;
43 }
45 float *operator [](int idx)
46 {
47 return m[idx];
48 }
50 const float *operator [](int idx) const
51 {
52 return m[idx];
53 }
54 };
56 } // namespace gph
58 #endif // GMATH_MATRIX_H_