fixed copying of library links in install target
[gph-math] / src / matrix.h
1 /*
2 gph-math - math library for graphics programs
3 Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software. Feel free to use, modify, and/or redistribute
6 it under the terms of the MIT/X11 license. See LICENSE for details.
7 If you intend to redistribute parts of the code without the LICENSE file
8 replace this paragraph with the full contents of the LICENSE file.
9 */
10 #ifndef GMATH_MATRIX_H_
11 #define GMATH_MATRIX_H_
12
13 #include <string.h>
14 #include "vector.h"
15
16 namespace gph {
17
18 class Matrix4x4 {
19 private:
20         float m[4][4];
21
22 public:
23         static Matrix4x4 identity;
24
25         Matrix4x4()
26         {
27                 memcpy((float*)m, (const float*)identity.m, 16 * sizeof(float));
28         }
29
30         Matrix4x4(const float *m)
31         {
32                 memcpy((float*)this->m, (const float*)m, 16 * sizeof(float));
33         }
34
35         Matrix4x4(float m00, float m01, float m02, float m03,
36                         float m10, float m11, float m12, float m13,
37                         float m20, float m21, float m22, float m23,
38                         float m30, float m31, float m32, float m33)
39         {
40                 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; m[0][3] = m03;
41                 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; m[1][3] = m13;
42                 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; m[2][3] = m23;
43                 m[3][0] = m30; m[3][1] = m31; m[3][2] = m32; m[3][3] = m33;
44         }
45
46         Matrix4x4(const Vector4 &v0, const Vector4 &v1, const Vector4 &v2, const Vector4 &v3)
47         {
48                 m[0][0] = v0.x; m[0][1] = v0.y; m[0][2] = v0.z; m[0][3] = v0.w;
49                 m[1][0] = v1.x; m[1][1] = v1.y; m[1][2] = v1.z; m[1][3] = v1.w;
50                 m[2][0] = v2.x; m[2][1] = v2.y; m[2][2] = v2.z; m[2][3] = v2.w;
51                 m[3][0] = v3.x; m[3][1] = v3.y; m[3][2] = v3.z; m[3][3] = v3.w;
52         }
53
54         float *operator [](int idx)
55         {
56                 return m[idx];
57         }
58
59         const float *operator [](int idx) const
60         {
61                 return m[idx];
62         }
63 };
64
65 }       // namespace gph
66
67 #endif  // GMATH_MATRIX_H_