view src/main.cpp @ 6:11e216148d1c

Making progress in Matrix. Reorganized code a bit. Reworked Vector routines to use += -= *=
author Eris Caffee <discordia@eldalin.com>
date Tue, 06 Sep 2011 11:26:39 -0500
parents f6e6f3c8f7eb
children 378862555189
line source
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 #include <string>
5 using namespace std;
7 #include "Math.h"
8 using namespace arda::Vector;
9 using namespace arda::Matrix;
11 ////////////////////////////////////////////////////////////////////////////////
12 void test_vector(void)
13 {
14 string s1, s2;
16 // Vector::scale*()
17 {
18 cout << "===============================================================" << endl <<
19 "Testing Vector::scale*()" << endl;
21 Vector2i v2i = { 1, 2 };
22 cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl;
23 scale2v(v2i, 2);
24 cout << setw(40) << "scale2v(v2i, 2): " << getstring2v(v2i, s1) << endl;
25 scale2v(v2i, 2.4);
26 cout << setw(40) << "scale2v(v2i, 2.4): " << getstring2v(v2i, s1) << endl;
27 scale2v(scale2v(v2i, 2), 3);
28 cout << setw(40) << "scale2v(scale2v(v2i, 2), 3): " << getstring2v(v2i, s1) << endl;
31 Vector3f v3f = { 3.0, 4.1, 5.2 };
32 cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl;
33 scale3v(v3f, 2.2f);
34 cout << setw(40) << "scale3v(v3f, 2.2f): " << getstring3v(v3f, s1) << endl;
35 scale3v(v3f, 2);
36 cout << setw(40) << "scale3v(v2f, 2): " << getstring3v(v3f, s1) << endl;
38 Vector4d v4d = { 6.0L, 7.1L, 8.2L, 9.3L };
39 cout << setw(40) << "vd4: " << getstring4v(v4d, s1) << endl;
40 scale4v(v4d, 2.0);
41 cout << setw(40) << "scale4v(v4d, 2.0): " << getstring4v(v4d, s1) << endl;
42 scale4v(v4d, 2);
43 cout << setw(40) << "scale4v(v4d, 2): " << getstring4v(v4d, s1) << endl;
44 }
47 // Vector::dot*()
48 {
49 cout << "===============================================================" << endl <<
50 "Testing Vector::dot*()" << endl;
52 Vector2i v2i[2] = { { 1, 2 }, { 3, 4 } };
53 cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl;
54 cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl;
55 cout << setw(40) << "dot2v(v2i[0], v2i[1]): " << dot2v(v2i[0], v2i[1]) << endl;
57 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
58 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
59 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
60 cout << setw(40) << "dot3v(v3f[0], v3f[1]): " << dot3v(v3f[0], v3f[1]) << endl;
62 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
63 cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl;
64 cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl;
65 cout << setw(40) << "dot4v(v4d[0], v4d[1]): " << dot4v(v4d[0], v4d[1]) << endl;
67 }
69 // Vector::length*()
70 {
71 cout << "===============================================================" << endl <<
72 "Testing Vector::length*()" << endl;
74 Vector2i v2i = { 1, 2 };
75 cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl;
76 cout << setw(40) << "length2v(v2i): " << length2v(v2i) << endl;
78 Vector3f v3f = { 1.1f, 2.2f, 3.3f };
79 cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl;
80 cout << setw(40) << "length3v(v3f): " << length3v(v3f) << endl;
82 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 };
83 cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl;
84 cout << setw(40) << "length4v(v4d): " << length4v(v4d) << endl;
86 }
88 // Vector::add*()
89 {
90 cout << "===============================================================" << endl <<
91 "Testing Vector::add*()" << endl;
93 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
94 cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl;
95 cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl;
96 add2v(v2i[0], v2i[1]);
97 cout << setw(40) << "add2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl;
98 cout << setw(40) << "length2v(add2v(v2i[0], v2i[1])): " << length2v(add2v(v2i[0], v2i[1])) << endl;
100 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
101 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
102 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
103 add3v(v3f[0], v3f[1]);
104 cout << setw(40) << "add3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl;
105 cout << setw(40) << "length3v(add3v(v3f[0], v3f[1])): " << length3v(add3v(v3f[0], v3f[1])) << endl;
107 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
108 cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl;
109 cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl;
110 add4v(v4d[0], v4d[1]);
111 cout << setw(40) << "add4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl;
112 cout << setw(40) << "length4v(add4v(v4d[0], v4d[1])): " << length4v(add4v(v4d[0], v4d[1])) << endl;
114 }
116 // Vector::normalize*()
117 {
118 cout << "===============================================================" << endl <<
119 "Testing Vector::normalize*()" << endl;
121 Vector2f v2f = { 1.1, 2.2 };
122 cout << setw(40) << "v2f: " << getstring2v(v2f, s1) << endl;
123 normalize2v(v2f);
124 cout << setw(40) << "normalize2v(v2f): " << getstring2v(v2f, s1) << endl;
125 scale2v(normalize2v(v2f), 2.0);
126 cout << setw(40) << "scale(normalize2v(v2f), 2.0): " << getstring2v(v2f, s1) << endl;
128 Vector3f v3f = { 1.1f, 2.2f, 3.3f };
129 cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl;
130 normalize3v(v3f);
131 cout << setw(40) << "normalize3v(v3f): " << getstring3v(v3f, s1) << endl;
132 scale3v(normalize3v(v3f), 2.0);
133 cout << setw(40) << "scale(normalize3v(v3f), 2.0): " << getstring3v(v3f, s1) << endl;
135 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 };
136 cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl;
137 normalize4v(v4d);
138 cout << setw(40) << "normalize4v(v4d): " << getstring4v(v4d, s1) << endl;
139 scale4v(normalize4v(v4d), 2.0);
140 cout << setw(40) << "scale4v(normalize4v(v4d), 2.0): " << getstring4v(v4d, s1) << endl;
142 }
144 // Vector::cross()
145 {
146 cout << "===============================================================" << endl <<
147 "Testing Vector::cross()" << endl;
149 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 0.0f, 0.0f, 0.0f } };
150 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
151 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
152 cross(v3f[0], v3f[1], v3f[2]);
153 cout << setw(40) << "cross(v3f[0], v3f[1], v3f[2]): " << getstring3v(v3f[2], s1) << endl;
155 Vector3d v3d[3] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 0.0, 0.0, 0.0 } };
156 cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl;
157 cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl;
158 cross(v3d[0], v3d[1], v3d[2]);
159 cout << setw(40) << "cross(v3d[0], v3d[1], v3d[2]): " << getstring3v(v3d[2], s1) << endl;
161 }
164 // Vector::cross()
165 {
166 cout << "===============================================================" << endl <<
167 "Testing Vector::get_angle*()" << endl;
169 Vector3i v3i[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
170 cout << setw(40) << "v3i[0]: " << getstring3v(v3i[0], s1) << endl;
171 cout << setw(40) << "v3i[1]: " << getstring3v(v3i[1], s1) << endl;
172 cout << setw(40) << "get_angle3v(v3i[0], v3i[1]): " << get_angle3v(v3i[0], v3i[1]) << endl;
174 Vector3f v3f[2] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
175 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
176 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
177 cout << setw(40) << "get_angle3v(v3f[0], v3f[1]): " << get_angle3v(v3f[0], v3f[1]) << endl;
178 normalize3v(v3f[0]);
179 normalize3v(v3f[1]);
180 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
181 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
182 cout << setw(40) << "get_angle3n(v3f[0], v3f[1]): " << get_angle3n(v3f[0], v3f[1]) << endl;
184 Vector3d v3d[2] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } };
185 cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl;
186 cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl;
187 cout << setw(40) << "get_angle3v(v3d[0], v3d[1]): " << get_angle3v(v3d[0], v3d[1]) << endl;
188 normalize3v(v3d[0]);
189 normalize3v(v3d[1]);
190 cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl;
191 cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl;
192 cout << setw(40) << "get_angle3n(v3d[0], v3d[1]): " << get_angle3n(v3d[0], v3d[1]) << endl;
193 }
195 // Vector::subtract*()
196 {
197 cout << "===============================================================" << endl <<
198 "Testing Vector::subtract*()" << endl;
200 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
201 cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl;
202 cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl;
203 subtract2v(v2i[0], v2i[1]);
204 cout << setw(40) << "subtract2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl;
205 cout << setw(40) << "length2v(subtract2v(v2i[0], v2i[1])): " << length2v(subtract2v(v2i[0], v2i[1])) << endl;
207 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
208 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
209 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
210 subtract3v(v3f[0], v3f[1]);
211 cout << setw(40) << "subtract3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl;
212 cout << setw(40) << "length3v(subtract3v(v3f[0], v3f[1])): " << length3v(subtract3v(v3f[0], v3f[1])) << endl;
214 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
215 cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl;
216 cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl;
217 subtract4v(v4d[0], v4d[1]);
218 cout << setw(40) << "subtract4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl;
219 cout << setw(40) << "length4v(subtract4v(v4d[0], v4d[1])): " << length4v(subtract4v(v4d[0], v4d[1])) << endl;
221 }
223 // Vector::assign*()
224 {
225 cout << "===============================================================" << endl <<
226 "Testing Vector::assign*()" << endl;
228 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
229 cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl;
230 cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl;
231 assign2v(v2i[0], v2i[1]);
232 cout << setw(40) << "assign2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl;
234 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
235 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
236 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
237 assign3v(v3f[0], v3f[1]);
238 cout << setw(40) << "assign3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl;
240 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
241 cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl;
242 cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl;
243 assign4v(v4d[0], v4d[1]);
244 cout << setw(40) << "assign4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl;
246 }
248 // Vector::proj*()
249 {
250 cout << "===============================================================" << endl <<
251 "Testing Vector::proj*()" << endl;
253 Vector2f v2f[3] = { { 1.1f, 2.2f }, { 3.3f, 4.4f } };
254 Vector2f v2fres;
255 cout << setw(40) << "v2f[0]: " << getstring2v(v2f[0], s1) << endl;
256 cout << setw(40) << "v2f[1]: " << getstring2v(v2f[1], s1) << endl;
257 proj3v(v2f[0], v2f[1], v2fres);
258 cout << setw(40) << "proj3v(v2f[0], v2f[1], v2fres): " << getstring2v(v2fres, s1) << endl;
260 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
261 Vector3f v3fres;
262 cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl;
263 cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl;
264 proj3v(v3f[0], v3f[1], v3fres);
265 cout << setw(40) << "proj3v(v3f[0], v3f[1], v3fres): " << getstring3v(v3fres, s1) << endl;
267 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
268 Vector4d v4dres;
269 cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl;
270 cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl;
271 proj4v(v4d[0], v4d[1], v4dres);
272 cout << setw(40) << "proj4v(v4d[0], v4d[1], v4dres): " << getstring4v(v4dres, s1) << endl;
274 }
276 }
278 ////////////////////////////////////////////////////////////////////////////////
279 void test_matrix(void)
280 {
281 std::string s;
283 {
284 cout << "===============================================================" << endl <<
285 "Testing Matrix::assign*()" << endl;
286 Matrix2i m2i[2] = { { 0, 0,
287 0, 0 },
288 { 1, 2,
289 3, 4 } };
290 Matrix3f m3f[2] = { { 0.0f, 0.0f, 0.0f,
291 0.0f, 0.0f, 0.0f,
292 0.0f, 0.0f, 0.0f },
293 { 1.1f, 2.2f, 3.3f,
294 4.4f, 5.5f, 6.6f,
295 7.7f, 8.8f, 9.9f } };
296 Matrix4d m4d[2] = { { 0.0, 0.0, 0.0, 0.0,
297 0.0, 0.0, 0.0, 0.0,
298 0.0, 0.0, 0.0, 0.0,
299 0.0, 0.0, 0.0, 0.0 },
300 { 1.1, 2.2, 3.3, 4.4,
301 5.5, 6.6, 7.7, 8.8,
302 9.9, 10.10, 11.11, 12.12,
303 13.13, 14.14, 15.15, 16.16 } };
304 cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl;
305 cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl;
306 assign2m(m2i[0], m2i[1]);
307 cout << setw(40) << "assign2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl;
309 cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl;
310 cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl;
311 assign3m(m3f[0], m3f[1]);
312 cout << setw(40) << "assign3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl;
314 cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl;
315 cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl;
316 assign4m(m4d[0], m4d[1]);
317 cout << setw(40) << "assign4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl;
318 }
320 {
321 cout << "===============================================================" << endl <<
322 "Testing Matrix::add*()" << endl;
323 Matrix2i m2i[2] = { { 1, 2,
324 3, 4 },
325 { 5, 6,
326 7, 8 } };
327 Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f,
328 4.4f, 5.5f, 6.6f,
329 7.7f, 8.8f, 9.9f },
330 { 10.10f, 11.11f, 12.12f,
331 13.13f, 14.14f, 15.15f,
332 16.16f, 17.17f, 18.18f } };
333 Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4,
334 5.5, 6.6, 7.7, 8.8,
335 9.9, 10.10, 11.11, 12.12,
336 13.13, 14.14, 15.15, 16.16 },
337 { 17.17, 18.18, 19.19, 20.20,
338 21.21, 22.22, 23.23, 24.24,
339 25.25, 26.26, 27.27, 28.28,
340 29.29, 30.30, 31.31, 32.32 } };
341 cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl;
342 cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl;
343 add2m(m2i[0], m2i[1]);
344 cout << setw(40) << "add2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl;
346 cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl;
347 cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl;
348 add3m(m3f[0], m3f[1]);
349 cout << setw(40) << "add3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl;
351 cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl;
352 cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl;
353 add4m(m4d[0], m4d[1]);
354 cout << setw(40) << "add4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl;
355 }
357 {
358 cout << "===============================================================" << endl <<
359 "Testing Matrix::subtract*()" << endl;
360 Matrix2i m2i[2] = { { 1, 2,
361 3, 4 },
362 { 5, 6,
363 7, 8 } };
364 Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f,
365 4.4f, 5.5f, 6.6f,
366 7.7f, 8.8f, 9.9f },
367 { 10.10f, 11.11f, 12.12f,
368 13.13f, 14.14f, 15.15f,
369 16.16f, 17.17f, 18.18f } };
370 Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4,
371 5.5, 6.6, 7.7, 8.8,
372 9.9, 10.10, 11.11, 12.12,
373 13.13, 14.14, 15.15, 16.16 },
374 { 17.17, 18.18, 19.19, 20.20,
375 21.21, 22.22, 23.23, 24.24,
376 25.25, 26.26, 27.27, 28.28,
377 29.29, 30.30, 31.31, 32.32 } };
378 cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl;
379 cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl;
380 subtract2m(m2i[0], m2i[1]);
381 cout << setw(40) << "subtract2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl;
383 cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl;
384 cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl;
385 subtract3m(m3f[0], m3f[1]);
386 cout << setw(40) << "subtract3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl;
388 cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl;
389 cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl;
390 subtract4m(m4d[0], m4d[1]);
391 cout << setw(40) << "subtract4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl;
392 }
394 {
395 cout << "===============================================================" << endl <<
396 "Testing Matrix::scale*()" << endl;
397 Matrix2i m2i = { 1, 2,
398 3, 4 };
399 Matrix3f m3f = { 1.1f, 2.2f, 3.3f,
400 4.4f, 5.5f, 6.6f,
401 7.7f, 8.8f, 9.9f };
402 Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4,
403 5.5, 6.6, 7.7, 8.8,
404 9.9, 10.10, 11.11, 12.12,
405 13.13, 14.14, 15.15, 16.16 };
406 cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl;
407 cout << setw(40) << "scale2m(m2i, 2)" << getstring2m(scale2m(m2i, 2), s) << endl;
409 cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl;
410 cout << setw(40) << "scale3m(m3f, 2.2f)" << getstring3m(scale3m(m3f, 2.2f), s) << endl;
412 cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl;
413 cout << setw(40) << "scale4m(m3d, 2.2)" << getstring4m(scale4m(m4d, 2.2), s) << endl;
414 }
416 {
417 cout << "===============================================================" << endl <<
418 "Testing Matrix::multvec*()" << endl;
419 Vector2i v2ires;
420 Vector3f v3fres;
421 Vector4d v4dres;
422 Vector2i v2i = { 1, 2 };
423 Vector3f v3f = { 1.1f, 2.2f, 3.3f };
424 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 };
425 Matrix2i m2i = { 1, 2,
426 3, 4 };
427 Matrix3f m3f = { 1.1f, 2.2f, 3.3f,
428 4.4f, 5.5f, 6.6f,
429 7.7f, 8.8f, 9.9f };
430 Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4,
431 5.5, 6.6, 7.7, 8.8,
432 9.9, 10.10, 11.11, 12.12,
433 13.13, 14.14, 15.15, 16.16 };
434 cout << setw(40) << "v2i" << getstring2v(v2i, s) << endl;
435 cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl;
436 cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" <<
437 getstring2v(multvec2mv(m2i, v2i, v2ires), s) << endl;
438 cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" <<
439 getstring2v(multvec2vm(v2i, m2i, v2ires), s) << endl;
441 cout << setw(40) << "v3f" << getstring3v(v3f, s) << endl;
442 cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl;
443 cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" <<
444 getstring3v(multvec3mv(m3f, v3f, v3fres), s) << endl;
445 cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" <<
446 getstring3v(multvec3vm(v3f, m3f, v3fres), s) << endl;
448 cout << setw(40) << "v4d" << getstring4v(v4d, s) << endl;
449 cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl;
450 cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" <<
451 getstring4v(multvec4mv(m4d, v4d, v4dres), s) << endl;
452 cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" <<
453 getstring4v(multvec4vm(v4d, m4d, v4dres), s) << endl;
455 }
458 {
459 cout << "===============================================================" << endl <<
460 "Testing Matrix::multmat*()" << endl;
461 Matrix2i m2ires;
462 Matrix3f m3fres;
463 Matrix4d m4dres;
464 Matrix2i m2i[2] = { { 1, 2,
465 3, 4 },
466 { 5, 6,
467 7, 8 } };
468 Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f,
469 4.4f, 5.5f, 6.6f,
470 7.7f, 8.8f, 9.9f },
471 { 10.10f, 11.11f, 12.12f,
472 13.13f, 14.14f, 15.15f,
473 16.16f, 17.17f, 18.18f } };
474 Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4,
475 5.5, 6.6, 7.7, 8.8,
476 9.9, 10.10, 11.11, 12.12,
477 13.13, 14.14, 15.15, 16.16 },
478 { 17.17, 18.18, 19.19, 20.20,
479 21.21, 22.22, 23.23, 24.24,
480 25.25, 26.26, 27.27, 28.28,
481 29.29, 30.30, 31.31, 32.32 } };
482 cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl;
483 cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl;
484 multmat2(m2i[0], m2i[1], m2ires);
485 cout << setw(40) << "multmat2(m2i[0], m2i[1], m21res)" <<
486 getstring2m(m2ires, s) << endl;
488 cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl;
489 cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl;
490 multmat3(m3f[0], m3f[1], m3fres);
491 cout << setw(40) << "multmat3(m3f[0], m3f[1], m3fres)" <<
492 getstring3m(m3fres, s) << endl;
494 cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl;
495 cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl;
496 multmat4(m4d[0], m4d[1], m4dres);
497 cout << setw(40) << "multmat4(m4d[0], m4d[1], m4dres)" <<
498 getstring4m(m4dres, s) << endl;
499 }
501 {
502 cout << "===============================================================" << endl <<
503 "Testing Matrix::transpose*()" << endl;
504 Matrix2i m2ires;
505 Matrix3f m3fres;
506 Matrix4d m4dres;
507 Matrix2i m2i = { 1, 2,
508 3, 4 };
509 Matrix3f m3f = { 1.1f, 2.2f, 3.3f,
510 4.4f, 5.5f, 6.6f,
511 7.7f, 8.8f, 9.9f };
512 Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4,
513 5.5, 6.6, 7.7, 8.8,
514 9.9, 10.10, 11.11, 12.12,
515 13.13, 14.14, 15.15, 16.16 };
516 cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl;
517 cout << setw(40) << "transpose2(m2i, m2ires)" <<
518 getstring2m(transpose2(m2i, m2ires), s) << endl;
520 cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl;
521 cout << setw(40) << "transpose3(m3f, m3fres)" <<
522 getstring3m(transpose3(m3f, m3fres), s) << endl;
524 cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl;
525 cout << setw(40) << "transpose4(m4d, m4dres)" <<
526 getstring4m(transpose4(m4d, m4dres), s) << endl;
528 }
529 }
531 ////////////////////////////////////////////////////////////////////////////////
532 void test_all(void)
533 {
534 test_vector();
535 test_matrix();
536 }
538 ////////////////////////////////////////////////////////////////////////////////
539 void show_menu(void)
540 {
541 cout << endl << endl
542 << "Test what?" << endl
543 << "0) All" << endl << endl
544 << "1) Vector" << endl
545 << "2) Matrix" << endl
546 << endl
547 << "99 Quit" << endl;
548 }
550 ////////////////////////////////////////////////////////////////////////////////
551 int main (int argc, char * argv[])
552 {
553 int retval = 0;
555 try
556 {
557 int choice = -1;
559 while (choice != 99)
560 {
561 show_menu();
562 cin >> choice;
563 if(!cin)
564 {
565 cin.clear();
566 cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
567 }
568 if (choice != 99)
569 {
570 switch (choice)
571 {
572 case 0:
573 test_all();
574 break;
575 case 1:
576 test_vector();
577 break;
578 case 2:
579 test_matrix();
580 break;
581 default:
582 cout << "Unrecognized choice. Please try again." << endl;
583 }
584 choice = -1;
585 }
586 }
587 }
588 catch (const std::exception & error)
589 {
590 string e = "Caught exception: ";
591 e += error.what();
592 cerr << e << endl;
593 retval = 1;
594 }
596 return retval;;
598 }