-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmattest.cpp
More file actions
181 lines (137 loc) · 4.26 KB
/
mattest.cpp
File metadata and controls
181 lines (137 loc) · 4.26 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include "Matrix.h"
int main() {
vec3 v;
v = {1,2,3};
std::cout << v[2] << std::endl;
mat2 a;
a = {
{7,1},
{8,4}
};
mat3 b;
b = {
{2,3,6},
{7,1,9},
{8,4,1}
};
mat4 m, n;
m = {
{2,3,4,2},
{1,2,7,1},
{3,4,5,6},
{9,8,7,8}
};
n = {
{4,5,1,2},
{2,7,8,6},
{9,1,2,4},
{7,1,1,2}
};
char str[200];
memset(str, 0, sizeof(str));
(a).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Matrices: " << std::endl;
memset(str, 0, sizeof(str));
(m).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(n).toString(str,1);
std::cout << str << std::endl << std::endl;
mat4 add = m+n;
std::cout << "Addition: " << std::endl;
memset(str, 0, sizeof(str));
(add).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Matrices: " << std::endl;
memset(str, 0, sizeof(str));
(m).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(n).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Multiplication: " << std::endl;
memset(str, 0, sizeof(str));
(m*n).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Matrices: " << std::endl;
memset(str, 0, sizeof(str));
(m).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(n).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Transposition: " << std::endl;
memset(str, 0, sizeof(str));
(~(m*n)).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Matrices: " << std::endl;
memset(str, 0, sizeof(str));
(m).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(n).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Identity: " << std::endl;
memset(str, 0, sizeof(str));
(mat4()).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Matrix * Vector " << std::endl;
memset(str, 0, sizeof(str));
(m*n[0]).toString(str,1);
std::cout << str << std::endl << std::endl;
vec3 v1(m[0][0],m[0][1],m[0][2]);
vec3 v2(n[0][0],n[0][1],n[0][2]);
std::cout << "Vector & Vector " << std::endl;
memset(str, 0, sizeof(str));
(v1).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(v2).toString(str,1);
std::cout << str << std::endl << std::endl;
memset(str, 0, sizeof(str));
(v1&v2).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "Vector Normal " << std::endl;
memset(str, 0, sizeof(str));
(v1.normalize()).toString(str);
std::cout << str << std::endl << std::endl;
std::cout << "2X2 Reduction" << std::endl;
memset(str, 0, sizeof(str));
std::cout << a.reduce(0,1) << std::endl << std::endl;
std::cout << "3X3 Reduction" << std::endl;
memset(str, 0, sizeof(str));
(b.reduce(0,1)).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "4X4 Reduction" << std::endl;
memset(str, 0, sizeof(str));
(m.reduce(0,1)).toString(str,1);
std::cout << str << std::endl << std::endl;
std::cout << "2X2 Determinant" << std::endl;
memset(str, 0, sizeof(str));
std::cout << a.determinant() << std::endl << std::endl;
std::cout << "3X3 Determinant" << std::endl;
memset(str, 0, sizeof(str));
std::cout << b.determinant() << std::endl << std::endl;
std::cout << "4X4 Determinant" << std::endl;
memset(str, 0, sizeof(str));
std::cout << m.determinant() << std::endl << std::endl;
std::cout << "2X2 Inverse" << std::endl;
memset(str, 0, sizeof(str));
(a.inverse()).toString(str);
std::cout << str << std::endl << std::endl;
std::cout << "3X3 Inverse" << std::endl;
memset(str, 0, sizeof(str));
(b.inverse()).toString(str);
std::cout << str << std::endl << std::endl;
std::cout << "4X4 Inverse" << std::endl;
memset(str, 0, sizeof(str));
(m.inverse()).toString(str);
std::cout << str << std::endl << std::endl;
std::cout << "4X4 Mat*Inverse" << std::endl;
memset(str, 0, sizeof(str));
((m.inverse())*m).toString(str,1);
std::cout << str << std::endl << std::endl;
return 0;
}