graphene
diff src/gmath/matrix.h @ 3:d71b4e899e08
minimal matrix and vec4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 25 Jul 2015 05:52:39 +0300 |
parents | |
children | d30e24132b6e |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/gmath/matrix.h Sat Jul 25 05:52:39 2015 +0300 1.3 @@ -0,0 +1,58 @@ 1.4 +#ifndef GMATH_MATRIX_H_ 1.5 +#define GMATH_MATRIX_H_ 1.6 + 1.7 +#include <string.h> 1.8 +#include "vec.h" 1.9 + 1.10 +namespace gph { 1.11 + 1.12 +class Matrix4x4 { 1.13 +private: 1.14 + float m[4][4]; 1.15 + 1.16 +public: 1.17 + static Matrix4x4 identity; 1.18 + 1.19 + Matrix4x4() 1.20 + { 1.21 + memcpy((float*)m, (const float*)identity.m, 16 * sizeof(float)); 1.22 + } 1.23 + 1.24 + Matrix4x4(const float *m) 1.25 + { 1.26 + memcpy((float*)this->m, (const float*)m, 16 * sizeof(float)); 1.27 + } 1.28 + 1.29 + Matrix4x4(float m00, float m01, float m02, float m03, 1.30 + float m10, float m11, float m12, float m13, 1.31 + float m20, float m21, float m22, float m23, 1.32 + float m30, float m31, float m32, float m33) 1.33 + { 1.34 + m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; m[0][3] = m03; 1.35 + m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; m[1][3] = m13; 1.36 + m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; m[2][3] = m23; 1.37 + m[3][0] = m30; m[3][1] = m31; m[3][2] = m32; m[3][3] = m33; 1.38 + } 1.39 + 1.40 + Matrix4x4(const Vector4 &v0, const Vector4 &v1, const Vector4 &v2, const Vector4 &v3) 1.41 + { 1.42 + m[0][0] = v0.x; m[0][1] = v0.y; m[0][2] = v0.z; m[0][3] = v0.w; 1.43 + m[1][0] = v1.x; m[1][1] = v1.y; m[1][2] = v1.z; m[1][3] = v1.w; 1.44 + m[2][0] = v2.x; m[2][1] = v2.y; m[2][2] = v2.z; m[2][3] = v2.w; 1.45 + m[3][0] = v3.x; m[3][1] = v3.y; m[3][2] = v3.z; m[3][3] = v3.w; 1.46 + } 1.47 + 1.48 + float *operator [](int idx) 1.49 + { 1.50 + return m[idx]; 1.51 + } 1.52 + 1.53 + const float *operator [](int idx) const 1.54 + { 1.55 + return m[idx]; 1.56 + } 1.57 +}; 1.58 + 1.59 +} // namespace gph 1.60 + 1.61 +#endif // GMATH_MATRIX_H_