-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmatrix4x4.cpp
67 lines (56 loc) · 2.01 KB
/
tmatrix4x4.cpp
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
#include "tmatrix4x4.h"
bool TMatrix4x4::isAffine() const {
return m[0][3] == 0.0f && m[1][3] == 0.0f && m[2][3] == 0.0f &&
m[3][3] == 1.0f;
}
bool TMatrix4x4::isIdentity() const {
if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f || m[0][3] != 0.0f)
return false;
if (m[1][0] != 0.0f || m[1][1] != 1.0f || m[1][2] != 0.0f || m[1][3] != 0.0f)
return false;
if (m[2][0] != 0.0f || m[2][1] != 0.0f || m[2][2] != 1.0f || m[2][3] != 0.0f)
return false;
if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
return false;
return (m[3][3] == 1.0f);
}
void TMatrix4x4::setToIdentity() {
for (auto j = 0; j < 4; j++)
for (auto i = 0; i < 4; i++)
m[j][i] = 0.0f;
m[0][0] = 1.0f;
m[1][1] = 1.0f;
m[2][2] = 1.0f;
m[3][3] = 1.0f;
}
void TMatrix4x4::fill(float value) {
for (auto j = 0; j < 4; j++)
for (auto i = 0; i < 4; i++)
m[j][i] = value;
}
TVector4D TMatrix4x4::column(int index) const {
if (index >= 0 && index < 4)
return TVector4D(m[index][0], m[index][1], m[index][2], m[index][3]);
}
void TMatrix4x4::setColumn(int index, const TVector4D &value) {
if (index >= 0 && index < 4) {
m[index][0] = value.x;
m[index][1] = value.y;
m[index][2] = value.z;
m[index][3] = value.w;
}
}
TVector4D TMatrix4x4::row(int index) const {
if (index >= 0 && index < 4)
return TVector4D(m[0][index], m[1][index], m[2][index], m[3][index]);
}
void TMatrix4x4::setRow(int index, const TVector4D &value) {
if (index >= 0 && index < 4) {
m[0][index] = value.x;
m[1][index] = value.y;
m[2][index] = value.z;
m[3][index] = value.w;
}
}
void TMatrix4x4::viewport(const TPoint &p1, const TPoint &p2) {
}