Mercurial > Math
changeset 20:b2c15ffdab9d
Forget src/main.cpp (because I forgot to use hg to rename it)
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Mon, 15 Sep 2014 01:02:52 -0500 |
parents | 4634ca3fc308 |
children | fbb4ac41da28 |
files | src/main.cpp |
diffstat | 1 files changed, 0 insertions(+), 1107 deletions(-) [+] |
line diff
1.1 --- a/src/main.cpp Mon Sep 15 01:02:04 2014 -0500 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,1107 +0,0 @@ 1.4 -#include <iostream> 1.5 -#include <iomanip> 1.6 -#include <limits> 1.7 -#include <string> 1.8 - 1.9 -using namespace std; 1.10 - 1.11 -#include "Math.h" 1.12 -using namespace arda::Math; 1.13 - 1.14 -//////////////////////////////////////////////////////////////////////////////// 1.15 -void test_vector(void) 1.16 - { 1.17 - string s1, s2; 1.18 - 1.19 - { 1.20 - cout << "===============================================================" << endl << 1.21 - "Testing Vector constructors" << endl; 1.22 - Vector2i v2i_1(0); 1.23 - Vector2i v2i_2(1); 1.24 - Vector2i v2i_3(1, 2); 1.25 - Vector2i v2i_4(v2i_3); 1.26 - 1.27 - cout << setw(40) << "v2i_1: " << v2i_1.to_string(s1) << endl; 1.28 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.29 - cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; 1.30 - cout << setw(40) << "v2i_4: " << v2i_4.to_string(s1) << endl; 1.31 - 1.32 - Vector3f v3f_1(0); 1.33 - Vector3f v3f_2(1); 1.34 - Vector3f v3f_3(1, 2, 3); 1.35 - Vector3f v3f_4(v3f_3); 1.36 - 1.37 - cout << setw(40) << "v3f_1: " << v3f_1.to_string(s1) << endl; 1.38 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.39 - cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 1.40 - cout << setw(40) << "v3f_4: " << v3f_4.to_string(s1) << endl; 1.41 - 1.42 - Vector4d v4d_1(0); 1.43 - Vector4d v4d_2(1); 1.44 - Vector4d v4d_3(1, 2, 3, 4); 1.45 - Vector4d v4d_4(v4d_3); 1.46 - 1.47 - cout << setw(40) << "v4d_1: " << v4d_1.to_string(s1) << endl; 1.48 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.49 - cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; 1.50 - cout << setw(40) << "v4d_4: " << v4d_4.to_string(s1) << endl; 1.51 - } 1.52 - 1.53 - { 1.54 - cout << "===============================================================" << endl << 1.55 - "Testing Vector array indexing" << endl; 1.56 - Vector2i v2i(1,2); 1.57 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.58 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.59 - 1.60 - cout << setw(40) << "v2i: " << v2i[0] << ", " << v2i[1] << endl; 1.61 - cout << setw(40) << "v3f: " << v3f[0] << ", " << v3f[1] << ", " << v3f[2] << endl; 1.62 - cout << setw(40) << "v4d: " << v4d[0] << ", " << v4d[1] << ", " << v4d[2] << ", " << v4d[3] << endl; 1.63 - } 1.64 - 1.65 - { 1.66 - cout << "===============================================================" << endl << 1.67 - "Testing Vector assignment" << endl; 1.68 - Vector2i v2i(1,2); 1.69 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.70 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.71 - Vector2i v2i_2(0); 1.72 - Vector3f v3f_2(0); 1.73 - Vector4d v4d_2(0); 1.74 - 1.75 - cout << "Before assignment" << endl; 1.76 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.77 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.78 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.79 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.80 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.81 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.82 - 1.83 - v2i_2 = v2i; 1.84 - v3f_2 = v3f; 1.85 - v4d_2 = v4d; 1.86 - cout << "After assignment by =" << endl; 1.87 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.88 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.89 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.90 - 1.91 - v2i_2.assign(1, 1); 1.92 - v3f_2.assign(2.2, 2.2, 2.2); 1.93 - v4d_2.assign(3.3, 3.3, 3.3, 3.3); 1.94 - cout << "After assignment by assign()" << endl; 1.95 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.96 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.97 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.98 - } 1.99 - 1.100 - { 1.101 - cout << "===============================================================" << endl << 1.102 - "Testing Vector comparison" << endl; 1.103 - Vector2i v2i(1,2); 1.104 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.105 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.106 - Vector2i v2i_2(1,2); 1.107 - Vector3f v3f_2(1.1f, 2.2f, 3.3f); 1.108 - Vector4d v4d_2(1.1, 2.2, 3.3, 4.4); 1.109 - Vector2i v2i_3(0); 1.110 - Vector3f v3f_3(0); 1.111 - Vector4d v4d_3(0); 1.112 - 1.113 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.114 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.115 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.116 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.117 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.118 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.119 - cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; 1.120 - cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 1.121 - cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; 1.122 - cout << boolalpha; 1.123 - cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl; 1.124 - cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl; 1.125 - cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl; 1.126 - cout << setw(40) << "v2i != v2i_3: " << (v2i != v2i_3) << endl; 1.127 - cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl; 1.128 - cout << setw(40) << "v3f == v3f_3: " << (v3f == v3f_3) << endl; 1.129 - cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl; 1.130 - cout << setw(40) << "v3f != v3f_3: " << (v3f != v3f_3) << endl; 1.131 - cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl; 1.132 - cout << setw(40) << "v4d == v4d_3: " << (v4d == v4d_3) << endl; 1.133 - cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl; 1.134 - cout << setw(40) << "v4d != v4d_3: " << (v4d != v4d_3) << endl; 1.135 - } 1.136 - 1.137 - { 1.138 - cout << "===============================================================" << endl << 1.139 - "Testing Vector addition" << endl; 1.140 - Vector2i v2i(1,2); 1.141 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.142 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.143 - Vector2i v2i_2(3,4); 1.144 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.145 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.146 - Vector2i v2i_3(0); 1.147 - Vector3f v3f_3(0); 1.148 - Vector4d v4d_3(0); 1.149 - 1.150 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.151 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.152 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.153 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.154 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.155 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.156 - v2i_3 = v2i + v2i_2; 1.157 - v3f_3 = v3f + v3f_2; 1.158 - v4d_3 = v4d + v4d_2; 1.159 - cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string(s1) << endl; 1.160 - cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string(s1) << endl; 1.161 - cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string(s1) << endl; 1.162 - v2i_3 += v2i_2; 1.163 - v3f_3 += v3f_2; 1.164 - v4d_3 += v4d_3; 1.165 - cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string(s1) << endl; 1.166 - cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string(s1) << endl; 1.167 - cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string(s1) << endl; 1.168 - } 1.169 - 1.170 - { 1.171 - cout << "===============================================================" << endl << 1.172 - "Testing Vector subtraction" << endl; 1.173 - Vector2i v2i(1,2); 1.174 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.175 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.176 - Vector2i v2i_2(3,4); 1.177 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.178 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.179 - Vector2i v2i_3(0); 1.180 - Vector3f v3f_3(0); 1.181 - Vector4d v4d_3(0); 1.182 - 1.183 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.184 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.185 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.186 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.187 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.188 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.189 - v2i_3 = v2i - v2i_2; 1.190 - v3f_3 = v3f - v3f_2; 1.191 - v4d_3 = v4d - v4d_2; 1.192 - cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string(s1) << endl; 1.193 - cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string(s1) << endl; 1.194 - cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string(s1) << endl; 1.195 - v2i_3 -= v2i_2; 1.196 - v3f_3 -= v3f_2; 1.197 - v4d_3 -= v4d_3; 1.198 - cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string(s1) << endl; 1.199 - cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string(s1) << endl; 1.200 - cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string(s1) << endl; 1.201 - } 1.202 - 1.203 - { 1.204 - cout << "===============================================================" << endl << 1.205 - "Testing Vector scalar multiplication" << endl; 1.206 - Vector2i v2i(1,2); 1.207 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.208 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.209 - Vector2i v2i_2(0); 1.210 - Vector3f v3f_2(0); 1.211 - Vector4d v4d_2(0); 1.212 - int i = 2; 1.213 - float f = 2.f; 1.214 - double d = 2.0; 1.215 - 1.216 - cout << setw(40) << "i: " << i << endl; 1.217 - cout << setw(40) << "f: " << f << endl; 1.218 - cout << setw(40) << "d: " << d << endl; 1.219 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.220 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.221 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.222 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.223 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.224 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.225 - v2i_2 = v2i * i; 1.226 - v3f_2 = v3f * f; 1.227 - v4d_2 = v4d * d; 1.228 - cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string(s1) << endl; 1.229 - cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string(s1) << endl; 1.230 - cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string(s1) << endl; 1.231 - v2i_2 *= i; 1.232 - v3f_2 *= f; 1.233 - v4d_2 *= d; 1.234 - cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string(s1) << endl; 1.235 - cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string(s1) << endl; 1.236 - cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string(s1) << endl; 1.237 - } 1.238 - 1.239 - { 1.240 - cout << "===============================================================" << endl << 1.241 - "Testing Vector scalar division" << endl; 1.242 - Vector2i v2i(1,2); 1.243 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.244 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.245 - Vector2i v2i_2(0); 1.246 - Vector3f v3f_2(0); 1.247 - Vector4d v4d_2(0); 1.248 - int i = 2; 1.249 - float f = 2.f; 1.250 - double d = 2.0; 1.251 - 1.252 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.253 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.254 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.255 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.256 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.257 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.258 - v2i_2 = v2i / i; 1.259 - v3f_2 = v3f / f; 1.260 - v4d_2 = v4d / d; 1.261 - cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string(s1) << endl; 1.262 - cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string(s1) << endl; 1.263 - cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string(s1) << endl; 1.264 - v2i_2 /= i; 1.265 - v3f_2 /= f; 1.266 - v4d_2 /= d; 1.267 - cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string(s1) << endl; 1.268 - cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string(s1) << endl; 1.269 - cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string(s1) << endl; 1.270 - } 1.271 - 1.272 - { 1.273 - cout << "===============================================================" << endl << 1.274 - "Testing Vector cross product" << endl; 1.275 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.276 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.277 - Vector3f v3f_3(0); 1.278 - Vector3f v3f_4(0); 1.279 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.280 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.281 - cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 1.282 - v3f.cross(v3f_2, v3f_3); 1.283 - cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; 1.284 - v3f_4 = 2.0 * v3f.cross(v3f_2); 1.285 - cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string(s1) << endl; 1.286 - v3f_4.assign(0,0,0); 1.287 - v3f.cross(v3f_2, v3f_4); 1.288 - cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string(s1) << endl; 1.289 - } 1.290 - 1.291 - { 1.292 - cout << "===============================================================" << endl << 1.293 - "Testing Vector dot product" << endl; 1.294 - Vector2i v2i(1, 2); 1.295 - Vector2i v2i_2(3, 4); 1.296 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.297 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.298 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.299 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.300 - int i; 1.301 - float f; 1.302 - double d; 1.303 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.304 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.305 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.306 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.307 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.308 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.309 - i = v2i.dot(v2i_2); 1.310 - cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl; 1.311 - f = v3f.dot(v3f_2); 1.312 - cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl; 1.313 - d = v4d.dot(v4d_2); 1.314 - cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl; 1.315 - } 1.316 - 1.317 - { 1.318 - cout << "===============================================================" << endl << 1.319 - "Testing Vector length" << endl; 1.320 - Vector2i v2i(1, 2); 1.321 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.322 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.323 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.324 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.325 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.326 - cout << setw(40) << "v2i.length(): " << v2i.length() << endl; 1.327 - cout << setw(40) << "v3f.length(): " << v3f.length() << endl; 1.328 - cout << setw(40) << "v4d.length(): " << v4d.length() << endl; 1.329 - } 1.330 - 1.331 - { 1.332 - cout << "===============================================================" << endl << 1.333 - "Testing Vector normalize" << endl; 1.334 - Vector2f v2f(1.1, 2.2); 1.335 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.336 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.337 - cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 1.338 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.339 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.340 - v2f.normalize(); 1.341 - cout << setw(40) << "v2f.normalize() " << v2f.to_string(s1) << endl; 1.342 - v3f.normalize(); 1.343 - cout << setw(40) << "v3f.normalize() " << v3f.to_string(s1) << endl; 1.344 - v4d.normalize(); 1.345 - cout << setw(40) << "v4d.normalize() " << v4d.to_string(s1) << endl; 1.346 - cout << setw(40) << "v2f.length(): " << v2f.length() << endl; 1.347 - cout << setw(40) << "v3f.length(): " << v3f.length() << endl; 1.348 - cout << setw(40) << "v4d.length(): " << v4d.length() << endl; 1.349 - } 1.350 - 1.351 - { 1.352 - cout << "===============================================================" << endl << 1.353 - "Testing Vector get_angle" << endl; 1.354 - Vector2i v2i(1, 2); 1.355 - Vector2i v2i_2(3, 4); 1.356 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.357 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.358 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.359 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.360 - double d; 1.361 - cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 1.362 - cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 1.363 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.364 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.365 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.366 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.367 - d = v2i.get_angle(v2i_2); 1.368 - cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl; 1.369 - d = v3f.get_angle(v3f_2); 1.370 - cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl; 1.371 - d = v4d.get_angle(v4d_2); 1.372 - cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl; 1.373 - } 1.374 - 1.375 - { 1.376 - cout << "===============================================================" << endl << 1.377 - "Testing Vector get_anglen" << endl; 1.378 - Vector2f v2f(1.1, 2.2); 1.379 - Vector2f v2f_2(3.3, 4.4); 1.380 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.381 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.382 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.383 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.384 - double d; 1.385 - v2f.normalize(); 1.386 - v2f_2.normalize(); 1.387 - v3f.normalize(); 1.388 - v3f_2.normalize(); 1.389 - v4d.normalize(); 1.390 - v4d_2.normalize(); 1.391 - cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 1.392 - cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; 1.393 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.394 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.395 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.396 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.397 - d = v2f.get_anglen(v2f_2); 1.398 - cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl; 1.399 - d = v3f.get_anglen(v3f_2); 1.400 - cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl; 1.401 - d = v4d.get_anglen(v4d_2); 1.402 - cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl; 1.403 - } 1.404 - 1.405 - { 1.406 - cout << "===============================================================" << endl << 1.407 - "Testing Vector get_proj" << endl; 1.408 - Vector2f v2f(1.1, 2.2); 1.409 - Vector2f v2f_2(3.3, 4.4); 1.410 - Vector2f v2f_3(0); 1.411 - Vector3f v3f(1.1f, 2.2f, 3.3f); 1.412 - Vector3f v3f_2(4.4, 5.5, 6.6); 1.413 - Vector3f v3f_3(0); 1.414 - Vector4d v4d(1.1, 2.2, 3.3, 4.4); 1.415 - Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 1.416 - Vector4d v4d_3(0); 1.417 - cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 1.418 - cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; 1.419 - cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 1.420 - cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 1.421 - cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 1.422 - cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 1.423 - v2f_3 = v2f.proj(v2f_2); 1.424 - cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string(s1) << endl; 1.425 - v3f_3 = v3f.proj(v3f_2); 1.426 - cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string(s1) << endl; 1.427 - v4d_3 = v4d.proj(v4d_2); 1.428 - cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string(s1) << endl; 1.429 - v2f_3.assign(0,0); 1.430 - v3f_3.assign(0,0,0); 1.431 - v4d_3.assign(0,0,0,0); 1.432 - v2f.proj(v2f_2, v2f_3); 1.433 - cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string(s1) << endl; 1.434 - v3f.proj(v3f_2, v3f_3); 1.435 - cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; 1.436 - v4d.proj(v4d_2, v4d_3); 1.437 - cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string(s1) << endl; 1.438 - } 1.439 - 1.440 - } 1.441 - 1.442 -//////////////////////////////////////////////////////////////////////////////// 1.443 -void test_matrix(void) 1.444 - { 1.445 - string s1, s2; 1.446 - 1.447 - { 1.448 - cout << "===============================================================" << endl << 1.449 - "Testing Maxtrix constructors" << endl; 1.450 - Matrix22i m22i_1(0); 1.451 - Matrix22i m22i_2(1); 1.452 - Matrix22i m22i_3(1, 2, 3, 4); 1.453 - Matrix22i m22i_4(m22i_3); 1.454 - 1.455 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.456 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.457 - cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 1.458 - cout << setw(40) << "m22i_4: " << m22i_4.to_string(s1) << endl; 1.459 - 1.460 - Matrix33f m33f_1(0.0f); 1.461 - Matrix33f m33f_2(1.1f); 1.462 - Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.463 - Matrix33f m33f_4(m33f_3); 1.464 - 1.465 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.466 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.467 - cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 1.468 - cout << setw(40) << "m33f_4: " << m33f_4.to_string(s1) << endl; 1.469 - 1.470 - Matrix44d m44d_1(0.0); 1.471 - Matrix44d m44d_2(1.1); 1.472 - Matrix44d m44d_3(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.473 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.474 - Matrix44d m44d_4(m44d_3); 1.475 - 1.476 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.477 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.478 - cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 1.479 - cout << setw(40) << "m44d_4: " << m44d_4.to_string(s1) << endl; 1.480 - } 1.481 - 1.482 - { 1.483 - cout << "===============================================================" << endl << 1.484 - "Testing Maxtrix array indexing" << endl; 1.485 - Matrix22i m22i(1, 2, 3, 4); 1.486 - 1.487 - cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl; 1.488 - 1.489 - Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.490 - 1.491 - cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl; 1.492 - 1.493 - Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.494 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.495 - 1.496 - cout << setw(40) << "m44d: " << m44d[0] << " " << m44d[1] << " " << m44d[2] << " " << m44d[3] << " " << m44d[4] << " " << m44d[5] << " " << m44d[6] << " " << m44d[7] << " " << m44d[8] << " " << m44d[9] << " " << m44d[10] << " " << m44d[11] << " " << m44d[12] << " " << m44d[13] << " " << m44d[14] << " " << m44d[15] << endl; 1.497 - } 1.498 - 1.499 - { 1.500 - cout << "===============================================================" << endl << 1.501 - "Testing Maxtrix assignment" << endl; 1.502 - Matrix22i m22i_1(1, 2, 3, 4); 1.503 - Matrix22i m22i_2(5, 6, 7, 8); 1.504 - 1.505 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.506 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.507 - 1.508 - m22i_2 = m22i_1; 1.509 - cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string(s1) << endl; 1.510 - 1.511 - m22i_2.assign(9, 10, 11, 12); 1.512 - cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): " 1.513 - << m22i_2.to_string(s1) << endl; 1.514 - 1.515 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.516 - Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 1.517 - 1.518 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.519 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.520 - 1.521 - m33f_2 = m33f_1; 1.522 - cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string(s1) << endl; 1.523 - 1.524 - m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f); 1.525 - cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): " 1.526 - << m33f_2.to_string(s1) << endl; 1.527 - 1.528 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.529 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.530 - Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 1.531 - 20.20, 21.21, 22.22, 23.23, 1.532 - 24.24, 25.25, 26.26, 27.27, 1.533 - 28.28, 29.29, 30.30, 31.31); 1.534 - 1.535 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.536 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.537 - 1.538 - m44d_2 = m44d_1; 1.539 - cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string(s1) << endl; 1.540 - 1.541 - m44d_2.assign(32.32, 33.33, 34.34, 35.35, 1.542 - 36.36, 37.37, 38.38, 39.39, 1.543 - 40.40, 41.41, 42.42, 43.43, 1.544 - 44.44, 45.45, 46.46, 47.47); 1.545 - cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): " 1.546 - << m44d_2.to_string(s1) << endl; 1.547 - } 1.548 - 1.549 - { 1.550 - cout << "===============================================================" << endl << 1.551 - "Testing Maxtrix comparison" << endl; 1.552 - Matrix22i m22i_1(1, 2, 3, 4); 1.553 - Matrix22i m22i_2(1, 2, 3, 4); 1.554 - Matrix22i m22i_3(0); 1.555 - 1.556 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.557 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.558 - cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 1.559 - cout << boolalpha; 1.560 - cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl; 1.561 - cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl; 1.562 - cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl; 1.563 - cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl; 1.564 - 1.565 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.566 - Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.567 - Matrix33f m33f_3(0.0f); 1.568 - 1.569 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.570 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.571 - cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 1.572 - cout << boolalpha; 1.573 - cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl; 1.574 - cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl; 1.575 - cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl; 1.576 - cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl; 1.577 - 1.578 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.579 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.580 - Matrix44d m44d_2(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.581 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.582 - Matrix44d m44d_3(0.0); 1.583 - 1.584 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.585 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.586 - cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 1.587 - cout << boolalpha; 1.588 - cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl; 1.589 - cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl; 1.590 - cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl; 1.591 - cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl; 1.592 - } 1.593 - 1.594 - { 1.595 - cout << "===============================================================" << endl << 1.596 - "Testing Maxtrix addition" << endl; 1.597 - Matrix22i m22i_1(1, 2, 3, 4); 1.598 - Matrix22i m22i_2(5, 6, 7, 8); 1.599 - Matrix22i m22i_3(0); 1.600 - 1.601 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.602 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.603 - cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 1.604 - m22i_3 = m22i_1 + m22i_2; 1.605 - cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string(s1) << endl; 1.606 - 1.607 - m22i_3 += m22i_1; 1.608 - cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string(s1) << endl; 1.609 - 1.610 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.611 - Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 1.612 - Matrix33f m33f_3(0.0f); 1.613 - 1.614 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.615 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.616 - cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 1.617 - m33f_3 = m33f_1 + m33f_2; 1.618 - cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string(s1) << endl; 1.619 - 1.620 - m33f_3 += m33f_1; 1.621 - cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string(s1) << endl; 1.622 - 1.623 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.624 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.625 - Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 1.626 - 20.20, 21.21, 22.22, 23.23, 1.627 - 24.24, 25.25, 26.26, 27.27, 1.628 - 28.28, 29.29, 30.30, 31.31); 1.629 - Matrix44d m44d_3(0.0); 1.630 - 1.631 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.632 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.633 - cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 1.634 - m44d_3 = m44d_1 + m44d_2; 1.635 - cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string(s1) << endl; 1.636 - 1.637 - m44d_3 += m44d_1; 1.638 - cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string(s1) << endl; 1.639 - } 1.640 - 1.641 - { 1.642 - cout << "===============================================================" << endl << 1.643 - "Testing Maxtrix subtraction" << endl; 1.644 - Matrix22i m22i_1(1, 2, 3, 4); 1.645 - Matrix22i m22i_2(5, 6, 7, 8); 1.646 - Matrix22i m22i_3(0); 1.647 - 1.648 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.649 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.650 - cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 1.651 - m22i_3 = m22i_1 - m22i_2; 1.652 - cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string(s1) << endl; 1.653 - 1.654 - m22i_3 -= m22i_1; 1.655 - cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string(s1) << endl; 1.656 - 1.657 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.658 - Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 1.659 - Matrix33f m33f_3(0.0f); 1.660 - 1.661 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.662 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.663 - cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 1.664 - m33f_3 = m33f_1 - m33f_2; 1.665 - cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string(s1) << endl; 1.666 - 1.667 - m33f_3 -= m33f_1; 1.668 - cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string(s1) << endl; 1.669 - 1.670 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.671 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.672 - Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 1.673 - 20.20, 21.21, 22.22, 23.23, 1.674 - 24.24, 25.25, 26.26, 27.27, 1.675 - 28.28, 29.29, 30.30, 31.31); 1.676 - Matrix44d m44d_3(0.0); 1.677 - 1.678 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.679 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.680 - cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 1.681 - m44d_3 = m44d_1 - m44d_2; 1.682 - cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string(s1) << endl; 1.683 - 1.684 - m44d_3 -= m44d_1; 1.685 - cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string(s1) << endl; 1.686 - } 1.687 - 1.688 - { 1.689 - cout << "===============================================================" << endl << 1.690 - "Testing Matrix scalar multiplication" << endl; 1.691 - Matrix22i m22i_1(1, 2, 3, 4); 1.692 - Matrix22i m22i_2(0); 1.693 - int i = 2; 1.694 - 1.695 - cout << setw(40) << "i: " << i << endl; 1.696 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.697 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.698 - m22i_2 = m22i_1 *i; 1.699 - cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string(s1) << endl; 1.700 - m22i_2 = i * m22i_1; 1.701 - cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string(s1) << endl; 1.702 - m22i_2 *= i; 1.703 - cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string(s1) << endl; 1.704 - 1.705 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.706 - Matrix33f m33f_2(0.0f); 1.707 - float f = 2.0f; 1.708 - 1.709 - cout << setw(40) << "f: " << f << endl; 1.710 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.711 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.712 - m33f_2 = m33f_1 * f; 1.713 - cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string(s1) << endl; 1.714 - m33f_2 = f * m33f_1; 1.715 - cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string(s1) << endl; 1.716 - m33f_2 *= f; 1.717 - cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string(s1) << endl; 1.718 - 1.719 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.720 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.721 - Matrix44d m44d_2(0.0); 1.722 - double d = 2.0f; 1.723 - 1.724 - cout << setw(40) << "d: " << d << endl; 1.725 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.726 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.727 - m44d_2 = m44d_1 * d; 1.728 - cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string(s1) << endl; 1.729 - m44d_2 = d * m44d_1; 1.730 - cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string(s1) << endl; 1.731 - m44d_2 *= d; 1.732 - cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string(s1) << endl; 1.733 - } 1.734 - 1.735 - { 1.736 - cout << "===============================================================" << endl << 1.737 - "Testing Matrix scalar division" << endl; 1.738 - Matrix22i m22i_1(1, 2, 3, 4); 1.739 - Matrix22i m22i_2(0); 1.740 - int i = 2; 1.741 - 1.742 - cout << setw(40) << "i: " << i << endl; 1.743 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.744 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.745 - m22i_2 = m22i_1 / i; 1.746 - cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string(s1) << endl; 1.747 - m22i_1 /= i; 1.748 - cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string(s1) << endl; 1.749 - 1.750 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.751 - Matrix33f m33f_2(0.0f); 1.752 - float f = 2.0f; 1.753 - 1.754 - cout << setw(40) << "f: " << f << endl; 1.755 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.756 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.757 - m33f_2 = m33f_1 / f; 1.758 - cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string(s1) << endl; 1.759 - m33f_1 /= f; 1.760 - cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string(s1) << endl; 1.761 - 1.762 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.763 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.764 - Matrix44d m44d_2(0.0); 1.765 - double d = 2.0f; 1.766 - 1.767 - cout << setw(40) << "d: " << d << endl; 1.768 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.769 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.770 - m44d_2 = m44d_1 / d; 1.771 - cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string(s1) << endl; 1.772 - m44d_1 /= d; 1.773 - cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string(s1) << endl; 1.774 - } 1.775 - 1.776 - { 1.777 - cout << "===============================================================" << endl << 1.778 - "Testing Maxtrix multiplication" << endl; 1.779 - Matrix22i m22i_1(1, 2, 3, 4); 1.780 - Matrix22i m22i_2(5, 6, 7, 8); 1.781 - Matrix22i m22i_3(0); 1.782 - 1.783 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.784 - cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 1.785 - cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 1.786 - m22i_3 = m22i_1 * m22i_2; 1.787 - cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string(s1) << endl; 1.788 - 1.789 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.790 - Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 1.791 - Matrix33f m33f_3(0.0f); 1.792 - 1.793 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.794 - cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 1.795 - cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 1.796 - m33f_3 = m33f_1 * m33f_2; 1.797 - cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string(s1) << endl; 1.798 - 1.799 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.800 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.801 - Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 1.802 - 20.20, 21.21, 22.22, 23.23, 1.803 - 24.24, 25.25, 26.26, 27.27, 1.804 - 28.28, 29.29, 30.30, 31.31); 1.805 - Matrix44d m44d_3(0.0); 1.806 - 1.807 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.808 - cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 1.809 - cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 1.810 - m44d_3 = m44d_1 * m44d_2; 1.811 - cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string(s1) << endl; 1.812 - } 1.813 - 1.814 - { 1.815 - cout << "===============================================================" << endl << 1.816 - "Testing Maxtrix det" << endl; 1.817 - Matrix22i m22i_1(1, 2, 3, 4); 1.818 - double d; 1.819 - 1.820 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.821 - d = det(m22i_1); 1.822 - cout << setw(40) << "d = det(m22i_1): " << d << endl; 1.823 - 1.824 - // Note: singular matrix. The real determinant is exactly zero. 1.825 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.826 - 1.827 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.828 - d = det(m33f_1); 1.829 - cout << setw(40) << "d = det(m33f_1): " << d << endl; 1.830 - 1.831 - // Note: singular matrix. The real determinant is exactly zero. 1.832 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.833 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.834 - 1.835 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.836 - d = det(m44d_1); 1.837 - cout << setw(40) << "d = det(m44d_1): " << d << endl; 1.838 - 1.839 - } 1.840 - 1.841 - { 1.842 - cout << "===============================================================" << endl << 1.843 - "Testing Maxtrix transpose" << endl; 1.844 - Matrix22i m22i_1(1, 2, 3, 4); 1.845 - Matrix22i m22i_2; 1.846 - 1.847 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.848 - m22i_2 = transpose(m22i_1); 1.849 - cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string(s1) << endl; 1.850 - 1.851 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.852 - Matrix33f m33f_2(0.0f); 1.853 - 1.854 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.855 - m33f_2 = transpose(m33f_1); 1.856 - cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string(s1) << endl; 1.857 - 1.858 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.859 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.860 - Matrix44d m44d_2(0.0); 1.861 - 1.862 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.863 - m44d_2 = transpose(m44d_1); 1.864 - cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string(s1) << endl; 1.865 - } 1.866 - 1.867 - { 1.868 - cout << "===============================================================" << endl << 1.869 - "Testing Maxtrix setidentity" << endl; 1.870 - Matrix22i m22i_1(1, 2, 3, 4); 1.871 - 1.872 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.873 - m22i_1.setidentity(); 1.874 - cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string(s1) << endl; 1.875 - 1.876 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.877 - 1.878 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.879 - m33f_1.setidentity(); 1.880 - cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string(s1) << endl; 1.881 - 1.882 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.883 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.884 - 1.885 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.886 - m44d_1.setidentity(); 1.887 - cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string(s1) << endl; 1.888 - } 1.889 - 1.890 - { 1.891 - cout << "===============================================================" << endl << 1.892 - "Testing Matrix getrow() and getcol()" << endl; 1.893 - Matrix22i m22i_1(1, 2, 3, 4); 1.894 - Vector2i v2i_1(0); 1.895 - 1.896 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.897 - v2i_1 = m22i_1.getrow(0); 1.898 - cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string(s1) << endl; 1.899 - v2i_1 = m22i_1.getrow(1); 1.900 - cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string(s1) << endl; 1.901 - v2i_1 = m22i_1.getcol(0); 1.902 - cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string(s1) << endl; 1.903 - v2i_1 = m22i_1.getcol(1); 1.904 - cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string(s1) << endl; 1.905 - 1.906 - Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 1.907 - Vector3f v3f_1(0); 1.908 - 1.909 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.910 - v3f_1 = m33f_1.getrow(0); 1.911 - cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string(s1) << endl; 1.912 - v3f_1 = m33f_1.getrow(1); 1.913 - cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string(s1) << endl; 1.914 - v3f_1 = m33f_1.getrow(2); 1.915 - cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string(s1) << endl; 1.916 - v3f_1 = m33f_1.getcol(0); 1.917 - cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string(s1) << endl; 1.918 - v3f_1 = m33f_1.getcol(1); 1.919 - cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string(s1) << endl; 1.920 - v3f_1 = m33f_1.getcol(2); 1.921 - cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string(s1) << endl; 1.922 - 1.923 - Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 1.924 - 12.12, 13.13, 14.14, 15.15, 16.16); 1.925 - Vector4d v4d_1(0); 1.926 - 1.927 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.928 - v4d_1 = m44d_1.getrow(0); 1.929 - cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string(s1) << endl; 1.930 - v4d_1 = m44d_1.getrow(1); 1.931 - cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string(s1) << endl; 1.932 - v4d_1 = m44d_1.getrow(2); 1.933 - cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string(s1) << endl; 1.934 - v4d_1 = m44d_1.getrow(3); 1.935 - cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string(s1) << endl; 1.936 - 1.937 - v4d_1 = m44d_1.getcol(0); 1.938 - cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string(s1) << endl; 1.939 - v4d_1 = m44d_1.getcol(1); 1.940 - cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string(s1) << endl; 1.941 - v4d_1 = m44d_1.getcol(2); 1.942 - cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string(s1) << endl; 1.943 - v4d_1 = m44d_1.getcol(3); 1.944 - cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string(s1) << endl; 1.945 - } 1.946 - 1.947 - { 1.948 - cout << "===============================================================" << endl << 1.949 - "Testing Matrix setrow() and setcol()" << endl; 1.950 - Matrix22i m22i_1; 1.951 - Vector2i v2i_1(2, 3); 1.952 - 1.953 - m22i_1.setidentity(); 1.954 - cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 1.955 - m22i_1.setrow(0, v2i_1); 1.956 - cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string(s1) << endl; 1.957 - 1.958 - m22i_1.setidentity(); 1.959 - m22i_1.setrow(1, v2i_1); 1.960 - cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string(s1) << endl; 1.961 - 1.962 - m22i_1.setidentity(); 1.963 - m22i_1.setrow(1, 4, 5); 1.964 - cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string(s1) << endl; 1.965 - 1.966 - m22i_1.setidentity(); 1.967 - m22i_1.setcol(0, v2i_1); 1.968 - cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string(s1) << endl; 1.969 - 1.970 - m22i_1.setidentity(); 1.971 - m22i_1.setcol(1, v2i_1); 1.972 - cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string(s1) << endl; 1.973 - 1.974 - m22i_1.setidentity(); 1.975 - m22i_1.setcol(1, 4, 5); 1.976 - cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string(s1) << endl; 1.977 - 1.978 - Matrix33f m33f_1; 1.979 - Vector3f v3f_1(0); 1.980 - 1.981 - m33f_1.setidentity(); 1.982 - cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 1.983 - m33f_1.setrow(0, v3f_1); 1.984 - cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string(s1) << endl; 1.985 - 1.986 - m33f_1.setidentity(); 1.987 - m33f_1.setrow(1, v3f_1); 1.988 - cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string(s1) << endl; 1.989 - 1.990 - m33f_1.setidentity(); 1.991 - m33f_1.setrow(1, 2.2f, 3.3f, 4.4f); 1.992 - cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): " 1.993 - << m33f_1.to_string(s1) << endl; 1.994 - 1.995 - m33f_1.setidentity(); 1.996 - m33f_1.setcol(0, v3f_1); 1.997 - cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string(s1) << endl; 1.998 - 1.999 - m33f_1.setidentity(); 1.1000 - m33f_1.setcol(1, v3f_1); 1.1001 - cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string(s1) << endl; 1.1002 - 1.1003 - m33f_1.setidentity(); 1.1004 - m33f_1.setcol(1, 2.2f, 3.3f, 4.4f); 1.1005 - cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: " 1.1006 - << m33f_1.to_string(s1) << endl; 1.1007 - 1.1008 - Matrix44d m44d_1; 1.1009 - Vector4d v4d_1(0); 1.1010 - 1.1011 - m44d_1.setidentity(); 1.1012 - cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 1.1013 - m44d_1.setrow(0, v4d_1); 1.1014 - cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string(s1) << endl; 1.1015 - 1.1016 - m44d_1.setidentity(); 1.1017 - m44d_1.setrow(1, v4d_1); 1.1018 - cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string(s1) << endl; 1.1019 - 1.1020 - m44d_1.setidentity(); 1.1021 - m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5); 1.1022 - cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): " 1.1023 - << m44d_1.to_string(s1) << endl; 1.1024 - 1.1025 - m44d_1.setidentity(); 1.1026 - m44d_1.setcol(0, v4d_1); 1.1027 - cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string(s1) << endl; 1.1028 - 1.1029 - m44d_1.setidentity(); 1.1030 - m44d_1.setcol(1, v4d_1); 1.1031 - cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string(s1) << endl; 1.1032 - 1.1033 - m44d_1.setidentity(); 1.1034 - m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5); 1.1035 - cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: " 1.1036 - << m44d_1.to_string(s1) << endl; 1.1037 - } 1.1038 - } 1.1039 - 1.1040 -//////////////////////////////////////////////////////////////////////////////// 1.1041 -void test_all(void) 1.1042 - { 1.1043 - test_vector(); 1.1044 - test_matrix(); 1.1045 - } 1.1046 - 1.1047 -//////////////////////////////////////////////////////////////////////////////// 1.1048 -void show_menu(void) 1.1049 - { 1.1050 - cout << endl << endl 1.1051 - << "Test what?" << endl 1.1052 - << "0) All" << endl << endl 1.1053 - << "1) Vector" << endl 1.1054 - << "2) Matrix" << endl 1.1055 - << endl 1.1056 - << "99 Quit" << endl; 1.1057 - } 1.1058 - 1.1059 -//////////////////////////////////////////////////////////////////////////////// 1.1060 -int main (int argc, char * argv[]) 1.1061 - { 1.1062 - int retval = 0; 1.1063 - 1.1064 - test_all(); 1.1065 - return 0; 1.1066 - 1.1067 - try 1.1068 - { 1.1069 - int choice = -1; 1.1070 - 1.1071 - while (choice != 99) 1.1072 - { 1.1073 - show_menu(); 1.1074 - cin >> choice; 1.1075 - if(!cin) 1.1076 - { 1.1077 - cin.clear(); 1.1078 - cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); 1.1079 - } 1.1080 - if (choice != 99) 1.1081 - { 1.1082 - switch (choice) 1.1083 - { 1.1084 - case 0: 1.1085 - test_all(); 1.1086 - break; 1.1087 - case 1: 1.1088 - test_vector(); 1.1089 - break; 1.1090 - case 2: 1.1091 - test_matrix(); 1.1092 - break; 1.1093 - default: 1.1094 - cout << "Unrecognized choice. Please try again." << endl; 1.1095 - } 1.1096 - choice = -1; 1.1097 - } 1.1098 - } 1.1099 - } 1.1100 - catch (const std::exception & error) 1.1101 - { 1.1102 - string e = "Caught exception: "; 1.1103 - e += error.what(); 1.1104 - cerr << e << endl; 1.1105 - retval = 1; 1.1106 - } 1.1107 - 1.1108 - return retval;; 1.1109 - 1.1110 - }