Mercurial > Math
changeset 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 |
files | .hgignore CMakeLists.txt include/Math.h include/Matrix.h include/Vector.h notes src/Math.cpp src/Matrix.cpp src/Vector.cpp src/main.cpp |
diffstat | 10 files changed, 1713 insertions(+), 458 deletions(-) [+] |
line diff
1.1 --- a/.hgignore Sun Sep 04 12:46:08 2011 -0500 1.2 +++ b/.hgignore Tue Sep 06 11:26:39 2011 -0500 1.3 @@ -2,4 +2,4 @@ 1.4 1.5 build*/* 1.6 *~ 1.7 - 1.8 +tmp/*
2.1 --- a/CMakeLists.txt Sun Sep 04 12:46:08 2011 -0500 2.2 +++ b/CMakeLists.txt Tue Sep 06 11:26:39 2011 -0500 2.3 @@ -138,8 +138,11 @@ 2.4 # test driver. Also, it just seems good practice to explicitly list things since 2.5 # it avoids accidental inclusion of things that ought not to be included. 2.6 set (SRCS_${App_Name} 2.7 - src/Math.cpp 2.8 + src/Vector.cpp 2.9 + src/Matrix.cpp 2.10 include/Math.h 2.11 + include/Vector.h 2.12 + include/Matrix.h 2.13 ) 2.14 2.15 include_directories (
3.1 --- a/include/Math.h Sun Sep 04 12:46:08 2011 -0500 3.2 +++ b/include/Math.h Tue Sep 06 11:26:39 2011 -0500 3.3 @@ -2,6 +2,7 @@ 3.4 #define MATH_H_ 3.5 3.6 #include "Vector.h" 3.7 +#include "Matrix.h" 3.8 3.9 namespace arda 3.10 {
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/include/Matrix.h Tue Sep 06 11:26:39 2011 -0500 4.3 @@ -0,0 +1,412 @@ 4.4 +#ifndef MATRIX_H_ 4.5 +#define MATRIX_H_ 4.6 + 4.7 +#include "Vector.h" 4.8 +using namespace arda::Vector; 4.9 + 4.10 +#include <cmath> 4.11 +#include <string> 4.12 + 4.13 +namespace arda 4.14 + { 4.15 + namespace Matrix 4.16 + { 4.17 + ////////////////////////////////////////////////////////////////////////// 4.18 + // Maxtrices 4.19 + // 4.20 + // Supported operations on matrices 4.21 + // 4.22 + // getstring*() Returns a printable string representation of the matrix. 4.23 + // assign*() Assign the value of one matrix to another. 4.24 + // add*() Add two matrices 4.25 + // subtract*() A convenience function to avoid writing 4.26 + // add(m1, scale(m2, -1)) 4.27 + // transpose*() Returns the transpose of a matrix. 4.28 + // scale*() Multiplies a matrix by a scalar. 4.29 + // multvec*() Multiplies a matrix by a vector. 4.30 + // multmat*() Multiplies a matrix by another matrix. 4.31 + // det*() Calculates the determinant of a matrix. 4.32 + // inverse*() Returns the inverse of a non-singular matrix. 4.33 + // setidentity*() Sets a matrix to the identity matrix. 4.34 + // getcol*() Returns the vector that is column n of the matrix. 4.35 + // setcol*() Set the vector that is column n of the matrix. 4.36 + // 4.37 + // assign*(), add*(), and subtract*() are defined inline, though this might 4.38 + // might not be the best thing. Some real world testing is needed to decide 4.39 + // whether or not htye should be remain inline. 4.40 + 4.41 + typedef int Matrix2i[4]; 4.42 + typedef float Matrix2f[4]; 4.43 + typedef double Matrix2d[4]; 4.44 + 4.45 + typedef int Matrix3i[9]; 4.46 + typedef float Matrix3f[9]; 4.47 + typedef double Matrix3d[9]; 4.48 + 4.49 + typedef int Matrix4i[16]; 4.50 + typedef float Matrix4f[16]; 4.51 + typedef double Matrix4d[16]; 4.52 + 4.53 + ////////////////////////////////////////////////////////////////////////// 4.54 + // getstring*() 4.55 + std::string & getstring2m(Matrix2i m, std::string & s); 4.56 + std::string & getstring2m(Matrix2f m, std::string & s); 4.57 + std::string & getstring2m(Matrix2d m, std::string & s); 4.58 + 4.59 + std::string & getstring3m(Matrix3i m, std::string & s); 4.60 + std::string & getstring3m(Matrix3f m, std::string & s); 4.61 + std::string & getstring3m(Matrix3d m, std::string & s); 4.62 + 4.63 + std::string & getstring4m(Matrix4i m, std::string & s); 4.64 + std::string & getstring4m(Matrix4f m, std::string & s); 4.65 + std::string & getstring4m(Matrix4d m, std::string & s); 4.66 + 4.67 + ////////////////////////////////////////////////////////////////////////// 4.68 + // assign*() 4.69 + 4.70 + inline int * assign2m(Matrix2i m1, Matrix2i m2) 4.71 + { 4.72 + m1[0] = m2[0]; m1[1] = m2[1]; 4.73 + m1[2] = m2[2]; m1[3] = m2[3]; 4.74 + return m1; 4.75 + } 4.76 + inline float * assign2m(Matrix2f m1, Matrix2f m2) 4.77 + { 4.78 + m1[0] = m2[0]; m1[1] = m2[1]; 4.79 + m1[2] = m2[2]; m1[3] = m2[3]; 4.80 + return m1; 4.81 + } 4.82 + inline double * assign2m(Matrix2d m1, Matrix2d m2) 4.83 + { 4.84 + m1[0] = m2[0]; m1[1] = m2[1]; 4.85 + m1[2] = m2[2]; m1[3] = m2[3]; 4.86 + return m1; 4.87 + } 4.88 + 4.89 + inline int * assign3m(Matrix3i m1, Matrix3i m2) 4.90 + { 4.91 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; 4.92 + m1[3] = m2[3]; m1[4] = m2[4]; m1[5] = m2[5]; 4.93 + m1[6] = m2[6]; m1[7] = m2[7]; m1[8] = m2[8]; 4.94 + return m1; 4.95 + } 4.96 + inline float * assign3m(Matrix3f m1, Matrix3f m2) 4.97 + { 4.98 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; 4.99 + m1[3] = m2[3]; m1[4] = m2[4]; m1[5] = m2[5]; 4.100 + m1[6] = m2[6]; m1[7] = m2[7]; m1[8] = m2[8]; 4.101 + return m1; 4.102 + } 4.103 + inline double * assign3m(Matrix3d m1, Matrix3d m2) 4.104 + { 4.105 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; 4.106 + m1[3] = m2[3]; m1[4] = m2[4]; m1[5] = m2[5]; 4.107 + m1[6] = m2[6]; m1[7] = m2[7]; m1[8] = m2[8]; 4.108 + return m1; 4.109 + } 4.110 + 4.111 + inline int * assign4m(Matrix4i m1, Matrix4i m2) 4.112 + { 4.113 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; m1[3] = m2[3]; 4.114 + m1[4] = m2[4]; m1[5] = m2[5]; m1[6] = m2[6]; m1[7] = m2[7]; 4.115 + m1[8] = m2[8]; m1[9] = m2[9]; m1[10] = m2[10]; m1[11] = m2[11]; 4.116 + m1[12] = m2[12]; m1[13] = m2[13]; m1[14] = m2[14]; m1[15] = m2[15]; 4.117 + return m1; 4.118 + } 4.119 + inline float * assign4m(Matrix4f m1, Matrix4f m2) 4.120 + { 4.121 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; m1[3] = m2[3]; 4.122 + m1[4] = m2[4]; m1[5] = m2[5]; m1[6] = m2[6]; m1[7] = m2[7]; 4.123 + m1[8] = m2[8]; m1[9] = m2[9]; m1[10] = m2[10]; m1[11] = m2[11]; 4.124 + m1[12] = m2[12]; m1[13] = m2[13]; m1[14] = m2[14]; m1[15] = m2[15]; 4.125 + return m1; 4.126 + } 4.127 + inline double * assign4m(Matrix4d m1, Matrix4d m2) 4.128 + { 4.129 + m1[0] = m2[0]; m1[1] = m2[1]; m1[2] = m2[2]; m1[3] = m2[3]; 4.130 + m1[4] = m2[4]; m1[5] = m2[5]; m1[6] = m2[6]; m1[7] = m2[7]; 4.131 + m1[8] = m2[8]; m1[9] = m2[9]; m1[10] = m2[10]; m1[11] = m2[11]; 4.132 + m1[12] = m2[12]; m1[13] = m2[13]; m1[14] = m2[14]; m1[15] = m2[15]; 4.133 + return m1; 4.134 + } 4.135 + 4.136 + ////////////////////////////////////////////////////////////////////////// 4.137 + // add*() 4.138 + 4.139 + inline int * add2m(Matrix2i m1, Matrix2i m2) 4.140 + { 4.141 + m1[0] += m2[0]; m1[1] += m2[1]; 4.142 + m1[2] += m2[2]; m1[3] += m2[3]; 4.143 + return m1; 4.144 + } 4.145 + inline float * add2m(Matrix2f m1, Matrix2f m2) 4.146 + { 4.147 + m1[0] += m2[0]; m1[1] += m2[1]; 4.148 + m1[2] += m2[2]; m1[3] += m2[3]; 4.149 + return m1; 4.150 + } 4.151 + inline double * add2m(Matrix2d m1, Matrix2d m2) 4.152 + { 4.153 + m1[0] += m2[0]; m1[1] += m2[1]; 4.154 + m1[2] += m2[2]; m1[3] += m2[3]; 4.155 + return m1; 4.156 + } 4.157 + 4.158 + inline int * add3m(Matrix3i m1, Matrix3i m2) 4.159 + { 4.160 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; 4.161 + m1[3] += m2[3]; m1[4] += m2[4]; m1[5] += m2[5]; 4.162 + m1[6] += m2[6]; m1[7] += m2[7]; m1[8] += m2[8]; 4.163 + return m1; 4.164 + } 4.165 + inline float * add3m(Matrix3f m1, Matrix3f m2) 4.166 + { 4.167 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; 4.168 + m1[3] += m2[3]; m1[4] += m2[4]; m1[5] += m2[5]; 4.169 + m1[6] += m2[6]; m1[7] += m2[7]; m1[8] += m2[8]; 4.170 + return m1; 4.171 + } 4.172 + inline double * add3m(Matrix3d m1, Matrix3d m2) 4.173 + { 4.174 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; 4.175 + m1[3] += m2[3]; m1[4] += m2[4]; m1[5] += m2[5]; 4.176 + m1[6] += m2[6]; m1[7] += m2[7]; m1[8] += m2[8]; 4.177 + return m1; 4.178 + } 4.179 + 4.180 + inline int * add4m(Matrix4i m1, Matrix4i m2) 4.181 + { 4.182 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; m1[3] += m2[3]; 4.183 + m1[4] += m2[4]; m1[5] += m2[5]; m1[6] += m2[6]; m1[7] += m2[7]; 4.184 + m1[8] += m2[8]; m1[9] += m2[9]; m1[10] += m2[10]; m1[11] += m2[11]; 4.185 + m1[12] += m2[12]; m1[13] += m2[13]; m1[14] += m2[14]; m1[15] += m2[15]; 4.186 + return m1; 4.187 + } 4.188 + inline float * add4m(Matrix4f m1, Matrix4f m2) 4.189 + { 4.190 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; m1[3] += m2[3]; 4.191 + m1[4] += m2[4]; m1[5] += m2[5]; m1[6] += m2[6]; m1[7] += m2[7]; 4.192 + m1[8] += m2[8]; m1[9] += m2[9]; m1[10] += m2[10]; m1[11] += m2[11]; 4.193 + m1[12] += m2[12]; m1[13] += m2[13]; m1[14] += m2[14]; m1[15] += m2[15]; 4.194 + return m1; 4.195 + } 4.196 + inline double * add4m(Matrix4d m1, Matrix4d m2) 4.197 + { 4.198 + m1[0] += m2[0]; m1[1] += m2[1]; m1[2] += m2[2]; m1[3] += m2[3]; 4.199 + m1[4] += m2[4]; m1[5] += m2[5]; m1[6] += m2[6]; m1[7] += m2[7]; 4.200 + m1[8] += m2[8]; m1[9] += m2[9]; m1[10] += m2[10]; m1[11] += m2[11]; 4.201 + m1[12] += m2[12]; m1[13] += m2[13]; m1[14] += m2[14]; m1[15] += m2[15]; 4.202 + return m1; 4.203 + } 4.204 + 4.205 + ////////////////////////////////////////////////////////////////////////// 4.206 + // subtract*() 4.207 + 4.208 + inline int * subtract2m(Matrix2i m1, Matrix2i m2) 4.209 + { 4.210 + m1[0] -= m2[0]; m1[1] -= m2[1]; 4.211 + m1[2] -= m2[2]; m1[3] -= m2[3]; 4.212 + return m1; 4.213 + } 4.214 + inline float * subtract2m(Matrix2f m1, Matrix2f m2) 4.215 + { 4.216 + m1[0] -= m2[0]; m1[1] -= m2[1]; 4.217 + m1[2] -= m2[2]; m1[3] -= m2[3]; 4.218 + return m1; 4.219 + } 4.220 + inline double * subtract2m(Matrix2d m1, Matrix2d m2) 4.221 + { 4.222 + m1[0] -= m2[0]; m1[1] -= m2[1]; 4.223 + m1[2] -= m2[2]; m1[3] -= m2[3]; 4.224 + return m1; 4.225 + } 4.226 + 4.227 + inline int * subtract3m(Matrix3i m1, Matrix3i m2) 4.228 + { 4.229 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; 4.230 + m1[3] -= m2[3]; m1[4] -= m2[4]; m1[5] -= m2[5]; 4.231 + m1[6] -= m2[6]; m1[7] -= m2[7]; m1[8] -= m2[8]; 4.232 + return m1; 4.233 + } 4.234 + inline float * subtract3m(Matrix3f m1, Matrix3f m2) 4.235 + { 4.236 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; 4.237 + m1[3] -= m2[3]; m1[4] -= m2[4]; m1[5] -= m2[5]; 4.238 + m1[6] -= m2[6]; m1[7] -= m2[7]; m1[8] -= m2[8]; 4.239 + return m1; 4.240 + } 4.241 + inline double * subtract3m(Matrix3d m1, Matrix3d m2) 4.242 + { 4.243 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; 4.244 + m1[3] -= m2[3]; m1[4] -= m2[4]; m1[5] -= m2[5]; 4.245 + m1[6] -= m2[6]; m1[7] -= m2[7]; m1[8] -= m2[8]; 4.246 + return m1; 4.247 + } 4.248 + 4.249 + inline int * subtract4m(Matrix4i m1, Matrix4i m2) 4.250 + { 4.251 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; m1[3] -= m2[3]; 4.252 + m1[4] -= m2[4]; m1[5] -= m2[5]; m1[6] -= m2[6]; m1[7] -= m2[7]; 4.253 + m1[8] -= m2[8]; m1[9] -= m2[9]; m1[10] -= m2[10]; m1[11] -= m2[11]; 4.254 + m1[12] -= m2[12]; m1[13] -= m2[13]; m1[14] -= m2[14]; m1[15] -= m2[15]; 4.255 + return m1; 4.256 + } 4.257 + inline float * subtract4m(Matrix4f m1, Matrix4f m2) 4.258 + { 4.259 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; m1[3] -= m2[3]; 4.260 + m1[4] -= m2[4]; m1[5] -= m2[5]; m1[6] -= m2[6]; m1[7] -= m2[7]; 4.261 + m1[8] -= m2[8]; m1[9] -= m2[9]; m1[10] -= m2[10]; m1[11] -= m2[11]; 4.262 + m1[12] -= m2[12]; m1[13] -= m2[13]; m1[14] -= m2[14]; m1[15] -= m2[15]; 4.263 + return m1; 4.264 + } 4.265 + inline double * subtract4m(Matrix4d m1, Matrix4d m2) 4.266 + { 4.267 + m1[0] -= m2[0]; m1[1] -= m2[1]; m1[2] -= m2[2]; m1[3] -= m2[3]; 4.268 + m1[4] -= m2[4]; m1[5] -= m2[5]; m1[6] -= m2[6]; m1[7] -= m2[7]; 4.269 + m1[8] -= m2[8]; m1[9] -= m2[9]; m1[10] -= m2[10]; m1[11] -= m2[11]; 4.270 + m1[12] -= m2[12]; m1[13] -= m2[13]; m1[14] -= m2[14]; m1[15] -= m2[15]; 4.271 + return m1; 4.272 + } 4.273 + 4.274 + ////////////////////////////////////////////////////////////////////////// 4.275 + // scale*() 4.276 + 4.277 + inline int * scale2m(Matrix2i m, int s) 4.278 + { 4.279 + m[0] *= s; m[1] *= s; 4.280 + m[2] *= s; m[3] *= s; 4.281 + return m; 4.282 + } 4.283 + inline float * scale2m(Matrix2f m, float s) 4.284 + { 4.285 + m[0] *= s; m[1] *= s; 4.286 + m[2] *= s; m[3] *= s; 4.287 + return m; 4.288 + } 4.289 + inline double * scale2m(Matrix2d m, double s) 4.290 + { 4.291 + m[0] *= s; m[1] *= s; 4.292 + m[2] *= s; m[3] *= s; 4.293 + return m; 4.294 + } 4.295 + 4.296 + inline int * scale3m(Matrix3i m, int s) 4.297 + { 4.298 + m[0] *= s; m[1] *= s; m[2] *= s; 4.299 + m[3] *= s; m[4] *= s; m[5] *= s; 4.300 + m[4] *= s; m[5] *= s; m[6] *= s; 4.301 + return m; 4.302 + } 4.303 + inline float * scale3m(Matrix3f m, float s) 4.304 + { 4.305 + m[0] *= s; m[1] *= s; m[2] *= s; 4.306 + m[3] *= s; m[4] *= s; m[5] *= s; 4.307 + m[4] *= s; m[5] *= s; m[6] *= s; 4.308 + return m; 4.309 + } 4.310 + inline double * scale3m(Matrix3d m, double s) 4.311 + { 4.312 + m[0] *= s; m[1] *= s; m[2] *= s; 4.313 + m[3] *= s; m[4] *= s; m[5] *= s; 4.314 + m[4] *= s; m[5] *= s; m[6] *= s; 4.315 + return m; 4.316 + } 4.317 + 4.318 + inline int * scale4m(Matrix4i m, int s) 4.319 + { 4.320 + m[0] *= s; m[1] *= s; m[2] *= s; m[3] *= s; 4.321 + m[4] *= s; m[5] *= s; m[4] *= s; m[5] *= s; 4.322 + m[6] *= s; m[7] *= s; m[8] *= s; m[9] *= s; 4.323 + m[10] *= s; m[11] *= s; m[12] *= s; m[13] *= s; 4.324 + return m; 4.325 + } 4.326 + inline float * scale4m(Matrix4f m, float s) 4.327 + { 4.328 + m[0] *= s; m[1] *= s; m[2] *= s; m[3] *= s; 4.329 + m[4] *= s; m[5] *= s; m[4] *= s; m[5] *= s; 4.330 + m[6] *= s; m[7] *= s; m[8] *= s; m[9] *= s; 4.331 + m[10] *= s; m[11] *= s; m[12] *= s; m[13] *= s; 4.332 + return m; 4.333 + } 4.334 + inline double * scale4m(Matrix4d m, double s) 4.335 + { 4.336 + m[0] *= s; m[1] *= s; m[2] *= s; m[3] *= s; 4.337 + m[4] *= s; m[5] *= s; m[6] *= s; m[7] *= s; 4.338 + m[8] *= s; m[9] *= s; m[10] *= s; m[11] *= s; 4.339 + m[12] *= s; m[13] *= s; m[14] *= s; m[15] *= s; 4.340 + return m; 4.341 + } 4.342 + 4.343 + ////////////////////////////////////////////////////////////////////////// 4.344 + // multvec*mv(Matrix m, Vector v, Vector vres) 4.345 + // Right multiplies a matrix m by a (column) vector v and stores 4.346 + // the result in vres. 4.347 + // Returns vres. 4.348 + // 4.349 + // multvec*vm(Vector v, Matrix m, Vector vres) 4.350 + // Left multiplies a (row) vector v by a matrix m and stores the 4.351 + // result in vres. 4.352 + // Returns vres. 4.353 + 4.354 + int * multvec2mv(Matrix2i m, Vector2i v, Vector2i vres); 4.355 + float * multvec2mv(Matrix2f m, Vector2f v, Vector2f vres); 4.356 + double * multvec2mv(Matrix2d m, Vector2d v, Vector2d vres); 4.357 + 4.358 + int * multvec3mv(Matrix3i m, Vector3i v, Vector3i vres); 4.359 + float * multvec3mv(Matrix3f m, Vector3f v, Vector3f vres); 4.360 + double * multvec3mv(Matrix3d m, Vector3d v, Vector3d vres); 4.361 + 4.362 + int * multvec4mv(Matrix4i m, Vector4i v, Vector4i vres); 4.363 + float * multvec4mv(Matrix4f m, Vector4f v, Vector4f vres); 4.364 + double * multvec4mv(Matrix4d m, Vector4d v, Vector4d vres); 4.365 + 4.366 + int * multvec2vm(Vector2i v, Matrix2i m, Vector2i vres); 4.367 + float * multvec2vm(Vector2f v, Matrix2f m, Vector2f vres); 4.368 + double * multvec2vm(Vector2d v, Matrix2d m, Vector2d vres); 4.369 + 4.370 + int * multvec3vm(Vector3i v, Matrix3i m, Vector3i vres); 4.371 + float * multvec3vm(Vector3f v, Matrix3f m, Vector3f vres); 4.372 + double * multvec3vm(Vector3d v, Matrix3d m, Vector3d vres); 4.373 + 4.374 + int * multvec4vm(Vector4i v, Matrix4i m, Vector4i vres); 4.375 + float * multvec4vm(Vector4f v, Matrix4f m, Vector4f vres); 4.376 + double * multvec4vm(Vector4d v, Matrix4d m, Vector4d vres); 4.377 + 4.378 + ////////////////////////////////////////////////////////////////////////// 4.379 + // multmat*(Matrix m1, Matrix m2, Matrix mres) 4.380 + // Multiply two matrices together and return the result in mres. 4.381 + // returns mres. 4.382 + 4.383 + int * multmat2(Matrix2i m1, Matrix2i m2, Matrix2i mres); 4.384 + float * multmat2(Matrix2f m1, Matrix2f m2, Matrix2f mres); 4.385 + double * multmat2(Matrix2d m1, Matrix2d m2, Matrix2d mres); 4.386 + 4.387 + int * multmat3(Matrix3i m1, Matrix3i m2, Matrix3i mres); 4.388 + float * multmat3(Matrix3f m1, Matrix3f m2, Matrix3f mres); 4.389 + double * multmat3(Matrix3d m1, Matrix3d m2, Matrix3d mres); 4.390 + 4.391 + int * multmat4(Matrix4i m1, Matrix4i m2, Matrix4i mres); 4.392 + float * multmat4(Matrix4f m1, Matrix4f m2, Matrix4f mres); 4.393 + double * multmat4(Matrix4d m1, Matrix4d m2, Matrix4d mres); 4.394 + 4.395 + ////////////////////////////////////////////////////////////////////////// 4.396 + // transpose*(Matrix m, Matrix mres) 4.397 + // Compute the transpose of a matrix and store the result in mres. 4.398 + // Returns mres. 4.399 + 4.400 + int * transpose2(Matrix2i m, Matrix2i mres); 4.401 + float * transpose2(Matrix2f m, Matrix2f mres); 4.402 + double * transpose2(Matrix2d m, Matrix2d mres); 4.403 + 4.404 + int * transpose3(Matrix3i m, Matrix3i mres); 4.405 + float * transpose3(Matrix3f m, Matrix3f mres); 4.406 + double * transpose3(Matrix3d m, Matrix3d mres); 4.407 + 4.408 + int * transpose4(Matrix4i m, Matrix4i mres); 4.409 + float * transpose4(Matrix4f m, Matrix4f mres); 4.410 + double * transpose4(Matrix4d m, Matrix4d mres); 4.411 + 4.412 + } // namespace Matrix 4.413 + 4.414 + } // namespace arda 4.415 +#endif // MATRIX_H_
5.1 --- a/include/Vector.h Sun Sep 04 12:46:08 2011 -0500 5.2 +++ b/include/Vector.h Tue Sep 06 11:26:39 2011 -0500 5.3 @@ -6,29 +6,28 @@ 5.4 5.5 namespace arda 5.6 { 5.7 - 5.8 - //////////////////////////////////////////////////////////////////////////////// 5.9 - // Vectors 5.10 - // 5.11 - // Supported operations on vectors 5.12 - // 5.13 - // assign*() Assign the value of one vector to another. 5.14 - // add*() Add two vectors 5.15 - // cross() Cross product of two 3-space vectors. 5.16 - // dot*() Dot product. 5.17 - // get_angle*() Calculate angle between two vectors. 5.18 - // length*() Length of a vector (the Euclidean norm). 5.19 - // normalize*() Normalize the vector. 5.20 - // proj*() Calculate the projection of one vector onto another. 5.21 - // scale*() Multiply vector by a scalar. 5.22 - // subtract*() A convenience function to avoid writing add(v1, scale(v2, -1)) 5.23 - // vectostr*() Returns a printable string representation of the vector. 5.24 - // 5.25 - // All functions except vectostr are defined inline. 5.26 - 5.27 namespace Vector 5.28 { 5.29 5.30 + //////////////////////////////////////////////////////////////////////////////// 5.31 + // Vectors 5.32 + // 5.33 + // Supported operations on vectors 5.34 + // 5.35 + // assign*() Assign the value of one vector to another. 5.36 + // add*() Add two vectors 5.37 + // cross() Cross product of two 3-space vectors. 5.38 + // dot*() Dot product. 5.39 + // get_angle*() Calculate angle between two vectors. 5.40 + // length*() Length of a vector (the Euclidean norm). 5.41 + // normalize*() Normalize the vector. 5.42 + // proj*() Calculate the projection of one vector onto another. 5.43 + // scale*() Multiply vector by a scalar. 5.44 + // subtract*() A convenience function to avoid writing add(v1, scale(v2, -1)) 5.45 + // getstring*() Returns a printable string representation of the vector. 5.46 + // 5.47 + // All functions except getstring are defined inline. 5.48 + 5.49 typedef int Vector2i[2]; 5.50 typedef float Vector2f[2]; 5.51 typedef double Vector2d[2]; 5.52 @@ -42,89 +41,89 @@ 5.53 typedef double Vector4d[4]; 5.54 5.55 ////////////////////////////////////////////////////////////////////////// 5.56 - // vectostr*(Vector v) 5.57 + // getstring*(Vector v) 5.58 // Returns a C string representation of the vector. 5.59 // This is one of the few non-inline Vector functions. 5.60 5.61 - std::string & vectostr2(Vector2i v, std::string & s); 5.62 - std::string & vectostr2(Vector2f v, std::string & s); 5.63 - std::string & vectostr2(Vector2d v, std::string & s); 5.64 - std::string & vectostr3(Vector3i v, std::string & s); 5.65 - std::string & vectostr3(Vector3f v, std::string & s); 5.66 - std::string & vectostr3(Vector3d v, std::string & s); 5.67 - std::string & vectostr4(Vector4i v, std::string & s); 5.68 - std::string & vectostr4(Vector4f v, std::string & s); 5.69 - std::string & vectostr4(Vector4d v, std::string & s); 5.70 + std::string & getstring2v(Vector2i v, std::string & s); 5.71 + std::string & getstring2v(Vector2f v, std::string & s); 5.72 + std::string & getstring2v(Vector2d v, std::string & s); 5.73 + std::string & getstring3v(Vector3i v, std::string & s); 5.74 + std::string & getstring3v(Vector3f v, std::string & s); 5.75 + std::string & getstring3v(Vector3d v, std::string & s); 5.76 + std::string & getstring4v(Vector4i v, std::string & s); 5.77 + std::string & getstring4v(Vector4f v, std::string & s); 5.78 + std::string & getstring4v(Vector4d v, std::string & s); 5.79 5.80 ////////////////////////////////////////////////////////////////////////// 5.81 // scale*(Vector v, scalar s) 5.82 // Multiply a vector by a scalar. 5.83 // Returns v so that the result may be passed to other functions. 5.84 5.85 - inline int * scale2(Vector2i v, const int s) 5.86 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.87 - inline int * scale2(Vector2i v, const float s) 5.88 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.89 - inline int * scale2(Vector2i v, const double s) 5.90 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.91 + inline int * scale2v(Vector2i v, const int s) 5.92 + { v[0] *= s ; v[1] *= s; return v; } 5.93 + inline int * scale2v(Vector2i v, const float s) 5.94 + { v[0] *= s ; v[1] *= s; return v; } 5.95 + inline int * scale2v(Vector2i v, const double s) 5.96 + { v[0] *= s ; v[1] *= s; return v; } 5.97 5.98 - inline float * scale2(Vector2f v, const int s) 5.99 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.100 - inline float * scale2(Vector2f v, const float s) 5.101 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.102 - inline float * scale2(Vector2f v, const double s) 5.103 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.104 + inline float * scale2v(Vector2f v, const int s) 5.105 + { v[0] *= s ; v[1] *= s; return v; } 5.106 + inline float * scale2v(Vector2f v, const float s) 5.107 + { v[0] *= s ; v[1] *= s; return v; } 5.108 + inline float * scale2v(Vector2f v, const double s) 5.109 + { v[0] *= s ; v[1] *= s; return v; } 5.110 5.111 - inline double * scale2(Vector2d v, const int s) 5.112 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.113 - inline double * scale2(Vector2d v, const float s) 5.114 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.115 - inline double * scale2(Vector2d v, const double s) 5.116 - { v[0] = v[0] * s ; v[1] = v[1] * s; return v; } 5.117 + inline double * scale2v(Vector2d v, const int s) 5.118 + { v[0] *= s ; v[1] *= s; return v; } 5.119 + inline double * scale2v(Vector2d v, const float s) 5.120 + { v[0] *= s ; v[1] *= s; return v; } 5.121 + inline double * scale2v(Vector2d v, const double s) 5.122 + { v[0] *= s ; v[1] *= s; return v; } 5.123 5.124 5.125 - inline int * scale3(Vector3i v, const int s) 5.126 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.127 - inline int * scale3(Vector3i v, const float s) 5.128 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.129 - inline int * scale3(Vector3i v, const double s) 5.130 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.131 + inline int * scale3v(Vector3i v, const int s) 5.132 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.133 + inline int * scale3v(Vector3i v, const float s) 5.134 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.135 + inline int * scale3v(Vector3i v, const double s) 5.136 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.137 5.138 - inline float * scale3(Vector3f v, const int s) 5.139 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.140 - inline float * scale3(Vector3f v, const float s) 5.141 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.142 - inline float * scale3(Vector3f v, const double s) 5.143 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.144 + inline float * scale3v(Vector3f v, const int s) 5.145 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.146 + inline float * scale3v(Vector3f v, const float s) 5.147 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.148 + inline float * scale3v(Vector3f v, const double s) 5.149 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.150 5.151 - inline double * scale3(Vector3d v, const int s) 5.152 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.153 - inline double * scale3(Vector3d v, const float s) 5.154 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.155 - inline double * scale3(Vector3d v, const double s) 5.156 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; return v; } 5.157 + inline double * scale3v(Vector3d v, const int s) 5.158 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.159 + inline double * scale3v(Vector3d v, const float s) 5.160 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.161 + inline double * scale3v(Vector3d v, const double s) 5.162 + { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } 5.163 5.164 5.165 - inline int * scale4(Vector4i v, const int s) 5.166 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.167 - inline int * scale4(Vector4i v, const float s) 5.168 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.169 - inline int * scale4(Vector4i v, const double s) 5.170 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.171 + inline int * scale4v(Vector4i v, const int s) 5.172 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.173 + inline int * scale4v(Vector4i v, const float s) 5.174 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.175 + inline int * scale4v(Vector4i v, const double s) 5.176 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.177 5.178 - inline float * scale4(Vector4f v, const int s) 5.179 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.180 - inline float * scale4(Vector4f v, const float s) 5.181 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.182 - inline float * scale4(Vector4f v, const double s) 5.183 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.184 + inline float * scale4v(Vector4f v, const int s) 5.185 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.186 + inline float * scale4v(Vector4f v, const float s) 5.187 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.188 + inline float * scale4v(Vector4f v, const double s) 5.189 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.190 5.191 - inline double * scale4(Vector4d v, const int s) 5.192 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.193 - inline double * scale4(Vector4d v, const float s) 5.194 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.195 - inline double * scale4(Vector4d v, const double s) 5.196 - { v[0] = v[0] * s ; v[1] = v[1] * s; v[2] = v[2] * s; v[3] = v[3] * s; return v; } 5.197 + inline double * scale4v(Vector4d v, const int s) 5.198 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.199 + inline double * scale4v(Vector4d v, const float s) 5.200 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.201 + inline double * scale4v(Vector4d v, const double s) 5.202 + { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } 5.203 5.204 5.205 ////////////////////////////////////////////////////////////////////////// 5.206 @@ -132,25 +131,25 @@ 5.207 // The dot product of two vectors, which must be the same type 5.208 // Returns a long for int vectors, a double for floating point vectors. 5.209 5.210 - inline long dot2(Vector2i v1, Vector2i v2) 5.211 + inline long dot2v(Vector2i v1, Vector2i v2) 5.212 { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1]; } 5.213 - inline double dot2(Vector2f v1, Vector2f v2) 5.214 + inline double dot2v(Vector2f v1, Vector2f v2) 5.215 { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1]; } 5.216 - inline double dot2(Vector2d v1, Vector2d v2) 5.217 + inline double dot2v(Vector2d v1, Vector2d v2) 5.218 { return v1[0]*v2[0] + v1[1]*v2[1]; } 5.219 5.220 - inline long dot3(Vector3i v1, Vector3i v2) 5.221 + inline long dot3v(Vector3i v1, Vector3i v2) 5.222 { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1] + (long) v1[2]*v2[2]; } 5.223 - inline double dot3(Vector3f v1, Vector3f v2) 5.224 + inline double dot3v(Vector3f v1, Vector3f v2) 5.225 { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1] + (double) v1[2]*v2[2]; } 5.226 - inline double dot3(Vector3d v1, Vector3d v2) 5.227 + inline double dot3v(Vector3d v1, Vector3d v2) 5.228 { return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; } 5.229 5.230 - inline long dot4(Vector4i v1, Vector4i v2) 5.231 + inline long dot4v(Vector4i v1, Vector4i v2) 5.232 { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1] + (long) v1[2]*v2[2] + (long) v1[3]*v2[3]; } 5.233 - inline double dot4(Vector4f v1, Vector4f v2) 5.234 + inline double dot4v(Vector4f v1, Vector4f v2) 5.235 { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1] + (double) v1[2]*v2[2] + (double) v1[3]*v2[3]; } 5.236 - inline double dot4(Vector4d v1, Vector4d v2) 5.237 + inline double dot4v(Vector4d v1, Vector4d v2) 5.238 { return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2] + v1[3]*v2[3]; } 5.239 5.240 5.241 @@ -160,74 +159,74 @@ 5.242 // Returns a float for float for float vectors, and a double for 5.243 // int and double vectors. 5.244 5.245 - inline double length2(Vector2i v) 5.246 - { return sqrt((dot2(v, v))); } 5.247 - inline double length2(Vector2f v) 5.248 - { return sqrtf((dot2(v, v))); } 5.249 - inline double length2(Vector2d v) 5.250 - { return sqrt((dot2(v, v))); } 5.251 + inline double length2v(Vector2i v) 5.252 + { return sqrt((dot2v(v, v))); } 5.253 + inline double length2v(Vector2f v) 5.254 + { return sqrtf((dot2v(v, v))); } 5.255 + inline double length2v(Vector2d v) 5.256 + { return sqrt((dot2v(v, v))); } 5.257 5.258 - inline double length3(Vector3i v) 5.259 - { return sqrt((dot3(v, v))); } 5.260 - inline double length3(Vector3f v) 5.261 - { return sqrtf((dot3(v, v))); } 5.262 - inline double length3(Vector3d v) 5.263 - { return sqrt((dot3(v, v))); } 5.264 + inline double length3v(Vector3i v) 5.265 + { return sqrt((dot3v(v, v))); } 5.266 + inline double length3v(Vector3f v) 5.267 + { return sqrtf((dot3v(v, v))); } 5.268 + inline double length3v(Vector3d v) 5.269 + { return sqrt((dot3v(v, v))); } 5.270 5.271 - inline double length4(Vector4i v) 5.272 - { return sqrt((dot4(v, v))); } 5.273 - inline double length4(Vector4f v) 5.274 - { return sqrtf((dot4(v, v))); } 5.275 - inline double length4(Vector4d v) 5.276 - { return sqrt((dot4(v, v))); } 5.277 + inline double length4v(Vector4i v) 5.278 + { return sqrt((dot4v(v, v))); } 5.279 + inline double length4v(Vector4f v) 5.280 + { return sqrtf((dot4v(v, v))); } 5.281 + inline double length4v(Vector4d v) 5.282 + { return sqrt((dot4v(v, v))); } 5.283 5.284 5.285 ////////////////////////////////////////////////////////////////////////// 5.286 - // add*(Vector v1, Vector v2, Vector vres) 5.287 - // Add two vectors together. 5.288 - // Returns vres so that the result may be used in further 5.289 + // add*(Vector v1, Vector v2) 5.290 + // Add v2 to v1. 5.291 + // Returns v1 so that the result may be used in further 5.292 // calculations. 5.293 5.294 - inline int * add2(Vector2i v1, Vector2i v2, Vector2i vres) 5.295 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; return vres; } 5.296 - inline float * add2(Vector2f v1, Vector2f v2, Vector2f vres) 5.297 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; return vres; } 5.298 - inline double * add2(Vector2d v1, Vector2d v2, Vector2d vres) 5.299 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; return vres; } 5.300 + inline int * add2v(Vector2i v1, Vector2i v2) 5.301 + { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } 5.302 + inline float * add2v(Vector2f v1, Vector2f v2) 5.303 + { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } 5.304 + inline double * add2v(Vector2d v1, Vector2d v2) 5.305 + { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } 5.306 5.307 - inline int * add3(Vector3i v1, Vector3i v2, Vector3i vres) 5.308 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; return vres; } 5.309 - inline float * add3(Vector3f v1, Vector3f v2, Vector3f vres) 5.310 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; return vres; } 5.311 - inline double * add3(Vector3d v1, Vector3d v2, Vector3d vres) 5.312 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; return vres; } 5.313 + inline int * add3v(Vector3i v1, Vector3i v2) 5.314 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } 5.315 + inline float * add3v(Vector3f v1, Vector3f v2) 5.316 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } 5.317 + inline double * add3v(Vector3d v1, Vector3d v2) 5.318 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } 5.319 5.320 - inline int * add4(Vector4i v1, Vector4i v2, Vector4i vres) 5.321 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; vres[3] = v1[3] + v2[3]; return vres;} 5.322 - inline float * add4(Vector4f v1, Vector4f v2, Vector4f vres) 5.323 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; vres[3] = v1[3] + v2[3]; return vres; } 5.324 - inline double * add4(Vector4d v1, Vector4d v2, Vector4d vres) 5.325 - { vres[0] = v1[0] + v2[0]; vres[1] = v1[1] + v2[1]; vres[2] = v1[2] + v2[2]; vres[3] = v1[3] + v2[3]; return vres; } 5.326 + inline int * add4v(Vector4i v1, Vector4i v2) 5.327 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } 5.328 + inline float * add4v(Vector4f v1, Vector4f v2) 5.329 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } 5.330 + inline double * add4v(Vector4d v1, Vector4d v2) 5.331 + { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } 5.332 5.333 ////////////////////////////////////////////////////////////////////////// 5.334 // normalize*(Vector v) 5.335 // Normalizes the vecor. Only defined for floating point vectors. 5.336 // Returns the vector. 5.337 5.338 - inline float * normalize2(Vector2f v) 5.339 - { double l = length2(v); v[0] /= l; v[1] /= l; return v; } 5.340 - inline double * normalize2(Vector2d v) 5.341 - { double l = length2(v); v[0] /= l; v[1] /= l; return v; } 5.342 + inline float * normalize2v(Vector2f v) 5.343 + { double l = length2v(v); v[0] /= l; v[1] /= l; return v; } 5.344 + inline double * normalize2v(Vector2d v) 5.345 + { double l = length2v(v); v[0] /= l; v[1] /= l; return v; } 5.346 5.347 - inline float * normalize3(Vector3f v) 5.348 - { double l = length3(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } 5.349 - inline double * normalize3(Vector3d v) 5.350 - { double l = length3(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } 5.351 + inline float * normalize3v(Vector3f v) 5.352 + { double l = length3v(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } 5.353 + inline double * normalize3v(Vector3d v) 5.354 + { double l = length3v(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } 5.355 5.356 - inline float * normalize4(Vector4f v) 5.357 - { double l = length4(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } 5.358 - inline double * normalize4(Vector4d v) 5.359 - { double l = length4(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } 5.360 + inline float * normalize4v(Vector4f v) 5.361 + { double l = length4v(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } 5.362 + inline double * normalize4v(Vector4d v) 5.363 + { double l = length4v(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } 5.364 5.365 ////////////////////////////////////////////////////////////////////////// 5.366 // cross(Vector3 v) 5.367 @@ -261,10 +260,10 @@ 5.368 // 5.369 // I started out with two version of get_angle3: 5.370 // get_angle3_1 implemented as 5.371 - // return acos(dot3(v1, v2)/(length3(v1)*length3(v2))); 5.372 + // return acos(dot3v(v1, v2)/(length3v(v1)*length3v(v2))); 5.373 // get_angle3_2 implemented as 5.374 - // double tmp = dot3(v1, v2); 5.375 - // return acos(sqrtf(tmp*tmp/(dot3(v1,v1)*dot3(v2,v2)))); 5.376 + // double tmp = dot3v(v1, v2); 5.377 + // return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); 5.378 // 5.379 // I ran timing tests, since I expected the second one - the one I chose to 5.380 // use, in the end - to be faster since it only resulted in one sqrt call 5.381 @@ -277,92 +276,92 @@ 5.382 // to worry about? Eh. I might as well use it. 5.383 5.384 inline double get_angle2n(Vector2f v1, Vector2f v2) 5.385 - { return acos(dot2(v1, v2)); } 5.386 + { return acos(dot2v(v1, v2)); } 5.387 inline double get_angle2n(Vector2d v1, Vector2d v2) 5.388 - { return acos(dot2(v1, v2)); } 5.389 - inline double get_angle2(Vector2i v1, Vector2i v2) 5.390 + { return acos(dot2v(v1, v2)); } 5.391 + inline double get_angle2v(Vector2i v1, Vector2i v2) 5.392 { 5.393 - double tmp = dot2(v1, v2); 5.394 - return acos(sqrtf(tmp*tmp/(dot2(v1,v1)*dot2(v2,v2)))); 5.395 + double tmp = dot2v(v1, v2); 5.396 + return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); 5.397 } 5.398 - inline double get_angle2(Vector2f v1, Vector2f v2) 5.399 + inline double get_angle2v(Vector2f v1, Vector2f v2) 5.400 { 5.401 - double tmp = dot2(v1, v2); 5.402 - return acos(sqrtf(tmp*tmp/(dot2(v1,v1)*dot2(v2,v2)))); 5.403 + double tmp = dot2v(v1, v2); 5.404 + return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); 5.405 } 5.406 - inline double get_angle2(Vector2d v1, Vector2d v2) 5.407 + inline double get_angle2v(Vector2d v1, Vector2d v2) 5.408 { 5.409 - double tmp = dot2(v1, v2); 5.410 - return acos(sqrtf(tmp*tmp/(dot2(v1,v1)*dot2(v2,v2)))); 5.411 + double tmp = dot2v(v1, v2); 5.412 + return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); 5.413 } 5.414 5.415 inline double get_angle3n(Vector3f v1, Vector3f v2) 5.416 - { return acos(dot3(v1, v2)); } 5.417 + { return acos(dot3v(v1, v2)); } 5.418 inline double get_angle3n(Vector3d v1, Vector3d v2) 5.419 - { return acos(dot3(v1, v2)); } 5.420 - inline double get_angle3(Vector3i v1, Vector3i v2) 5.421 + { return acos(dot3v(v1, v2)); } 5.422 + inline double get_angle3v(Vector3i v1, Vector3i v2) 5.423 { 5.424 - double tmp = dot3(v1, v2); 5.425 - return acos(sqrtf(tmp*tmp/(dot3(v1,v1)*dot3(v2,v2)))); 5.426 + double tmp = dot3v(v1, v2); 5.427 + return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); 5.428 } 5.429 - inline double get_angle3(Vector3f v1, Vector3f v2) 5.430 + inline double get_angle3v(Vector3f v1, Vector3f v2) 5.431 { 5.432 - double tmp = dot3(v1, v2); 5.433 - return acos(sqrtf(tmp*tmp/(dot3(v1,v1)*dot3(v2,v2)))); 5.434 + double tmp = dot3v(v1, v2); 5.435 + return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); 5.436 } 5.437 - inline double get_angle3(Vector3d v1, Vector3d v2) 5.438 + inline double get_angle3v(Vector3d v1, Vector3d v2) 5.439 { 5.440 - double tmp = dot3(v1, v2); 5.441 - return acos(sqrtf(tmp*tmp/(dot3(v1,v1)*dot3(v2,v2)))); 5.442 + double tmp = dot3v(v1, v2); 5.443 + return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); 5.444 } 5.445 5.446 inline double get_angle4n(Vector4f v1, Vector4f v2) 5.447 - { return acos(dot4(v1, v2)); } 5.448 + { return acos(dot4v(v1, v2)); } 5.449 inline double get_angle4n(Vector4d v1, Vector4d v2) 5.450 - { return acos(dot4(v1, v2)); } 5.451 - inline double get_angle4(Vector4i v1, Vector4i v2) 5.452 + { return acos(dot4v(v1, v2)); } 5.453 + inline double get_angle4v(Vector4i v1, Vector4i v2) 5.454 { 5.455 - double tmp = dot4(v1, v2); 5.456 - return acos(sqrtf(tmp*tmp/(dot4(v1,v1)*dot4(v2,v2)))); 5.457 + double tmp = dot4v(v1, v2); 5.458 + return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); 5.459 } 5.460 - inline double get_angle4(Vector4f v1, Vector4f v2) 5.461 + inline double get_angle4v(Vector4f v1, Vector4f v2) 5.462 { 5.463 - double tmp = dot4(v1, v2); 5.464 - return acos(sqrtf(tmp*tmp/(dot4(v1,v1)*dot4(v2,v2)))); 5.465 + double tmp = dot4v(v1, v2); 5.466 + return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); 5.467 } 5.468 - inline double get_angle4(Vector4d v1, Vector4d v2) 5.469 + inline double get_angle4v(Vector4d v1, Vector4d v2) 5.470 { 5.471 - double tmp = dot4(v1, v2); 5.472 - return acos(sqrtf(tmp*tmp/(dot4(v1,v1)*dot4(v2,v2)))); 5.473 + double tmp = dot4v(v1, v2); 5.474 + return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); 5.475 } 5.476 5.477 ////////////////////////////////////////////////////////////////////////// 5.478 - // subtract*(Vector v1, Vector v2, Vector vres) 5.479 - // Subtract v2 from v1 and store result in vres. 5.480 - // Equivalent to add(v1, scale(v2, -1), vres). 5.481 - // Returns vres so that the result may be used in further 5.482 + // subtract*(Vector v1, Vector v2) 5.483 + // Subtract v2 from v1, 5.484 + // Equivalent to add(v1, scale(v2, -1)). 5.485 + // Returns v1 so that the result may be used in further 5.486 // calculations. 5.487 5.488 - inline int * subtract2(Vector2i v1, Vector2i v2, Vector2i vres) 5.489 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; return vres; } 5.490 - inline float * subtract2(Vector2f v1, Vector2f v2, Vector2f vres) 5.491 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; return vres; } 5.492 - inline double * subtract2(Vector2d v1, Vector2d v2, Vector2d vres) 5.493 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; return vres; } 5.494 + inline int * subtract2v(Vector2i v1, Vector2i v2) 5.495 + { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } 5.496 + inline float * subtract2v(Vector2f v1, Vector2f v2) 5.497 + { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } 5.498 + inline double * subtract2v(Vector2d v1, Vector2d v2) 5.499 + { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } 5.500 5.501 - inline int * subtract3(Vector3i v1, Vector3i v2, Vector3i vres) 5.502 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; return vres; } 5.503 - inline float * subtract3(Vector3f v1, Vector3f v2, Vector3f vres) 5.504 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; return vres; } 5.505 - inline double * subtract3(Vector3d v1, Vector3d v2, Vector3d vres) 5.506 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; return vres; } 5.507 + inline int * subtract3v(Vector3i v1, Vector3i v2) 5.508 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } 5.509 + inline float * subtract3v(Vector3f v1, Vector3f v2) 5.510 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } 5.511 + inline double * subtract3v(Vector3d v1, Vector3d v2) 5.512 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } 5.513 5.514 - inline int * subtract4(Vector4i v1, Vector4i v2, Vector4i vres) 5.515 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; vres[3] = v1[3] - v2[3]; return vres;} 5.516 - inline float * subtract4(Vector4f v1, Vector4f v2, Vector4f vres) 5.517 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; vres[3] = v1[3] - v2[3]; return vres; } 5.518 - inline double * subtract4(Vector4d v1, Vector4d v2, Vector4d vres) 5.519 - { vres[0] = v1[0] - v2[0]; vres[1] = v1[1] - v2[1]; vres[2] = v1[2] - v2[2]; vres[3] = v1[3] - v2[3]; return vres; } 5.520 + inline int * subtract4v(Vector4i v1, Vector4i v2) 5.521 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1;} 5.522 + inline float * subtract4v(Vector4f v1, Vector4f v2) 5.523 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1; } 5.524 + inline double * subtract4v(Vector4d v1, Vector4d v2) 5.525 + { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1; } 5.526 5.527 5.528 ////////////////////////////////////////////////////////////////////////// 5.529 @@ -370,25 +369,25 @@ 5.530 // Copies the value of v2 into v1. 5.531 // Returns v1. 5.532 5.533 - inline int * assign2(Vector2i v1, Vector2i v2) 5.534 + inline int * assign2v(Vector2i v1, Vector2i v2) 5.535 { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } 5.536 - inline float * assign2(Vector2f v1, Vector2f v2) 5.537 + inline float * assign2v(Vector2f v1, Vector2f v2) 5.538 { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } 5.539 - inline double * assign2(Vector2d v1, Vector2d v2) 5.540 + inline double * assign2v(Vector2d v1, Vector2d v2) 5.541 { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } 5.542 5.543 - inline int * assign3(Vector3i v1, Vector3i v2) 5.544 + inline int * assign3v(Vector3i v1, Vector3i v2) 5.545 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } 5.546 - inline float * assign3(Vector3f v1, Vector3f v2) 5.547 + inline float * assign3v(Vector3f v1, Vector3f v2) 5.548 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } 5.549 - inline double * assign3(Vector3d v1, Vector3d v2) 5.550 + inline double * assign3v(Vector3d v1, Vector3d v2) 5.551 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } 5.552 5.553 - inline int * assign4(Vector4i v1, Vector4i v2) 5.554 + inline int * assign4v(Vector4i v1, Vector4i v2) 5.555 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } 5.556 - inline float * assign4(Vector4f v1, Vector4f v2) 5.557 + inline float * assign4v(Vector4f v1, Vector4f v2) 5.558 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } 5.559 - inline double * assign4(Vector4d v1, Vector4d v2) 5.560 + inline double * assign4v(Vector4d v1, Vector4d v2) 5.561 { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } 5.562 5.563 5.564 @@ -399,20 +398,20 @@ 5.565 // Only defined for floating point vectors. 5.566 // Returns vres. 5.567 5.568 - inline float * proj2(Vector2f v1, Vector2f v2, Vector2f vres) 5.569 - { assign2(vres, v2); scale2(vres, (dot2(v1, vres)/dot2(vres,vres))); return vres; } 5.570 - inline double * proj2(Vector2d v1, Vector2d v2, Vector2d vres) 5.571 - { assign2(vres, v2); scale2(vres, (dot2(v1, vres)/dot2(vres,vres))); return vres; } 5.572 + inline float * proj2v(Vector2f v1, Vector2f v2, Vector2f vres) 5.573 + { assign2v(vres, v2); scale2v(vres, (dot2v(v1, vres)/dot2v(vres,vres))); return vres; } 5.574 + inline double * proj2v(Vector2d v1, Vector2d v2, Vector2d vres) 5.575 + { assign2v(vres, v2); scale2v(vres, (dot2v(v1, vres)/dot2v(vres,vres))); return vres; } 5.576 5.577 - inline float * proj3(Vector3f v1, Vector3f v2, Vector3f vres) 5.578 - { assign3(vres, v2); scale3(vres, (dot3(v1, vres)/dot3(vres,vres))); return vres; } 5.579 - inline double * proj3(Vector3d v1, Vector3d v2, Vector3d vres) 5.580 - { assign3(vres, v2); scale3(vres, (dot3(v1, vres)/dot3(vres,vres))); return vres; } 5.581 + inline float * proj3v(Vector3f v1, Vector3f v2, Vector3f vres) 5.582 + { assign3v(vres, v2); scale3v(vres, (dot3v(v1, vres)/dot3v(vres,vres))); return vres; } 5.583 + inline double * proj3v(Vector3d v1, Vector3d v2, Vector3d vres) 5.584 + { assign3v(vres, v2); scale3v(vres, (dot3v(v1, vres)/dot3v(vres,vres))); return vres; } 5.585 5.586 - inline float * proj4(Vector4f v1, Vector4f v2, Vector4f vres) 5.587 - { assign4(vres, v2); scale4(vres, (dot4(v1, vres)/dot4(vres,vres))); return vres; } 5.588 - inline double * proj4(Vector4d v1, Vector4d v2, Vector4d vres) 5.589 - { assign4(vres, v2); scale4(vres, (dot4(v1, vres)/dot4(vres,vres))); return vres; } 5.590 + inline float * proj4v(Vector4f v1, Vector4f v2, Vector4f vres) 5.591 + { assign4v(vres, v2); scale4v(vres, (dot4v(v1, vres)/dot4v(vres,vres))); return vres; } 5.592 + inline double * proj4v(Vector4d v1, Vector4d v2, Vector4d vres) 5.593 + { assign4v(vres, v2); scale4v(vres, (dot4v(v1, vres)/dot4v(vres,vres))); return vres; } 5.594 5.595 } // Vector 5.596
6.1 --- a/notes Sun Sep 04 12:46:08 2011 -0500 6.2 +++ b/notes Tue Sep 06 11:26:39 2011 -0500 6.3 @@ -11,8 +11,9 @@ 6.4 * normalize 6.5 * cross 6.6 * angle between two vectors 6.7 -assignment 6.8 -projection of one vector onto another. 6.9 +* subtraction 6.10 +* assignment 6.11 +* projection of one vector onto another. 6.12 triple product i.e. dot(u, cross(v, w)) Is this really that common? 6.13 6.14 Class with operator overloading? 6.15 @@ -20,13 +21,17 @@ 6.16 -------------------------------------------------------------------------------- 6.17 Matrices 6.18 6.19 +* getstring 6.20 +* assign 6.21 +* add 6.22 +* subtract 6.23 +* scalar multiplication 6.24 +* vector multiplication 6.25 +* matrix multiplication 6.26 +* transpose 6.27 det 6.28 -transpose 6.29 inverse 6.30 -add 6.31 -matrix multiplication 6.32 -vector multiplication 6.33 -scalar multiplication 6.34 6.35 -------------------------------------------------------------------------------- 6.36 Quaternions 6.37 +
7.1 --- a/src/Math.cpp Sun Sep 04 12:46:08 2011 -0500 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,95 +0,0 @@ 7.4 -#include "Math.h" 7.5 - 7.6 -#include <iostream> 7.7 -#include <string> 7.8 -#include <sstream> 7.9 - 7.10 -//////////////////////////////////////////////////////////////////////////////// 7.11 -std::string & arda::Vector::vectostr2(Vector2i v, std::string & s) 7.12 - { 7.13 - s.clear(); 7.14 - std::stringstream ss; 7.15 - ss << "{ " << v[0] << ", " << v[1] << " }"; 7.16 - s = ss.str(); 7.17 - return s; 7.18 - } 7.19 - 7.20 -//////////////////////////////////////////////////////////////////////////////// 7.21 -std::string & arda::Vector::vectostr2(Vector2f v, std::string & s) 7.22 - { 7.23 - s.clear(); 7.24 - std::stringstream ss; 7.25 - ss << "{ " << v[0] << ", " << v[1] << " }"; 7.26 - s = ss.str(); 7.27 - return s; 7.28 - } 7.29 - 7.30 -//////////////////////////////////////////////////////////////////////////////// 7.31 -std::string & arda::Vector::vectostr2(Vector2d v, std::string & s) 7.32 - { 7.33 - s.clear(); 7.34 - std::stringstream ss; 7.35 - ss << "{ " << v[0] << ", " << v[1] << " }"; 7.36 - s = ss.str(); 7.37 - return s; 7.38 - } 7.39 - 7.40 -//////////////////////////////////////////////////////////////////////////////// 7.41 -std::string & arda::Vector::vectostr3(Vector3i v, std::string & s) 7.42 - { 7.43 - s.clear(); 7.44 - std::stringstream ss; 7.45 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }"; 7.46 - s = ss.str(); 7.47 - return s; 7.48 - } 7.49 - 7.50 -//////////////////////////////////////////////////////////////////////////////// 7.51 -std::string & arda::Vector::vectostr3(Vector3f v, std::string & s) 7.52 - { 7.53 - s.clear(); 7.54 - std::stringstream ss; 7.55 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }"; 7.56 - s = ss.str(); 7.57 - return s; 7.58 - } 7.59 - 7.60 -//////////////////////////////////////////////////////////////////////////////// 7.61 -std::string & arda::Vector::vectostr3(Vector3d v, std::string & s) 7.62 - { 7.63 - s.clear(); 7.64 - std::stringstream ss; 7.65 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }"; 7.66 - s = ss.str(); 7.67 - return s; 7.68 - } 7.69 - 7.70 -//////////////////////////////////////////////////////////////////////////////// 7.71 -std::string & arda::Vector::vectostr4(Vector4i v, std::string & s) 7.72 - { 7.73 - s.clear(); 7.74 - std::stringstream ss; 7.75 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " }"; 7.76 - s = ss.str(); 7.77 - return s; 7.78 - } 7.79 - 7.80 -//////////////////////////////////////////////////////////////////////////////// 7.81 -std::string & arda::Vector::vectostr4(Vector4f v, std::string & s) 7.82 - { 7.83 - s.clear(); 7.84 - std::stringstream ss; 7.85 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " }"; 7.86 - s = ss.str(); 7.87 - return s; 7.88 - } 7.89 - 7.90 -//////////////////////////////////////////////////////////////////////////////// 7.91 -std::string & arda::Vector::vectostr4(Vector4d v, std::string & s) 7.92 - { 7.93 - s.clear(); 7.94 - std::stringstream ss; 7.95 - ss << "{ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " }"; 7.96 - s = ss.str(); 7.97 - return s; 7.98 - }
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/Matrix.cpp Tue Sep 06 11:26:39 2011 -0500 8.3 @@ -0,0 +1,515 @@ 8.4 +#include "Matrix.h" 8.5 + 8.6 +#include <iostream> 8.7 +using namespace std; 8.8 +#include <string> 8.9 +#include <sstream> 8.10 + 8.11 +//////////////////////////////////////////////////////////////////////////////// 8.12 +std::string & arda::Matrix::getstring2m(Matrix2i m, std::string & s) 8.13 + { 8.14 + s.clear(); 8.15 + std::stringstream ss; 8.16 + ss << "[ " 8.17 + "[ " << m[0] << ", " << m[1] << " ], " 8.18 + "[ " << m[2] << ", " << m[3] << " ] ]"; 8.19 + s = ss.str(); 8.20 + return s; 8.21 + } 8.22 + 8.23 +//////////////////////////////////////////////////////////////////////////////// 8.24 +std::string & arda::Matrix::getstring2m(Matrix2f m, std::string & s) 8.25 + { 8.26 + s.clear(); 8.27 + std::stringstream ss; 8.28 + ss << "[ " 8.29 + "[ " << m[0] << ", " << m[1] << " ], " 8.30 + "[ " << m[2] << ", " << m[3] << " ] ]"; 8.31 + s = ss.str(); 8.32 + return s; 8.33 + } 8.34 + 8.35 +//////////////////////////////////////////////////////////////////////////////// 8.36 +std::string & arda::Matrix::getstring2m(Matrix2d m, std::string & s) 8.37 + { 8.38 + s.clear(); 8.39 + std::stringstream ss; 8.40 + ss << "[ " 8.41 + "[ " << m[0] << ", " << m[1] << " ], " 8.42 + "[ " << m[2] << ", " << m[3] << " ] ]"; 8.43 + s = ss.str(); 8.44 + return s; 8.45 + } 8.46 + 8.47 +//////////////////////////////////////////////////////////////////////////////// 8.48 +std::string & arda::Matrix::getstring3m(Matrix3i m, std::string & s) 8.49 + { 8.50 + s.clear(); 8.51 + std::stringstream ss; 8.52 + ss << "[ " 8.53 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], " 8.54 + "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], " 8.55 + "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ] ]"; 8.56 + s = ss.str(); 8.57 + return s; 8.58 + } 8.59 + 8.60 +//////////////////////////////////////////////////////////////////////////////// 8.61 +std::string & arda::Matrix::getstring3m(Matrix3f m, std::string & s) 8.62 + { 8.63 + s.clear(); 8.64 + std::stringstream ss; 8.65 + ss << "[ " 8.66 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], " 8.67 + "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], " 8.68 + "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ] ]"; 8.69 + s = ss.str(); 8.70 + return s; 8.71 + } 8.72 + 8.73 +//////////////////////////////////////////////////////////////////////////////// 8.74 +std::string & arda::Matrix::getstring3m(Matrix3d m, std::string & s) 8.75 + { 8.76 + s.clear(); 8.77 + std::stringstream ss; 8.78 + ss << "[ " 8.79 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], " 8.80 + "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], " 8.81 + "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ] ]"; 8.82 + s = ss.str(); 8.83 + return s; 8.84 + } 8.85 + 8.86 +//////////////////////////////////////////////////////////////////////////////// 8.87 +std::string & arda::Matrix::getstring4m(Matrix4i m, std::string & s) 8.88 + { 8.89 + s.clear(); 8.90 + std::stringstream ss; 8.91 + ss << "[ " 8.92 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], " 8.93 + "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], " 8.94 + "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], " 8.95 + "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ] ]"; 8.96 + s = ss.str(); 8.97 + return s; 8.98 + } 8.99 + 8.100 +//////////////////////////////////////////////////////////////////////////////// 8.101 +std::string & arda::Matrix::getstring4m(Matrix4f m, std::string & s) 8.102 + { 8.103 + s.clear(); 8.104 + std::stringstream ss; 8.105 + ss << "[ " 8.106 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], " 8.107 + "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], " 8.108 + "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], " 8.109 + "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ] ]"; 8.110 + s = ss.str(); 8.111 + return s; 8.112 + } 8.113 + 8.114 +//////////////////////////////////////////////////////////////////////////////// 8.115 +std::string & arda::Matrix::getstring4m(Matrix4d m, std::string & s) 8.116 + { 8.117 + s.clear(); 8.118 + std::stringstream ss; 8.119 + ss << "[ " 8.120 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], " 8.121 + "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], " 8.122 + "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], " 8.123 + "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ] ]"; 8.124 + s = ss.str(); 8.125 + return s; 8.126 + } 8.127 + 8.128 +//////////////////////////////////////////////////////////////////////////////// 8.129 +int * arda::Matrix::multvec2mv(Matrix2i m, Vector2i v, Vector2i vres) 8.130 + { 8.131 + vres[0] = m[0]*v[0] + m[2]*v[1]; 8.132 + vres[1] = m[1]*v[0] + m[3]*v[1]; 8.133 + return vres; 8.134 + } 8.135 + 8.136 +//////////////////////////////////////////////////////////////////////////////// 8.137 +float * arda::Matrix::multvec2mv(Matrix2f m, Vector2f v, Vector2f vres) 8.138 + { 8.139 + vres[0] = m[0]*v[0] + m[2]*v[1]; 8.140 + vres[1] = m[1]*v[0] + m[3]*v[1]; 8.141 + return vres; 8.142 + } 8.143 + 8.144 +//////////////////////////////////////////////////////////////////////////////// 8.145 +double * arda::Matrix::multvec2mv(Matrix2d m, Vector2d v, Vector2d vres) 8.146 + { 8.147 + vres[0] = m[0]*v[0] + m[2]*v[1]; 8.148 + vres[1] = m[1]*v[0] + m[3]*v[1]; 8.149 + return vres; 8.150 + } 8.151 + 8.152 +//////////////////////////////////////////////////////////////////////////////// 8.153 +int * arda::Matrix::multvec3mv(Matrix3i m, Vector3i v, Vector3i vres) 8.154 + { 8.155 + vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; 8.156 + vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; 8.157 + vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; 8.158 + return vres; 8.159 + } 8.160 + 8.161 +//////////////////////////////////////////////////////////////////////////////// 8.162 +float * arda::Matrix::multvec3mv(Matrix3f m, Vector3f v, Vector3f vres) 8.163 + { 8.164 + vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; 8.165 + vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; 8.166 + vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; 8.167 + return vres; 8.168 + } 8.169 + 8.170 +//////////////////////////////////////////////////////////////////////////////// 8.171 +double * arda::Matrix::multvec3mv(Matrix3d m, Vector3d v, Vector3d vres) 8.172 + { 8.173 + vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; 8.174 + vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; 8.175 + vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; 8.176 + return vres; 8.177 + } 8.178 + 8.179 +//////////////////////////////////////////////////////////////////////////////// 8.180 +int * arda::Matrix::multvec4mv(Matrix4i m, Vector4i v, Vector4i vres) 8.181 + { 8.182 + vres[0] = m[0]*v[0] + m[4]*v[1] + m[8] *v[2] + m[12]*v[3]; 8.183 + vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; 8.184 + vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; 8.185 + vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; 8.186 + return vres; 8.187 + } 8.188 + 8.189 +//////////////////////////////////////////////////////////////////////////////// 8.190 +float * arda::Matrix::multvec4mv(Matrix4f m, Vector4f v, Vector4f vres) 8.191 + { 8.192 + vres[0] = m[0]*v[0] + m[4]*v[1] + m[8] *v[2] + m[12]*v[3]; 8.193 + vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; 8.194 + vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; 8.195 + vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; 8.196 + return vres; 8.197 + 8.198 + } 8.199 + 8.200 +//////////////////////////////////////////////////////////////////////////////// 8.201 +double * arda::Matrix::multvec4mv(Matrix4d m, Vector4d v, Vector4d vres) 8.202 + { 8.203 + vres[0] = m[0]*v[0] + m[4]*v[1] + m[8] *v[2] + m[12]*v[3]; 8.204 + vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; 8.205 + vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; 8.206 + vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; 8.207 + return vres; 8.208 + } 8.209 + 8.210 +//////////////////////////////////////////////////////////////////////////////// 8.211 +int * arda::Matrix::multvec2vm(Vector2i v, Matrix2i m, Vector2i vres) 8.212 + { 8.213 + vres[0] = v[0]*m[0] + v[1]*m[1]; 8.214 + vres[1] = v[0]*m[2] + v[1]*m[3]; 8.215 + return vres; 8.216 + } 8.217 + 8.218 +//////////////////////////////////////////////////////////////////////////////// 8.219 +float * arda::Matrix::multvec2vm(Vector2f v, Matrix2f m, Vector2f vres) 8.220 + { 8.221 + vres[0] = v[0]*m[0] + v[1]*m[1]; 8.222 + vres[1] = v[0]*m[2] + v[1]*m[3]; 8.223 + return vres; 8.224 + } 8.225 + 8.226 +//////////////////////////////////////////////////////////////////////////////// 8.227 +double * arda::Matrix::multvec2vm(Vector2d v, Matrix2d m, Vector2d vres) 8.228 + { 8.229 + vres[0] = v[0]*m[0] + v[1]*m[1]; 8.230 + vres[1] = v[0]*m[2] + v[1]*m[3]; 8.231 + return vres; 8.232 + } 8.233 + 8.234 +//////////////////////////////////////////////////////////////////////////////// 8.235 +int * arda::Matrix::multvec3vm(Vector3i v, Matrix3i m, Vector3i vres) 8.236 + { 8.237 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; 8.238 + vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; 8.239 + vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; 8.240 + return vres; 8.241 + } 8.242 + 8.243 +//////////////////////////////////////////////////////////////////////////////// 8.244 +float * arda::Matrix::multvec3vm(Vector3f v, Matrix3f m, Vector3f vres) 8.245 + { 8.246 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; 8.247 + vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; 8.248 + vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; 8.249 + return vres; 8.250 + } 8.251 + 8.252 +//////////////////////////////////////////////////////////////////////////////// 8.253 +double * arda::Matrix::multvec3vm(Vector3d v, Matrix3d m, Vector3d vres) 8.254 + { 8.255 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; 8.256 + vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; 8.257 + vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; 8.258 + return vres; 8.259 + } 8.260 + 8.261 +//////////////////////////////////////////////////////////////////////////////// 8.262 +int * arda::Matrix::multvec4vm(Vector4i v, Matrix4i m, Vector4i vres) 8.263 + { 8.264 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; 8.265 + vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; 8.266 + vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; 8.267 + vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; 8.268 + return vres; 8.269 + } 8.270 + 8.271 +//////////////////////////////////////////////////////////////////////////////// 8.272 +float * arda::Matrix::multvec4vm(Vector4f v, Matrix4f m, Vector4f vres) 8.273 + { 8.274 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; 8.275 + vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; 8.276 + vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; 8.277 + vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; 8.278 + return vres; 8.279 + } 8.280 + 8.281 +//////////////////////////////////////////////////////////////////////////////// 8.282 +double * arda::Matrix::multvec4vm(Vector4d v, Matrix4d m, Vector4d vres) 8.283 + { 8.284 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; 8.285 + vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; 8.286 + vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; 8.287 + vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; 8.288 + return vres; 8.289 + } 8.290 + 8.291 + 8.292 +//////////////////////////////////////////////////////////////////////////////// 8.293 +int * arda::Matrix::multmat2(Matrix2i m1, Matrix2i m2, Matrix2i mres) 8.294 + { 8.295 + const int size=2; 8.296 + int i, j, k; 8.297 + for (i=0; i<size*size; ++i) 8.298 + mres[i] = 0; 8.299 + for (i=0; i<size; ++i) 8.300 + for (j=0; j<size; ++j) 8.301 + for (k=0; k<size; ++k) 8.302 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.303 + return mres; 8.304 + } 8.305 + 8.306 +//////////////////////////////////////////////////////////////////////////////// 8.307 +float * arda::Matrix::multmat2(Matrix2f m1, Matrix2f m2, Matrix2f mres) 8.308 + { 8.309 + const int size=2; 8.310 + int i, j, k; 8.311 + for (i=0; i<size*size; ++i) 8.312 + mres[i] = 0; 8.313 + for (i=0; i<size; ++i) 8.314 + for (j=0; j<size; ++j) 8.315 + for (k=0; k<size; ++k) 8.316 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.317 + return mres; 8.318 + } 8.319 + 8.320 +//////////////////////////////////////////////////////////////////////////////// 8.321 +double * arda::Matrix::multmat2(Matrix2d m1, Matrix2d m2, Matrix2d mres) 8.322 + { 8.323 + const int size=2; 8.324 + int i, j, k; 8.325 + for (i=0; i<size*size; ++i) 8.326 + mres[i] = 0; 8.327 + for (i=0; i<size; ++i) 8.328 + for (j=0; j<size; ++j) 8.329 + for (k=0; k<size; ++k) 8.330 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.331 + return mres; 8.332 + } 8.333 + 8.334 +//////////////////////////////////////////////////////////////////////////////// 8.335 +int * arda::Matrix::multmat3(Matrix3i m1, Matrix3i m2, Matrix3i mres) 8.336 + { 8.337 + const int size=3; 8.338 + int i, j, k; 8.339 + for (i=0; i<size*size; ++i) 8.340 + mres[i] = 0; 8.341 + for (i=0; i<size; ++i) 8.342 + for (j=0; j<size; ++j) 8.343 + for (k=0; k<size; ++k) 8.344 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.345 + return mres; 8.346 + } 8.347 + 8.348 +//////////////////////////////////////////////////////////////////////////////// 8.349 +float * arda::Matrix::multmat3(Matrix3f m1, Matrix3f m2, Matrix3f mres) 8.350 + { 8.351 + const int size=3; 8.352 + int i, j, k; 8.353 + for (i=0; i<size*size; ++i) 8.354 + mres[i] = 0; 8.355 + for (i=0; i<size; ++i) 8.356 + for (j=0; j<size; ++j) 8.357 + for (k=0; k<size; ++k) 8.358 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.359 + return mres; 8.360 + } 8.361 + 8.362 +//////////////////////////////////////////////////////////////////////////////// 8.363 +double * arda::Matrix::multmat3(Matrix3d m1, Matrix3d m2, Matrix3d mres) 8.364 + { 8.365 + const int size=3; 8.366 + int i, j, k; 8.367 + for (i=0; i<size*size; ++i) 8.368 + mres[i] = 0; 8.369 + for (i=0; i<size; ++i) 8.370 + for (j=0; j<size; ++j) 8.371 + for (k=0; k<size; ++k) 8.372 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.373 + return mres; 8.374 + } 8.375 + 8.376 +//////////////////////////////////////////////////////////////////////////////// 8.377 +int * arda::Matrix::multmat4(Matrix4i m1, Matrix4i m2, Matrix4i mres) 8.378 + { 8.379 + const int size=4; 8.380 + int i, j, k; 8.381 + for (i=0; i<size*size; ++i) 8.382 + mres[i] = 0; 8.383 + for (i=0; i<size; ++i) 8.384 + for (j=0; j<size; ++j) 8.385 + for (k=0; k<size; ++k) 8.386 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.387 + return mres; 8.388 + } 8.389 + 8.390 +//////////////////////////////////////////////////////////////////////////////// 8.391 +float * arda::Matrix::multmat4(Matrix4f m1, Matrix4f m2, Matrix4f mres) 8.392 + { 8.393 + const int size=4; 8.394 + int i, j, k; 8.395 + for (i=0; i<size*size; ++i) 8.396 + mres[i] = 0; 8.397 + for (i=0; i<size; ++i) 8.398 + for (j=0; j<size; ++j) 8.399 + for (k=0; k<size; ++k) 8.400 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.401 + return mres; 8.402 + } 8.403 + 8.404 +//////////////////////////////////////////////////////////////////////////////// 8.405 +double * arda::Matrix::multmat4(Matrix4d m1, Matrix4d m2, Matrix4d mres) 8.406 + { 8.407 + cout << "here" << endl; 8.408 + const int size=4; 8.409 + int i, j, k; 8.410 + for (i=0; i<size*size; ++i) 8.411 + mres[i] = 0; 8.412 + for (i=0; i<size; ++i) 8.413 + for (j=0; j<size; ++j) 8.414 + for (k=0; k<size; ++k) 8.415 + mres[size*i+j] += m1[size*k+j] * m2[size*i+k]; 8.416 + return mres; 8.417 + } 8.418 + 8.419 +//////////////////////////////////////////////////////////////////////////////// 8.420 +int * arda::Matrix::transpose2(Matrix2i m, Matrix2i mres) 8.421 + { 8.422 + const int size=2; 8.423 + int i, j; 8.424 + for (i=0; i<size; ++i) 8.425 + for (j=0; j<size; j++) 8.426 + mres[size*i+j] = m[size*j+i]; 8.427 + return mres; 8.428 + } 8.429 + 8.430 +//////////////////////////////////////////////////////////////////////////////// 8.431 +float * arda::Matrix::transpose2(Matrix2f m, Matrix2f mres) 8.432 + { 8.433 + const int size=2; 8.434 + int i, j; 8.435 + for (i=0; i<size; ++i) 8.436 + for (j=0; j<size; j++) 8.437 + mres[size*i+j] = m[size*j+i]; 8.438 + return mres; 8.439 + } 8.440 + 8.441 +//////////////////////////////////////////////////////////////////////////////// 8.442 +double * arda::Matrix::transpose2(Matrix2d m, Matrix2d mres) 8.443 + { 8.444 + const int size=2; 8.445 + int i, j; 8.446 + for (i=0; i<size; ++i) 8.447 + for (j=0; j<size; j++) 8.448 + mres[size*i+j] = m[size*j+i]; 8.449 + return mres; 8.450 + } 8.451 + 8.452 +//////////////////////////////////////////////////////////////////////////////// 8.453 +int * arda::Matrix::transpose3(Matrix3i m, Matrix3i mres) 8.454 + { 8.455 + const int size=3; 8.456 + int i, j; 8.457 + for (i=0; i<size; ++i) 8.458 + for (j=0; j<size; j++) 8.459 + mres[size*i+j] = m[size*j+i]; 8.460 + return mres; 8.461 + } 8.462 + 8.463 +//////////////////////////////////////////////////////////////////////////////// 8.464 +float * arda::Matrix::transpose3(Matrix3f m, Matrix3f mres) 8.465 + { 8.466 + const int size=3; 8.467 + int i, j; 8.468 + for (i=0; i<size; ++i) 8.469 + for (j=0; j<size; j++) 8.470 + mres[size*i+j] = m[size*j+i]; 8.471 + return mres; 8.472 + } 8.473 + 8.474 +//////////////////////////////////////////////////////////////////////////////// 8.475 +double * arda::Matrix::transpose3(Matrix3d m, Matrix3d mres) 8.476 + { 8.477 + const int size=3; 8.478 + int i, j; 8.479 + for (i=0; i<size; ++i) 8.480 + for (j=0; j<size; j++) 8.481 + mres[size*i+j] = m[size*j+i]; 8.482 + return mres; 8.483 + } 8.484 + 8.485 +//////////////////////////////////////////////////////////////////////////////// 8.486 +int * arda::Matrix::transpose4(Matrix4i m, Matrix4i mres) 8.487 + { 8.488 + const int size=4; 8.489 + int i, j; 8.490 + for (i=0; i<size; ++i) 8.491 + for (j=0; j<size; j++) 8.492 + mres[size*i+j] = m[size*j+i]; 8.493 + return mres; 8.494 + } 8.495 + 8.496 +//////////////////////////////////////////////////////////////////////////////// 8.497 +float * arda::Matrix::transpose4(Matrix4f m, Matrix4f mres) 8.498 + { 8.499 + const int size=4; 8.500 + int i, j; 8.501 + for (i=0; i<size; ++i) 8.502 + for (j=0; j<size; j++) 8.503 + mres[size*i+j] = m[size*j+i]; 8.504 + return mres; 8.505 + } 8.506 + 8.507 +//////////////////////////////////////////////////////////////////////////////// 8.508 +double * arda::Matrix::transpose4(Matrix4d m, Matrix4d mres) 8.509 + { 8.510 + const int size=4; 8.511 + int i, j; 8.512 + for (i=0; i<size; ++i) 8.513 + for (j=0; j<size; j++) 8.514 + mres[size*i+j] = m[size*j+i]; 8.515 + return mres; 8.516 + } 8.517 + 8.518 +
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/src/Vector.cpp Tue Sep 06 11:26:39 2011 -0500 9.3 @@ -0,0 +1,95 @@ 9.4 +#include "Vector.h" 9.5 + 9.6 +#include <iostream> 9.7 +#include <string> 9.8 +#include <sstream> 9.9 + 9.10 +//////////////////////////////////////////////////////////////////////////////// 9.11 +std::string & arda::Vector::getstring2v(Vector2i v, std::string & s) 9.12 + { 9.13 + s.clear(); 9.14 + std::stringstream ss; 9.15 + ss << "[ " << v[0] << ", " << v[1] << " ]"; 9.16 + s = ss.str(); 9.17 + return s; 9.18 + } 9.19 + 9.20 +//////////////////////////////////////////////////////////////////////////////// 9.21 +std::string & arda::Vector::getstring2v(Vector2f v, std::string & s) 9.22 + { 9.23 + s.clear(); 9.24 + std::stringstream ss; 9.25 + ss << "[ " << v[0] << ", " << v[1] << " ]"; 9.26 + s = ss.str(); 9.27 + return s; 9.28 + } 9.29 + 9.30 +//////////////////////////////////////////////////////////////////////////////// 9.31 +std::string & arda::Vector::getstring2v(Vector2d v, std::string & s) 9.32 + { 9.33 + s.clear(); 9.34 + std::stringstream ss; 9.35 + ss << "[ " << v[0] << ", " << v[1] << " ]"; 9.36 + s = ss.str(); 9.37 + return s; 9.38 + } 9.39 + 9.40 +//////////////////////////////////////////////////////////////////////////////// 9.41 +std::string & arda::Vector::getstring3v(Vector3i v, std::string & s) 9.42 + { 9.43 + s.clear(); 9.44 + std::stringstream ss; 9.45 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; 9.46 + s = ss.str(); 9.47 + return s; 9.48 + } 9.49 + 9.50 +//////////////////////////////////////////////////////////////////////////////// 9.51 +std::string & arda::Vector::getstring3v(Vector3f v, std::string & s) 9.52 + { 9.53 + s.clear(); 9.54 + std::stringstream ss; 9.55 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; 9.56 + s = ss.str(); 9.57 + return s; 9.58 + } 9.59 + 9.60 +//////////////////////////////////////////////////////////////////////////////// 9.61 +std::string & arda::Vector::getstring3v(Vector3d v, std::string & s) 9.62 + { 9.63 + s.clear(); 9.64 + std::stringstream ss; 9.65 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; 9.66 + s = ss.str(); 9.67 + return s; 9.68 + } 9.69 + 9.70 +//////////////////////////////////////////////////////////////////////////////// 9.71 +std::string & arda::Vector::getstring4v(Vector4i v, std::string & s) 9.72 + { 9.73 + s.clear(); 9.74 + std::stringstream ss; 9.75 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; 9.76 + s = ss.str(); 9.77 + return s; 9.78 + } 9.79 + 9.80 +//////////////////////////////////////////////////////////////////////////////// 9.81 +std::string & arda::Vector::getstring4v(Vector4f v, std::string & s) 9.82 + { 9.83 + s.clear(); 9.84 + std::stringstream ss; 9.85 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; 9.86 + s = ss.str(); 9.87 + return s; 9.88 + } 9.89 + 9.90 +//////////////////////////////////////////////////////////////////////////////// 9.91 +std::string & arda::Vector::getstring4v(Vector4d v, std::string & s) 9.92 + { 9.93 + s.clear(); 9.94 + std::stringstream ss; 9.95 + ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; 9.96 + s = ss.str(); 9.97 + return s; 9.98 + }
10.1 --- a/src/main.cpp Sun Sep 04 12:46:08 2011 -0500 10.2 +++ b/src/main.cpp Tue Sep 06 11:26:39 2011 -0500 10.3 @@ -1,12 +1,15 @@ 10.4 #include <iostream> 10.5 #include <iomanip> 10.6 +#include <limits> 10.7 #include <string> 10.8 using namespace std; 10.9 10.10 #include "Math.h" 10.11 using namespace arda::Vector; 10.12 +using namespace arda::Matrix; 10.13 10.14 -int main (int argc, char * argv[]) 10.15 +//////////////////////////////////////////////////////////////////////////////// 10.16 +void test_vector(void) 10.17 { 10.18 string s1, s2; 10.19 10.20 @@ -16,28 +19,28 @@ 10.21 "Testing Vector::scale*()" << endl; 10.22 10.23 Vector2i v2i = { 1, 2 }; 10.24 - cout << setw(40) << "v2i: " << vectostr2(v2i, s1) << endl; 10.25 - scale2(v2i, 2); 10.26 - cout << setw(40) << "scale2(v2i, 2): " << vectostr2(v2i, s1) << endl; 10.27 - scale2(v2i, 2.4); 10.28 - cout << setw(40) << "scale2(vi, 2.4): " << vectostr2(v2i, s1) << endl; 10.29 - scale2(scale2(v2i, 2), 3); 10.30 - cout << setw(40) << "scale2(scale2(v2i, 2), 3): " << vectostr2(v2i, s1) << endl; 10.31 + cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl; 10.32 + scale2v(v2i, 2); 10.33 + cout << setw(40) << "scale2v(v2i, 2): " << getstring2v(v2i, s1) << endl; 10.34 + scale2v(v2i, 2.4); 10.35 + cout << setw(40) << "scale2v(v2i, 2.4): " << getstring2v(v2i, s1) << endl; 10.36 + scale2v(scale2v(v2i, 2), 3); 10.37 + cout << setw(40) << "scale2v(scale2v(v2i, 2), 3): " << getstring2v(v2i, s1) << endl; 10.38 10.39 10.40 Vector3f v3f = { 3.0, 4.1, 5.2 }; 10.41 - cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl; 10.42 - scale3(v3f, 2.2f); 10.43 - cout << setw(40) << "scale3(v3f, 2.2f): " << vectostr3(v3f, s1) << endl; 10.44 - scale3(v3f, 2); 10.45 - cout << setw(40) << "scale3(v2f, 2): " << vectostr3(v3f, s1) << endl; 10.46 + cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; 10.47 + scale3v(v3f, 2.2f); 10.48 + cout << setw(40) << "scale3v(v3f, 2.2f): " << getstring3v(v3f, s1) << endl; 10.49 + scale3v(v3f, 2); 10.50 + cout << setw(40) << "scale3v(v2f, 2): " << getstring3v(v3f, s1) << endl; 10.51 10.52 Vector4d v4d = { 6.0L, 7.1L, 8.2L, 9.3L }; 10.53 - cout << setw(40) << "vd4: " << vectostr4(v4d, s1) << endl; 10.54 - scale4(v4d, 2.0); 10.55 - cout << setw(40) << "scale4(v4d, 2.0): " << vectostr4(v4d, s1) << endl; 10.56 - scale4(v4d, 2); 10.57 - cout << setw(40) << "scale4(v4d, 2): " << vectostr4(v4d, s1) << endl; 10.58 + cout << setw(40) << "vd4: " << getstring4v(v4d, s1) << endl; 10.59 + scale4v(v4d, 2.0); 10.60 + cout << setw(40) << "scale4v(v4d, 2.0): " << getstring4v(v4d, s1) << endl; 10.61 + scale4v(v4d, 2); 10.62 + cout << setw(40) << "scale4v(v4d, 2): " << getstring4v(v4d, s1) << endl; 10.63 } 10.64 10.65 10.66 @@ -47,19 +50,19 @@ 10.67 "Testing Vector::dot*()" << endl; 10.68 10.69 Vector2i v2i[2] = { { 1, 2 }, { 3, 4 } }; 10.70 - cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl; 10.71 - cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl; 10.72 - cout << setw(40) << "dot2(v2i[0], v2i[1]): " << dot2(v2i[0], v2i[1]) << endl; 10.73 + cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; 10.74 + cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; 10.75 + cout << setw(40) << "dot2v(v2i[0], v2i[1]): " << dot2v(v2i[0], v2i[1]) << endl; 10.76 10.77 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.78 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.79 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.80 - cout << setw(40) << "dot3(v3f[0], v3f[1]): " << dot3(v3f[0], v3f[1]) << endl; 10.81 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.82 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.83 + cout << setw(40) << "dot3v(v3f[0], v3f[1]): " << dot3v(v3f[0], v3f[1]) << endl; 10.84 10.85 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; 10.86 - cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl; 10.87 - cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl; 10.88 - cout << setw(40) << "dot4(v4d[0], v4d[1]): " << dot4(v4d[0], v4d[1]) << endl; 10.89 + cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; 10.90 + cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; 10.91 + cout << setw(40) << "dot4v(v4d[0], v4d[1]): " << dot4v(v4d[0], v4d[1]) << endl; 10.92 10.93 } 10.94 10.95 @@ -69,16 +72,16 @@ 10.96 "Testing Vector::length*()" << endl; 10.97 10.98 Vector2i v2i = { 1, 2 }; 10.99 - cout << setw(40) << "v2i: " << vectostr2(v2i, s1) << endl; 10.100 - cout << setw(40) << "length2(v2i): " << length2(v2i) << endl; 10.101 + cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl; 10.102 + cout << setw(40) << "length2v(v2i): " << length2v(v2i) << endl; 10.103 10.104 Vector3f v3f = { 1.1f, 2.2f, 3.3f }; 10.105 - cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl; 10.106 - cout << setw(40) << "length3(v3f): " << length3(v3f) << endl; 10.107 + cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; 10.108 + cout << setw(40) << "length3v(v3f): " << length3v(v3f) << endl; 10.109 10.110 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; 10.111 - cout << setw(40) << "v4d: " << vectostr4(v4d, s1) << endl; 10.112 - cout << setw(40) << "length4(v4d): " << length4(v4d) << endl; 10.113 + cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl; 10.114 + cout << setw(40) << "length4v(v4d): " << length4v(v4d) << endl; 10.115 10.116 } 10.117 10.118 @@ -88,28 +91,25 @@ 10.119 "Testing Vector::add*()" << endl; 10.120 10.121 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; 10.122 - Vector2i v2ires; 10.123 - cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl; 10.124 - cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl; 10.125 - add2(v2i[0], v2i[1], v2ires); 10.126 - cout << setw(40) << "add2(v2i[0], v2i[1], v2ires): " << vectostr2(v2ires, s1) << endl; 10.127 - cout << setw(40) << "length2(add2(v2i[0], v2i[1], v2ires)): " << length2(add2(v2i[0], v2i[1], v2ires)) << endl; 10.128 + cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; 10.129 + cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; 10.130 + add2v(v2i[0], v2i[1]); 10.131 + cout << setw(40) << "add2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; 10.132 + cout << setw(40) << "length2v(add2v(v2i[0], v2i[1])): " << length2v(add2v(v2i[0], v2i[1])) << endl; 10.133 10.134 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.135 - Vector3f v3fres; 10.136 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.137 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.138 - add3(v3f[0], v3f[1], v3fres); 10.139 - cout << setw(40) << "add3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl; 10.140 - cout << setw(40) << "length3(add3(v3f[0], v3f[1], v3fres)): " << length3(add3(v3f[0], v3f[1], v3fres)) << endl; 10.141 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.142 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.143 + add3v(v3f[0], v3f[1]); 10.144 + cout << setw(40) << "add3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; 10.145 + cout << setw(40) << "length3v(add3v(v3f[0], v3f[1])): " << length3v(add3v(v3f[0], v3f[1])) << endl; 10.146 10.147 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; 10.148 - Vector4d v4dres; 10.149 - cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl; 10.150 - cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl; 10.151 - add4(v4d[0], v4d[1], v4dres); 10.152 - cout << setw(40) << "add4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl; 10.153 - cout << setw(40) << "length4(add4(v4d[0], v4d[1], v4dres)): " << length4(add4(v4d[0], v4d[1], v4dres)) << endl; 10.154 + cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; 10.155 + cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; 10.156 + add4v(v4d[0], v4d[1]); 10.157 + cout << setw(40) << "add4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; 10.158 + cout << setw(40) << "length4v(add4v(v4d[0], v4d[1])): " << length4v(add4v(v4d[0], v4d[1])) << endl; 10.159 10.160 } 10.161 10.162 @@ -119,25 +119,25 @@ 10.163 "Testing Vector::normalize*()" << endl; 10.164 10.165 Vector2f v2f = { 1.1, 2.2 }; 10.166 - cout << setw(40) << "v2f: " << vectostr2(v2f, s1) << endl; 10.167 - normalize2(v2f); 10.168 - cout << setw(40) << "normalize2(v2f): " << vectostr2(v2f, s1) << endl; 10.169 - scale2(normalize2(v2f), 2.0); 10.170 - cout << setw(40) << "scale(normalize2(v2f), 2.0): " << vectostr2(v2f, s1) << endl; 10.171 + cout << setw(40) << "v2f: " << getstring2v(v2f, s1) << endl; 10.172 + normalize2v(v2f); 10.173 + cout << setw(40) << "normalize2v(v2f): " << getstring2v(v2f, s1) << endl; 10.174 + scale2v(normalize2v(v2f), 2.0); 10.175 + cout << setw(40) << "scale(normalize2v(v2f), 2.0): " << getstring2v(v2f, s1) << endl; 10.176 10.177 Vector3f v3f = { 1.1f, 2.2f, 3.3f }; 10.178 - cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl; 10.179 - normalize3(v3f); 10.180 - cout << setw(40) << "normalize3(v3f): " << vectostr3(v3f, s1) << endl; 10.181 - scale3(normalize3(v3f), 2.0); 10.182 - cout << setw(40) << "scale(normalize3(v3f), 2.0): " << vectostr3(v3f, s1) << endl; 10.183 + cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; 10.184 + normalize3v(v3f); 10.185 + cout << setw(40) << "normalize3v(v3f): " << getstring3v(v3f, s1) << endl; 10.186 + scale3v(normalize3v(v3f), 2.0); 10.187 + cout << setw(40) << "scale(normalize3v(v3f), 2.0): " << getstring3v(v3f, s1) << endl; 10.188 10.189 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; 10.190 - cout << setw(40) << "v4d: " << vectostr4(v4d, s1) << endl; 10.191 - normalize4(v4d); 10.192 - cout << setw(40) << "normalize4(v4d): " << vectostr4(v4d, s1) << endl; 10.193 - scale4(normalize4(v4d), 2.0); 10.194 - cout << setw(40) << "scale4(normalize4(v4d), 2.0): " << vectostr4(v4d, s1) << endl; 10.195 + cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl; 10.196 + normalize4v(v4d); 10.197 + cout << setw(40) << "normalize4v(v4d): " << getstring4v(v4d, s1) << endl; 10.198 + scale4v(normalize4v(v4d), 2.0); 10.199 + cout << setw(40) << "scale4v(normalize4v(v4d), 2.0): " << getstring4v(v4d, s1) << endl; 10.200 10.201 } 10.202 10.203 @@ -147,16 +147,16 @@ 10.204 "Testing Vector::cross()" << endl; 10.205 10.206 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 0.0f, 0.0f, 0.0f } }; 10.207 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.208 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.209 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.210 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.211 cross(v3f[0], v3f[1], v3f[2]); 10.212 - cout << setw(40) << "cross(v3f[0], v3f[1], v3f[2]): " << vectostr3(v3f[2], s1) << endl; 10.213 + cout << setw(40) << "cross(v3f[0], v3f[1], v3f[2]): " << getstring3v(v3f[2], s1) << endl; 10.214 10.215 Vector3d v3d[3] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 0.0, 0.0, 0.0 } }; 10.216 - cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl; 10.217 - cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl; 10.218 + cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; 10.219 + cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; 10.220 cross(v3d[0], v3d[1], v3d[2]); 10.221 - cout << setw(40) << "cross(v3d[0], v3d[1], v3d[2]): " << vectostr3(v3d[2], s1) << endl; 10.222 + cout << setw(40) << "cross(v3d[0], v3d[1], v3d[2]): " << getstring3v(v3d[2], s1) << endl; 10.223 10.224 } 10.225 10.226 @@ -167,28 +167,28 @@ 10.227 "Testing Vector::get_angle*()" << endl; 10.228 10.229 Vector3i v3i[2] = { { 1, 2, 3 }, { 4, 5, 6 } }; 10.230 - cout << setw(40) << "v3i[0]: " << vectostr3(v3i[0], s1) << endl; 10.231 - cout << setw(40) << "v3i[1]: " << vectostr3(v3i[1], s1) << endl; 10.232 - cout << setw(40) << "get_angle3(v3i[0], v3i[1]): " << get_angle3(v3i[0], v3i[1]) << endl; 10.233 + cout << setw(40) << "v3i[0]: " << getstring3v(v3i[0], s1) << endl; 10.234 + cout << setw(40) << "v3i[1]: " << getstring3v(v3i[1], s1) << endl; 10.235 + cout << setw(40) << "get_angle3v(v3i[0], v3i[1]): " << get_angle3v(v3i[0], v3i[1]) << endl; 10.236 10.237 Vector3f v3f[2] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.238 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.239 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.240 - cout << setw(40) << "get_angle3(v3f[0], v3f[1]): " << get_angle3(v3f[0], v3f[1]) << endl; 10.241 - normalize3(v3f[0]); 10.242 - normalize3(v3f[1]); 10.243 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.244 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.245 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.246 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.247 + cout << setw(40) << "get_angle3v(v3f[0], v3f[1]): " << get_angle3v(v3f[0], v3f[1]) << endl; 10.248 + normalize3v(v3f[0]); 10.249 + normalize3v(v3f[1]); 10.250 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.251 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.252 cout << setw(40) << "get_angle3n(v3f[0], v3f[1]): " << get_angle3n(v3f[0], v3f[1]) << endl; 10.253 10.254 Vector3d v3d[2] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } }; 10.255 - cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl; 10.256 - cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl; 10.257 - cout << setw(40) << "get_angle3(v3d[0], v3d[1]): " << get_angle3(v3d[0], v3d[1]) << endl; 10.258 - normalize3(v3d[0]); 10.259 - normalize3(v3d[1]); 10.260 - cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl; 10.261 - cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl; 10.262 + cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; 10.263 + cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; 10.264 + cout << setw(40) << "get_angle3v(v3d[0], v3d[1]): " << get_angle3v(v3d[0], v3d[1]) << endl; 10.265 + normalize3v(v3d[0]); 10.266 + normalize3v(v3d[1]); 10.267 + cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; 10.268 + cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; 10.269 cout << setw(40) << "get_angle3n(v3d[0], v3d[1]): " << get_angle3n(v3d[0], v3d[1]) << endl; 10.270 } 10.271 10.272 @@ -198,28 +198,25 @@ 10.273 "Testing Vector::subtract*()" << endl; 10.274 10.275 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; 10.276 - Vector2i v2ires; 10.277 - cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl; 10.278 - cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl; 10.279 - subtract2(v2i[0], v2i[1], v2ires); 10.280 - cout << setw(40) << "subtract2(v2i[0], v2i[1], v2ires): " << vectostr2(v2ires, s1) << endl; 10.281 - cout << setw(40) << "length2(subtract2(v2i[0], v2i[1], v2ires)): " << length2(subtract2(v2i[0], v2i[1], v2ires)) << endl; 10.282 + cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; 10.283 + cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; 10.284 + subtract2v(v2i[0], v2i[1]); 10.285 + cout << setw(40) << "subtract2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; 10.286 + cout << setw(40) << "length2v(subtract2v(v2i[0], v2i[1])): " << length2v(subtract2v(v2i[0], v2i[1])) << endl; 10.287 10.288 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.289 - Vector3f v3fres; 10.290 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.291 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.292 - subtract3(v3f[0], v3f[1], v3fres); 10.293 - cout << setw(40) << "subtract3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl; 10.294 - cout << setw(40) << "length3(subtract3(v3f[0], v3f[1], v3fres)): " << length3(subtract3(v3f[0], v3f[1], v3fres)) << endl; 10.295 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.296 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.297 + subtract3v(v3f[0], v3f[1]); 10.298 + cout << setw(40) << "subtract3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; 10.299 + cout << setw(40) << "length3v(subtract3v(v3f[0], v3f[1])): " << length3v(subtract3v(v3f[0], v3f[1])) << endl; 10.300 10.301 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; 10.302 - Vector4d v4dres; 10.303 - cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl; 10.304 - cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl; 10.305 - subtract4(v4d[0], v4d[1], v4dres); 10.306 - cout << setw(40) << "subtract4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl; 10.307 - cout << setw(40) << "length4(subtract4(v4d[0], v4d[1], v4dres)): " << length4(subtract4(v4d[0], v4d[1], v4dres)) << endl; 10.308 + cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; 10.309 + cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; 10.310 + subtract4v(v4d[0], v4d[1]); 10.311 + cout << setw(40) << "subtract4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; 10.312 + cout << setw(40) << "length4v(subtract4v(v4d[0], v4d[1])): " << length4v(subtract4v(v4d[0], v4d[1])) << endl; 10.313 10.314 } 10.315 10.316 @@ -229,22 +226,22 @@ 10.317 "Testing Vector::assign*()" << endl; 10.318 10.319 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; 10.320 - cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl; 10.321 - cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl; 10.322 - assign2(v2i[0], v2i[1]); 10.323 - cout << setw(40) << "assign2(v2i[0], v2i[1]): " << vectostr2(v2i[0], s1) << endl; 10.324 + cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; 10.325 + cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; 10.326 + assign2v(v2i[0], v2i[1]); 10.327 + cout << setw(40) << "assign2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; 10.328 10.329 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.330 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.331 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.332 - assign3(v3f[0], v3f[1]); 10.333 - cout << setw(40) << "assign3(v3f[0], v3f[1]): " << vectostr3(v3f[0], s1) << endl; 10.334 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.335 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.336 + assign3v(v3f[0], v3f[1]); 10.337 + cout << setw(40) << "assign3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; 10.338 10.339 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; 10.340 - cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl; 10.341 - cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl; 10.342 - assign4(v4d[0], v4d[1]); 10.343 - cout << setw(40) << "assign4(v4d[0], v4d[1]): " << vectostr4(v4d[0], s1) << endl; 10.344 + cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; 10.345 + cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; 10.346 + assign4v(v4d[0], v4d[1]); 10.347 + cout << setw(40) << "assign4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; 10.348 10.349 } 10.350 10.351 @@ -255,24 +252,347 @@ 10.352 10.353 Vector2f v2f[3] = { { 1.1f, 2.2f }, { 3.3f, 4.4f } }; 10.354 Vector2f v2fres; 10.355 - cout << setw(40) << "v2f[0]: " << vectostr2(v2f[0], s1) << endl; 10.356 - cout << setw(40) << "v2f[1]: " << vectostr2(v2f[1], s1) << endl; 10.357 - proj3(v2f[0], v2f[1], v2fres); 10.358 - cout << setw(40) << "proj3(v2f[0], v2f[1], v2fres): " << vectostr2(v2fres, s1) << endl; 10.359 + cout << setw(40) << "v2f[0]: " << getstring2v(v2f[0], s1) << endl; 10.360 + cout << setw(40) << "v2f[1]: " << getstring2v(v2f[1], s1) << endl; 10.361 + proj3v(v2f[0], v2f[1], v2fres); 10.362 + cout << setw(40) << "proj3v(v2f[0], v2f[1], v2fres): " << getstring2v(v2fres, s1) << endl; 10.363 10.364 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; 10.365 Vector3f v3fres; 10.366 - cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl; 10.367 - cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl; 10.368 - proj3(v3f[0], v3f[1], v3fres); 10.369 - cout << setw(40) << "proj3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl; 10.370 + cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; 10.371 + cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; 10.372 + proj3v(v3f[0], v3f[1], v3fres); 10.373 + cout << setw(40) << "proj3v(v3f[0], v3f[1], v3fres): " << getstring3v(v3fres, s1) << endl; 10.374 10.375 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; 10.376 Vector4d v4dres; 10.377 - cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl; 10.378 - cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl; 10.379 - proj4(v4d[0], v4d[1], v4dres); 10.380 - cout << setw(40) << "proj4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl; 10.381 + cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; 10.382 + cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; 10.383 + proj4v(v4d[0], v4d[1], v4dres); 10.384 + cout << setw(40) << "proj4v(v4d[0], v4d[1], v4dres): " << getstring4v(v4dres, s1) << endl; 10.385 10.386 } 10.387 + 10.388 } 10.389 + 10.390 +//////////////////////////////////////////////////////////////////////////////// 10.391 +void test_matrix(void) 10.392 + { 10.393 + std::string s; 10.394 + 10.395 + { 10.396 + cout << "===============================================================" << endl << 10.397 + "Testing Matrix::assign*()" << endl; 10.398 + Matrix2i m2i[2] = { { 0, 0, 10.399 + 0, 0 }, 10.400 + { 1, 2, 10.401 + 3, 4 } }; 10.402 + Matrix3f m3f[2] = { { 0.0f, 0.0f, 0.0f, 10.403 + 0.0f, 0.0f, 0.0f, 10.404 + 0.0f, 0.0f, 0.0f }, 10.405 + { 1.1f, 2.2f, 3.3f, 10.406 + 4.4f, 5.5f, 6.6f, 10.407 + 7.7f, 8.8f, 9.9f } }; 10.408 + Matrix4d m4d[2] = { { 0.0, 0.0, 0.0, 0.0, 10.409 + 0.0, 0.0, 0.0, 0.0, 10.410 + 0.0, 0.0, 0.0, 0.0, 10.411 + 0.0, 0.0, 0.0, 0.0 }, 10.412 + { 1.1, 2.2, 3.3, 4.4, 10.413 + 5.5, 6.6, 7.7, 8.8, 10.414 + 9.9, 10.10, 11.11, 12.12, 10.415 + 13.13, 14.14, 15.15, 16.16 } }; 10.416 + cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; 10.417 + cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; 10.418 + assign2m(m2i[0], m2i[1]); 10.419 + cout << setw(40) << "assign2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; 10.420 + 10.421 + cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; 10.422 + cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; 10.423 + assign3m(m3f[0], m3f[1]); 10.424 + cout << setw(40) << "assign3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; 10.425 + 10.426 + cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; 10.427 + cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; 10.428 + assign4m(m4d[0], m4d[1]); 10.429 + cout << setw(40) << "assign4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; 10.430 + } 10.431 + 10.432 + { 10.433 + cout << "===============================================================" << endl << 10.434 + "Testing Matrix::add*()" << endl; 10.435 + Matrix2i m2i[2] = { { 1, 2, 10.436 + 3, 4 }, 10.437 + { 5, 6, 10.438 + 7, 8 } }; 10.439 + Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, 10.440 + 4.4f, 5.5f, 6.6f, 10.441 + 7.7f, 8.8f, 9.9f }, 10.442 + { 10.10f, 11.11f, 12.12f, 10.443 + 13.13f, 14.14f, 15.15f, 10.444 + 16.16f, 17.17f, 18.18f } }; 10.445 + Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, 10.446 + 5.5, 6.6, 7.7, 8.8, 10.447 + 9.9, 10.10, 11.11, 12.12, 10.448 + 13.13, 14.14, 15.15, 16.16 }, 10.449 + { 17.17, 18.18, 19.19, 20.20, 10.450 + 21.21, 22.22, 23.23, 24.24, 10.451 + 25.25, 26.26, 27.27, 28.28, 10.452 + 29.29, 30.30, 31.31, 32.32 } }; 10.453 + cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; 10.454 + cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; 10.455 + add2m(m2i[0], m2i[1]); 10.456 + cout << setw(40) << "add2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; 10.457 + 10.458 + cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; 10.459 + cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; 10.460 + add3m(m3f[0], m3f[1]); 10.461 + cout << setw(40) << "add3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; 10.462 + 10.463 + cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; 10.464 + cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; 10.465 + add4m(m4d[0], m4d[1]); 10.466 + cout << setw(40) << "add4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; 10.467 + } 10.468 + 10.469 + { 10.470 + cout << "===============================================================" << endl << 10.471 + "Testing Matrix::subtract*()" << endl; 10.472 + Matrix2i m2i[2] = { { 1, 2, 10.473 + 3, 4 }, 10.474 + { 5, 6, 10.475 + 7, 8 } }; 10.476 + Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, 10.477 + 4.4f, 5.5f, 6.6f, 10.478 + 7.7f, 8.8f, 9.9f }, 10.479 + { 10.10f, 11.11f, 12.12f, 10.480 + 13.13f, 14.14f, 15.15f, 10.481 + 16.16f, 17.17f, 18.18f } }; 10.482 + Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, 10.483 + 5.5, 6.6, 7.7, 8.8, 10.484 + 9.9, 10.10, 11.11, 12.12, 10.485 + 13.13, 14.14, 15.15, 16.16 }, 10.486 + { 17.17, 18.18, 19.19, 20.20, 10.487 + 21.21, 22.22, 23.23, 24.24, 10.488 + 25.25, 26.26, 27.27, 28.28, 10.489 + 29.29, 30.30, 31.31, 32.32 } }; 10.490 + cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; 10.491 + cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; 10.492 + subtract2m(m2i[0], m2i[1]); 10.493 + cout << setw(40) << "subtract2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; 10.494 + 10.495 + cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; 10.496 + cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; 10.497 + subtract3m(m3f[0], m3f[1]); 10.498 + cout << setw(40) << "subtract3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; 10.499 + 10.500 + cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; 10.501 + cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; 10.502 + subtract4m(m4d[0], m4d[1]); 10.503 + cout << setw(40) << "subtract4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; 10.504 + } 10.505 + 10.506 + { 10.507 + cout << "===============================================================" << endl << 10.508 + "Testing Matrix::scale*()" << endl; 10.509 + Matrix2i m2i = { 1, 2, 10.510 + 3, 4 }; 10.511 + Matrix3f m3f = { 1.1f, 2.2f, 3.3f, 10.512 + 4.4f, 5.5f, 6.6f, 10.513 + 7.7f, 8.8f, 9.9f }; 10.514 + Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, 10.515 + 5.5, 6.6, 7.7, 8.8, 10.516 + 9.9, 10.10, 11.11, 12.12, 10.517 + 13.13, 14.14, 15.15, 16.16 }; 10.518 + cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; 10.519 + cout << setw(40) << "scale2m(m2i, 2)" << getstring2m(scale2m(m2i, 2), s) << endl; 10.520 + 10.521 + cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; 10.522 + cout << setw(40) << "scale3m(m3f, 2.2f)" << getstring3m(scale3m(m3f, 2.2f), s) << endl; 10.523 + 10.524 + cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; 10.525 + cout << setw(40) << "scale4m(m3d, 2.2)" << getstring4m(scale4m(m4d, 2.2), s) << endl; 10.526 + } 10.527 + 10.528 + { 10.529 + cout << "===============================================================" << endl << 10.530 + "Testing Matrix::multvec*()" << endl; 10.531 + Vector2i v2ires; 10.532 + Vector3f v3fres; 10.533 + Vector4d v4dres; 10.534 + Vector2i v2i = { 1, 2 }; 10.535 + Vector3f v3f = { 1.1f, 2.2f, 3.3f }; 10.536 + Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; 10.537 + Matrix2i m2i = { 1, 2, 10.538 + 3, 4 }; 10.539 + Matrix3f m3f = { 1.1f, 2.2f, 3.3f, 10.540 + 4.4f, 5.5f, 6.6f, 10.541 + 7.7f, 8.8f, 9.9f }; 10.542 + Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, 10.543 + 5.5, 6.6, 7.7, 8.8, 10.544 + 9.9, 10.10, 11.11, 12.12, 10.545 + 13.13, 14.14, 15.15, 16.16 }; 10.546 + cout << setw(40) << "v2i" << getstring2v(v2i, s) << endl; 10.547 + cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; 10.548 + cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" << 10.549 + getstring2v(multvec2mv(m2i, v2i, v2ires), s) << endl; 10.550 + cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" << 10.551 + getstring2v(multvec2vm(v2i, m2i, v2ires), s) << endl; 10.552 + 10.553 + cout << setw(40) << "v3f" << getstring3v(v3f, s) << endl; 10.554 + cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; 10.555 + cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" << 10.556 + getstring3v(multvec3mv(m3f, v3f, v3fres), s) << endl; 10.557 + cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" << 10.558 + getstring3v(multvec3vm(v3f, m3f, v3fres), s) << endl; 10.559 + 10.560 + cout << setw(40) << "v4d" << getstring4v(v4d, s) << endl; 10.561 + cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; 10.562 + cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" << 10.563 + getstring4v(multvec4mv(m4d, v4d, v4dres), s) << endl; 10.564 + cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" << 10.565 + getstring4v(multvec4vm(v4d, m4d, v4dres), s) << endl; 10.566 + 10.567 + } 10.568 + 10.569 + 10.570 + { 10.571 + cout << "===============================================================" << endl << 10.572 + "Testing Matrix::multmat*()" << endl; 10.573 + Matrix2i m2ires; 10.574 + Matrix3f m3fres; 10.575 + Matrix4d m4dres; 10.576 + Matrix2i m2i[2] = { { 1, 2, 10.577 + 3, 4 }, 10.578 + { 5, 6, 10.579 + 7, 8 } }; 10.580 + Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, 10.581 + 4.4f, 5.5f, 6.6f, 10.582 + 7.7f, 8.8f, 9.9f }, 10.583 + { 10.10f, 11.11f, 12.12f, 10.584 + 13.13f, 14.14f, 15.15f, 10.585 + 16.16f, 17.17f, 18.18f } }; 10.586 + Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, 10.587 + 5.5, 6.6, 7.7, 8.8, 10.588 + 9.9, 10.10, 11.11, 12.12, 10.589 + 13.13, 14.14, 15.15, 16.16 }, 10.590 + { 17.17, 18.18, 19.19, 20.20, 10.591 + 21.21, 22.22, 23.23, 24.24, 10.592 + 25.25, 26.26, 27.27, 28.28, 10.593 + 29.29, 30.30, 31.31, 32.32 } }; 10.594 + cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; 10.595 + cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; 10.596 + multmat2(m2i[0], m2i[1], m2ires); 10.597 + cout << setw(40) << "multmat2(m2i[0], m2i[1], m21res)" << 10.598 + getstring2m(m2ires, s) << endl; 10.599 + 10.600 + cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; 10.601 + cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; 10.602 + multmat3(m3f[0], m3f[1], m3fres); 10.603 + cout << setw(40) << "multmat3(m3f[0], m3f[1], m3fres)" << 10.604 + getstring3m(m3fres, s) << endl; 10.605 + 10.606 + cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; 10.607 + cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; 10.608 + multmat4(m4d[0], m4d[1], m4dres); 10.609 + cout << setw(40) << "multmat4(m4d[0], m4d[1], m4dres)" << 10.610 + getstring4m(m4dres, s) << endl; 10.611 + } 10.612 + 10.613 + { 10.614 + cout << "===============================================================" << endl << 10.615 + "Testing Matrix::transpose*()" << endl; 10.616 + Matrix2i m2ires; 10.617 + Matrix3f m3fres; 10.618 + Matrix4d m4dres; 10.619 + Matrix2i m2i = { 1, 2, 10.620 + 3, 4 }; 10.621 + Matrix3f m3f = { 1.1f, 2.2f, 3.3f, 10.622 + 4.4f, 5.5f, 6.6f, 10.623 + 7.7f, 8.8f, 9.9f }; 10.624 + Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, 10.625 + 5.5, 6.6, 7.7, 8.8, 10.626 + 9.9, 10.10, 11.11, 12.12, 10.627 + 13.13, 14.14, 15.15, 16.16 }; 10.628 + cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; 10.629 + cout << setw(40) << "transpose2(m2i, m2ires)" << 10.630 + getstring2m(transpose2(m2i, m2ires), s) << endl; 10.631 + 10.632 + cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; 10.633 + cout << setw(40) << "transpose3(m3f, m3fres)" << 10.634 + getstring3m(transpose3(m3f, m3fres), s) << endl; 10.635 + 10.636 + cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; 10.637 + cout << setw(40) << "transpose4(m4d, m4dres)" << 10.638 + getstring4m(transpose4(m4d, m4dres), s) << endl; 10.639 + 10.640 + } 10.641 + } 10.642 + 10.643 +//////////////////////////////////////////////////////////////////////////////// 10.644 +void test_all(void) 10.645 + { 10.646 + test_vector(); 10.647 + test_matrix(); 10.648 + } 10.649 + 10.650 +//////////////////////////////////////////////////////////////////////////////// 10.651 +void show_menu(void) 10.652 + { 10.653 + cout << endl << endl 10.654 + << "Test what?" << endl 10.655 + << "0) All" << endl << endl 10.656 + << "1) Vector" << endl 10.657 + << "2) Matrix" << endl 10.658 + << endl 10.659 + << "99 Quit" << endl; 10.660 + } 10.661 + 10.662 +//////////////////////////////////////////////////////////////////////////////// 10.663 +int main (int argc, char * argv[]) 10.664 + { 10.665 + int retval = 0; 10.666 + 10.667 + try 10.668 + { 10.669 + int choice = -1; 10.670 + 10.671 + while (choice != 99) 10.672 + { 10.673 + show_menu(); 10.674 + cin >> choice; 10.675 + if(!cin) 10.676 + { 10.677 + cin.clear(); 10.678 + cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); 10.679 + } 10.680 + if (choice != 99) 10.681 + { 10.682 + switch (choice) 10.683 + { 10.684 + case 0: 10.685 + test_all(); 10.686 + break; 10.687 + case 1: 10.688 + test_vector(); 10.689 + break; 10.690 + case 2: 10.691 + test_matrix(); 10.692 + break; 10.693 + default: 10.694 + cout << "Unrecognized choice. Please try again." << endl; 10.695 + } 10.696 + choice = -1; 10.697 + } 10.698 + } 10.699 + } 10.700 + catch (const std::exception & error) 10.701 + { 10.702 + string e = "Caught exception: "; 10.703 + e += error.what(); 10.704 + cerr << e << endl; 10.705 + retval = 1; 10.706 + } 10.707 + 10.708 + return retval;; 10.709 + 10.710 + }