-
Notifications
You must be signed in to change notification settings - Fork 5
/
matrix2.h
executable file
·147 lines (108 loc) · 2.35 KB
/
matrix2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/******************************************************
g-Matrix3D Neo Engine
Copyright (c)2003 Kim Seong Wan (kaswan, Â𻧱ͽÅ)
E-mail: [email protected]
http://www.g-matrix.pe.kr
*******************************************************/
#ifndef MATRIX2_H
#define MATRIX2_H
class Matrix2 {
public:
float _11, _12;
float _21, _22;
Matrix2(){};
Matrix2(float m11, float m12, float m21, float m22)
{
_11 = m11;
_12 = m12;
_21 = m21;
_22 = m22;
};
~Matrix2(){};
void operator+=(const Matrix2 &m)
{
_11 += m._11;
_12 += m._12;
_21 += m._21;
_22 += m._22;
};
void operator-=(const Matrix2 &m)
{
_11 -= m._11;
_12 -= m._12;
_21 -= m._21;
_22 -= m._22;
};
Matrix2 operator+(const Matrix2 &m) const
{
return Matrix2(_11 + m._11, _12 + m._12, _21 + m._21, _22 + m._22);
};
Matrix2 operator-(const Matrix2 &m) const
{
return Matrix2(_11 - m._11, _12 - m._12, _21 - m._21, _22 - m._22);
};
void operator*=(const Matrix2 &m)
{
Matrix2 temp;
temp._11 = _11 * m._11 + _12 * m._21;
temp._12 = _11 * m._12 + _12 * m._22;
temp._21 = _21 * m._11 + _22 * m._21;
temp._22 = _21 * m._12 + _22 * m._22;
_11 = temp._11;
_12 = temp._12;
_21 = temp._21;
_22 = temp._22;
};
Matrix2 operator*(const Matrix2 &m) const
{
Matrix2 temp;
temp._11 = _11 * m._11 + _12 * m._21;
temp._12 = _11 * m._12 + _12 * m._22;
temp._21 = _21 * m._11 + _22 * m._21;
temp._22 = _21 * m._12 + _22 * m._22;
return temp;
};
void operator*=(const float scalar)
{
Matrix2 temp;
_11 *= scalar;
_12 *= scalar;
_21 *= scalar;
_22 *= scalar;
};
Matrix2 operator*(const float scalar) const
{
Matrix2 temp;
temp._11 = _11 * scalar;
temp._12 = _12 * scalar;
temp._21 = _21 * scalar;
temp._22 = _22 * scalar;
return temp;
};
friend Matrix2 operator*(const float scalar, const Matrix2 &m);
void Identity()
{
_11 = 1.0f;
_12 = 0.0f;
_21 = 0.0f;
_22 = 1.0f;
};
void Transpose()
{
float temp;
temp = _21;
_21 = _12;
_12 = temp;
};
void Inverse()
{
float Det = _11 * _22 - _12 * _21;
float InvDet = 1.0f / Det;
float temp_11 = _11;
_11 = _22 * InvDet;
_12 = -_12 * InvDet;
_21 = -_21 * InvDet;
_22 = temp_11 * InvDet;
};
};
#endif