Mercurial > Math
changeset 12:1d2b25d4517f
Lot's of updates, some quite old since I guess I forgot to commit a while back. But I just added rotation matrix related things.
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Mon, 06 May 2013 01:06:12 -0500 |
parents | 398894c52b69 |
children | e00321d11fe1 |
files | include/Math.h include/Matrix.h include/Vector.h src/main.cpp |
diffstat | 4 files changed, 1483 insertions(+), 448 deletions(-) [+] |
line diff
1.1 --- a/include/Math.h Fri Oct 07 13:33:48 2011 -0500 1.2 +++ b/include/Math.h Mon May 06 01:06:12 2013 -0500 1.3 @@ -4,29 +4,30 @@ 1.4 #include "Vector.h" 1.5 #include "Matrix.h" 1.6 1.7 +/////////////////////////////////////////////////////////////////////////////////// 1.8 +// Notes for improvement 1.9 +// 1.10 +// The angle related constants (PI, 2PI, etc) and functions (deg_to_rad, rad_to_deg) 1.11 +// could be made faster by using #define's. In fact, this would turn them into 1.12 +// compile time operations. But it would also put them, effectively, in the 1.13 +// global namespace. Do I want that? For now I'm leaving things as const 1.14 +// variables and inline functions. I can profile things later to see if changes 1.15 +// are really needed. 1.16 + 1.17 namespace arda 1.18 { 1.19 1.20 //////////////////////////////////////////////////////////////////////////////// 1.21 - // General notes: 1.22 - // 1.23 - // As much as possible is defined inline for performance. 1.24 - // Using typedef'ed arrays for vectors and matrices necessitates a lot of 1.25 - // redundant function names: scale2, scale3, scale4, for example. 1.26 - // This is, however, perfectly in line with the implementation of OpenGL and 1.27 - // allows the library to maintain optimal memory usage and performance. (I hope!) 1.28 - // In any event, I think I could do far worse than to emulate the OpenGL 1.29 - // working group - a group of people who have studied this for years and are 1.30 - // experts in the field. 1.31 - 1.32 - //////////////////////////////////////////////////////////////////////////////// 1.33 // Angles 1.34 1.35 namespace Math 1.36 { 1.37 // This many decimals is enough to cover even IEEE quad precision (128 bit) 1.38 // reals. Run on PA-RISC lately? :) 1.39 - const double PI = 3.14159265358979323846264338327950288; 1.40 + long double const PI = 3.14159265358979323846264338327950288; 1.41 + long double const TWO_PI = 6.28318530717958647692528676655900577; 1.42 + long double const PI_DIV_180 = 0.01745329251994329576923690768488613; 1.43 + long double const INV_PI_DIV_180 = 57.29577951308232087679815481410517033; 1.44 1.45 ////////////////////////////////////////////////////////////////////////// 1.46 // Mixed Vector / Matrix operations. 1.47 @@ -35,8 +36,10 @@ 1.48 // operators are not part of the class. They are defined independently. 1.49 // 1.50 1.51 - // Vector * Matrix 1.52 - template <typename T> inline Vector2<T>& operator*=(Vector2<T>& v, const Matrix22<T>& m) 1.53 + // Vector2 * Matrix22 1.54 + template <typename T> 1.55 + inline Vector2<T>& operator*=(Vector2<T> & v, 1.56 + Matrix22<T> const & m) 1.57 { 1.58 Vector2<T> vres(0); 1.59 vres[0] = v[0]*m[0] + v[1]*m[1]; 1.60 @@ -44,12 +47,16 @@ 1.61 v = vres; 1.62 return v; 1.63 } 1.64 - template <typename T> inline Vector2<T> operator*(const Vector2<T>& v, const Matrix22<T>& m) 1.65 + 1.66 + template <typename T> 1.67 + inline Vector2<T> operator*(Vector2<T> const & v, 1.68 + Matrix22<T> const & m) 1.69 { return Vector2<T>(v) *= m; } 1.70 1.71 - // Matrix * Vector 1.72 // Note: can't define Matrix *= Vector since the result is a Vector. 1.73 - template <typename T> inline Vector2<T> operator*(const Matrix22<T>& m, const Vector2<T>& v) 1.74 + template <typename T> 1.75 + inline Vector2<T> operator*(Matrix22<T> const & m, 1.76 + Vector2<T> const & v) 1.77 { 1.78 Vector2<T> vres(0); 1.79 vres[0] = m[0]*v[0] + m[2]*v[1]; 1.80 @@ -57,8 +64,110 @@ 1.81 return vres; 1.82 } 1.83 1.84 + //////////////////////////////////////// 1.85 + // Vector3 * Matrix33 1.86 + template <typename T> 1.87 + inline Vector3<T>& operator*=(Vector3<T> & v, 1.88 + Matrix33<T> const & m) 1.89 + { 1.90 + Vector3<T> vres(0); 1.91 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; 1.92 + vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; 1.93 + vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; 1.94 + v = vres; 1.95 + return v; 1.96 + } 1.97 + 1.98 + template <typename T> 1.99 + inline Vector3<T> operator*(Vector3<T> const & v, 1.100 + Matrix33<T> const & m) 1.101 + { return Vector3<T>(v) *= m; } 1.102 + 1.103 + // Matrix * Vector 1.104 + // Note: can't define Matrix *= Vector since the result is a Vector. 1.105 + template <typename T> 1.106 + inline Vector3<T> operator*(Matrix33<T> const & m, 1.107 + Vector3<T> const & v) 1.108 + { 1.109 + Vector3<T> vres(0); 1.110 + vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; 1.111 + vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; 1.112 + vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; 1.113 + return vres; 1.114 + } 1.115 + 1.116 + //////////////////////////////////////// 1.117 + // Vector4 * Matrix44 1.118 + template <typename T> 1.119 + inline Vector4<T>& operator*=(Vector4<T> & v, 1.120 + Matrix44<T> const & m) 1.121 + { 1.122 + Vector4<T> vres(0); 1.123 + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; 1.124 + vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; 1.125 + vres[8] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; 1.126 + vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; 1.127 + v = vres; 1.128 + return v; 1.129 + } 1.130 + 1.131 + template <typename T> 1.132 + inline Vector4<T> operator*(Vector4<T> const & v, 1.133 + Matrix44<T> const & m) 1.134 + { return Vector4<T>(v) *= m; } 1.135 + 1.136 + // Matrix * Vector 1.137 + // Note: can't define Matrix *= Vector since the result is a Vector. 1.138 + template <typename T> 1.139 + inline Vector4<T> operator*(Matrix44<T> const & m, 1.140 + Vector4<T> const & v) 1.141 + { 1.142 + Vector4<T> vres(0); 1.143 + vres[0] = m[0]*v[0] + m[4]*v[1] + m[8]*v[2] + m[12]*v[3]; 1.144 + vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; 1.145 + vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; 1.146 + vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; 1.147 + return vres; 1.148 + } 1.149 + 1.150 + ////////////////////////////////////////////////////////////////////////// 1.151 + 1.152 + template <typename T> 1.153 + void get_rot_mat33(Matrix33<T> & m, float rot, Vector3<T> v); 1.154 + 1.155 + 1.156 + ////////////////////////////////////////////////////////////////////////// 1.157 + 1.158 + inline double deg_to_rad(double deg) { return deg * PI_DIV_180; }; 1.159 + inline double rad_to_deg(double rad) { return rad * INV_PI_DIV_180; }; 1.160 + 1.161 } // namespace Math 1.162 1.163 } // namespace arda 1.164 1.165 +//////////////////////////////////////////////////////////////////////////////// 1.166 +template <typename T> 1.167 +void arda::Math::get_rot_mat33(arda::Math::Matrix33<T> & m, float theta, arda::Math::Vector3<T> v) 1.168 + { 1.169 + m.setidentity(); 1.170 + if (0.0 == v.length()) 1.171 + return; 1.172 + 1.173 + // TODO: I should also immediately return identity if theta is a multiple of 2*PI but I'm not 1.174 + // yet sure how I should I check for that (taking into account floating point imprecision). 1.175 + 1.176 + 1.177 + v.normalize(); 1.178 + 1.179 + float c = cos(theta); 1.180 + float s = sin(theta); 1.181 + float one_minus_c = 1.0f - c; 1.182 + 1.183 + m.assign( 1.184 + c + one_minus_c * v.x * v.x , one_minus_c * v.x * v.y + s * v.z , one_minus_c * v.x * v.z - s * v.y , 1.185 + one_minus_c * v.x * v.y - s * v.z , c + one_minus_c * v.y * v.y , one_minus_c * v.y * v.z + s * v.x , 1.186 + one_minus_c * v.x * v.z + s * v.y , one_minus_c * v.y * v.z - s * v.x , c + one_minus_c * v.z * v.z 1.187 + ); 1.188 + } 1.189 + 1.190 #endif
2.1 --- a/include/Matrix.h Fri Oct 07 13:33:48 2011 -0500 2.2 +++ b/include/Matrix.h Mon May 06 01:06:12 2013 -0500 2.3 @@ -33,7 +33,7 @@ 2.4 // 2.5 // assign() Assign the value of one matrix to another. 2.6 // getcol() Returns the vector that is column n of the matrix. 2.7 - // getstring() Returns a printable string representation of the matrix. 2.8 + // to_string() Returns a printable string representation of the matrix. 2.9 // setcol() Set the vector that is column n of the matrix. 2.10 // Overloaded so that you can set from a vector or from 2.11 // specific values. 2.12 @@ -50,7 +50,8 @@ 2.13 // transpose() Returns the transpose of a matrix. 2.14 2.15 ////////////////////////////////////////////////////////////////////////// 2.16 - template <typename T> class Matrix22 2.17 + template <typename T> 2.18 + class Matrix22 2.19 { 2.20 public: 2.21 T m[4]; 2.22 @@ -66,19 +67,20 @@ 2.23 2.24 // Array indexing 2.25 // Remember: column major order is used. 2.26 - inline T& operator[](unsigned int i) 2.27 + inline T& operator[](unsigned int const i) 2.28 { assert (i<4); return m[i]; } 2.29 - inline T operator[](unsigned int i) const 2.30 + inline T operator[](unsigned int const i) const 2.31 { assert (i<4); return m[i]; } 2.32 2.33 // Assignment 2.34 - inline Matrix22<T>& operator=(const Matrix22<T>& m2) 2.35 + inline Matrix22<T>& operator=(Matrix22<T> const & m2) 2.36 { 2.37 m[0] = m2[0]; m[2] = m2[2]; 2.38 m[1] = m2[1]; m[3] = m2[3]; 2.39 return *this; 2.40 } 2.41 - inline Matrix22<T>& assign(T a0, T a1, T a2, T a3) 2.42 + inline Matrix22<T>& assign(T const a0, T const a1, 2.43 + T const a2, T const a3) 2.44 { 2.45 m[0] = a0; m[2] = a2; 2.46 m[1] = a1; m[3] = a3; 2.47 @@ -86,49 +88,49 @@ 2.48 } 2.49 2.50 // Comparison 2.51 - inline bool operator==(Matrix22<T>& m2) const 2.52 + inline bool operator==(Matrix22<T> const & m2) const 2.53 { 2.54 return 2.55 m[0] == m2[0] && m[2] == m2[2] && 2.56 m[1] == m2[1] && m[3] == m2[3]; 2.57 } 2.58 - inline bool operator!=(Matrix22<T>& m2) const 2.59 + inline bool operator!=(Matrix22<T> const & m2) const 2.60 { return ! (*this == m2); } 2.61 2.62 // Matrix addition 2.63 - inline Matrix22<T>& operator+=(const Matrix22<T>& m2) 2.64 + inline Matrix22<T>& operator+=(Matrix22<T> const & m2) 2.65 { 2.66 m[0] += m2[0]; m[2] += m2[2]; 2.67 m[1] += m2[1]; m[3] += m2[3]; 2.68 return *this; 2.69 } 2.70 - inline Matrix22<T> operator+(const Matrix22<T>& m2) const 2.71 + inline Matrix22<T> operator+(Matrix22<T> const & m2) const 2.72 { return Matrix22<T>(*this) += m2; } 2.73 2.74 // Matrix subtraction 2.75 - inline Matrix22<T>& operator-=(const Matrix22<T>& m2) 2.76 + inline Matrix22<T>& operator-=(Matrix22<T> const & m2) 2.77 { 2.78 m[0] -= m2[0]; m[2] -= m2[2]; 2.79 m[1] -= m2[1]; m[3] -= m2[3]; 2.80 return *this; 2.81 } 2.82 - inline Matrix22<T> operator-(const Matrix22<T>& m2) const 2.83 + inline Matrix22<T> operator-(Matrix22<T> const & m2) const 2.84 { return Matrix22<T>(*this) -= m2; } 2.85 2.86 // Scalar multiplication 2.87 - inline Matrix22<T>& operator*=(const int a) 2.88 + inline Matrix22<T>& operator*=(int const a) 2.89 { 2.90 m[0] *= a; m[2] *= a; 2.91 m[1] *= a; m[3] *= a; 2.92 return *this; 2.93 } 2.94 - inline Matrix22<T>& operator*=(const float a) 2.95 + inline Matrix22<T>& operator*=(float const a) 2.96 { 2.97 m[0] *= a; m[2] *= a; 2.98 m[1] *= a; m[3] *= a; 2.99 return *this; 2.100 } 2.101 - inline Matrix22<T>& operator*=(const double a) 2.102 + inline Matrix22<T>& operator*=(double const a) 2.103 { 2.104 m[0] *= a; m[2] *= a; 2.105 m[1] *= a; m[3] *= a; 2.106 @@ -136,39 +138,39 @@ 2.107 } 2.108 2.109 // Scalar division 2.110 - inline Matrix22<T>& operator/=(const int a) 2.111 + inline Matrix22<T>& operator/=(int const a) 2.112 { 2.113 assert(a!=0); 2.114 m[0] /= a; m[2] /= a; 2.115 m[1] /= a; m[3] /= a; 2.116 return *this; 2.117 } 2.118 - inline Matrix22<T>& operator/=(const float a) 2.119 + inline Matrix22<T>& operator/=(float const a) 2.120 { 2.121 assert(a!=0); 2.122 m[0] /= a; m[2] /= a; 2.123 m[1] /= a; m[3] /= a; 2.124 return *this; 2.125 } 2.126 - inline Matrix22<T>& operator/=(const double a) 2.127 + inline Matrix22<T>& operator/=(double const a) 2.128 { 2.129 assert(a!=0); 2.130 m[0] /= a; m[2] /= a; 2.131 m[1] /= a; m[3] /= a; 2.132 return *this; 2.133 } 2.134 - inline Matrix22<T> operator/(const int a) 2.135 + inline Matrix22<T> operator/(int const a) 2.136 { return Matrix22<T>(*this) /= a; } 2.137 - inline Matrix22<T> operator/(const float a) 2.138 + inline Matrix22<T> operator/(float const a) 2.139 { return Matrix22<T>(*this) /= a; } 2.140 - inline Matrix22<T> operator/(const double a) 2.141 + inline Matrix22<T> operator/(double const a) 2.142 { return Matrix22<T>(*this) /= a; } 2.143 2.144 // Matrix multiplication 2.145 // Not sure if this should be inlined at all. Sure the compiler will 2.146 // probably ignore the inline request here, but maybe it won't and maybe 2.147 // that would be bad. Needs real testing. 2.148 - inline Matrix22<T>& operator*=(Matrix22<T> m2) 2.149 + inline Matrix22<T>& operator*=(Matrix22<T> const & m2) 2.150 { 2.151 const int size=2; 2.152 Matrix22<T> mres(0); 2.153 @@ -180,34 +182,34 @@ 2.154 *this = mres; 2.155 return *this; 2.156 } 2.157 - inline Matrix22<T> operator*(Matrix22<T> m2) const 2.158 + inline Matrix22<T> operator*(Matrix22<T> const & m2) const 2.159 { return Matrix22<T>(*this) *= m2; } 2.160 2.161 2.162 - inline Vector2<T> getcol(const unsigned int i) const 2.163 + inline Vector2<T> getcol(unsigned int const i) const 2.164 { 2.165 assert(i<2); 2.166 - const int size=2; 2.167 + int const size=2; 2.168 return Vector2<T>(m[i*size], m[i*size+1]); 2.169 } 2.170 2.171 - inline Vector2<T> getrow(const unsigned int i) const 2.172 + inline Vector2<T> getrow(unsigned int const i) const 2.173 { 2.174 assert(i<2); 2.175 - const int size=2; 2.176 + int const size=2; 2.177 return Vector2<T>(m[i], m[i+size]); 2.178 } 2.179 2.180 - inline Matrix22<T>& setcol(const unsigned int i, const Vector2<T>& v) 2.181 + inline Matrix22<T>& setcol(unsigned int const i, Vector2<T> const & v) 2.182 { 2.183 assert(i<2); 2.184 - const int size=2; 2.185 + int const size=2; 2.186 m[i*size] = v[0]; 2.187 m[i*size+1] = v[1]; 2.188 return *this; 2.189 } 2.190 2.191 - inline Matrix22<T>& setcol(const unsigned int i, const T a, const T b) 2.192 + inline Matrix22<T>& setcol(unsigned int const i, T const a, T const b) 2.193 { 2.194 assert(i<2); 2.195 const int size=2; 2.196 @@ -216,25 +218,25 @@ 2.197 return *this; 2.198 } 2.199 2.200 - inline Matrix22<T>& setrow(const unsigned int i, const Vector2<T>& v) 2.201 + inline Matrix22<T>& setrow(unsigned int const i, Vector2<T> const & v) 2.202 { 2.203 assert(i<2); 2.204 - const int size=2; 2.205 + int const size=2; 2.206 m[i] = v[0]; 2.207 m[i+size] = v[1]; 2.208 return *this; 2.209 } 2.210 2.211 - inline Matrix22<T>& setrow(const unsigned int i, const T a, const T b) 2.212 + inline Matrix22<T>& setrow(unsigned int const i, T const a, T const b) 2.213 { 2.214 assert(i<2); 2.215 - const int size=2; 2.216 + int const size=2; 2.217 m[i] = a; 2.218 m[i+size] = b; 2.219 return *this; 2.220 } 2.221 2.222 - std::string & getstring(std::string & s) const; 2.223 + std::string & to_string(std::string & s) const; 2.224 2.225 inline Matrix22<T>& setidentity() 2.226 { 2.227 @@ -246,28 +248,560 @@ 2.228 }; 2.229 2.230 // Scalar multiplication continued 2.231 - template <typename T> inline Matrix22<T> operator*(const Matrix22<T>& m, const int a) 2.232 + template <typename T> 2.233 + inline Matrix22<T> operator*(Matrix22<T> const & m, int const a) 2.234 { return Matrix22<T>(m) *= a; } 2.235 - template <typename T> inline Matrix22<T> operator*(const int a, const Matrix22<T>& m) 2.236 + 2.237 + template <typename T> 2.238 + inline Matrix22<T> operator*(int const a, Matrix22<T> const & m) 2.239 { return Matrix22<T>(m) *= a; } 2.240 - template <typename T> inline Matrix22<T> operator*(const Matrix22<T>& m, const float a) 2.241 + 2.242 + template <typename T> 2.243 + inline Matrix22<T> operator*(Matrix22<T> const & m, float const a) 2.244 { return Matrix22<T>(m) *= a; } 2.245 - template <typename T> inline Matrix22<T> operator*(const float a, const Matrix22<T>& m) 2.246 + 2.247 + template <typename T> 2.248 + inline Matrix22<T> operator*(float const a, Matrix22<T> const & m) 2.249 { return Matrix22<T>(m) *= a; } 2.250 - template <typename T> inline Matrix22<T> operator*(const Matrix22<T>& m, const double a) 2.251 + 2.252 + template <typename T> 2.253 + inline Matrix22<T> operator*(Matrix22<T> const & m, double const a) 2.254 { return Matrix22<T>(m) *= a; } 2.255 - template <typename T> inline Matrix22<T> operator*(const double a, const Matrix22<T>& m) 2.256 + 2.257 + template <typename T> 2.258 + inline Matrix22<T> operator*(double const a, Matrix22<T> const & m) 2.259 { return Matrix22<T>(m) *= a; } 2.260 2.261 2.262 2.263 2.264 ////////////////////////////////////////////////////////////////////////// 2.265 + template <typename T> 2.266 + class Matrix33 2.267 + { 2.268 + public: 2.269 + T m[9]; 2.270 + 2.271 + // Constructors 2.272 + Matrix33() {} 2.273 + explicit Matrix33(T a) 2.274 + { 2.275 + // TODO: Is this really more efficient than memset? 2.276 + m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = m[6] = m[7] = m[8] = a; 2.277 + } 2.278 + Matrix33(T a0, T a1, T a2, 2.279 + T a3, T a4, T a5, 2.280 + T a6, T a7, T a8) 2.281 + { 2.282 + m[0] = a0; m[3] = a3; m[6] = a6; 2.283 + m[1] = a1; m[4] = a4; m[7] = a7; 2.284 + m[2] = a2; m[5] = a5; m[8] = a8; 2.285 + } 2.286 + 2.287 + // Array indexing 2.288 + // Remember: column major order is used. 2.289 + inline T& operator[](unsigned int const i) 2.290 + { assert (i<9); return m[i]; } 2.291 + inline T operator[](unsigned int const i) const 2.292 + { assert (i<9); return m[i]; } 2.293 + 2.294 + // Assignment 2.295 + inline Matrix33<T>& operator=(Matrix33<T> const & m2) 2.296 + { 2.297 + m[0] = m2[0]; m[3] = m2[3]; m[6] = m2[6]; 2.298 + m[1] = m2[1]; m[4] = m2[4]; m[7] = m2[7]; 2.299 + m[2] = m2[2]; m[5] = m2[5]; m[8] = m2[8]; 2.300 + return *this; 2.301 + } 2.302 + inline Matrix33<T>& assign(T const a0, T const a1, T const a2, 2.303 + T const a3, T const a4, T const a5, 2.304 + T const a6, T const a7, T const a8) 2.305 + { 2.306 + m[0] = a0; m[3] = a3; m[6] = a6; 2.307 + m[1] = a1; m[4] = a4; m[7] = a7; 2.308 + m[2] = a2; m[5] = a5; m[8] = a8; 2.309 + return *this; 2.310 + } 2.311 + 2.312 + // Comparison 2.313 + inline bool operator==(Matrix33<T> const & m2) const 2.314 + { 2.315 + return 2.316 + m[0] == m2[0] && m[3] == m2[3] && m[6] == m2[6] && 2.317 + m[1] == m2[1] && m[4] == m2[4] && m[7] == m2[7] && 2.318 + m[2] == m2[2] && m[5] == m2[5] && m[8] == m2[8]; 2.319 + } 2.320 + inline bool operator!=(Matrix33<T> const & m2) const 2.321 + { return ! (*this == m2); } 2.322 + 2.323 + // Matrix addition 2.324 + inline Matrix33<T>& operator+=(Matrix33<T> const & m2) 2.325 + { 2.326 + m[0] += m2[0]; m[3] += m2[3]; m[6] += m2[6]; 2.327 + m[1] += m2[1]; m[4] += m2[4]; m[7] += m2[7]; 2.328 + m[2] += m2[2]; m[5] += m2[5]; m[8] += m2[8]; 2.329 + return *this; 2.330 + } 2.331 + inline Matrix33<T> operator+(Matrix33<T> const & m2) const 2.332 + { return Matrix33<T>(*this) += m2; } 2.333 + 2.334 + // Matrix subtraction 2.335 + inline Matrix33<T>& operator-=(Matrix33<T> const & m2) 2.336 + { 2.337 + m[0] -= m2[0]; m[3] -= m2[3]; m[6] -= m2[6]; 2.338 + m[1] -= m2[1]; m[4] -= m2[4]; m[7] -= m2[7]; 2.339 + m[2] -= m2[2]; m[5] -= m2[5]; m[8] -= m2[8]; 2.340 + return *this; 2.341 + } 2.342 + inline Matrix33<T> operator-(Matrix33<T> const & m2) const 2.343 + { return Matrix33<T>(*this) -= m2; } 2.344 + 2.345 + // Scalar multiplication 2.346 + inline Matrix33<T>& operator*=(int const a) 2.347 + { 2.348 + m[0] *= a; m[3] *= a; m[6] *= a; 2.349 + m[1] *= a; m[4] *= a; m[7] *= a; 2.350 + m[2] *= a; m[5] *= a; m[8] *= a; 2.351 + return *this; 2.352 + } 2.353 + inline Matrix33<T>& operator*=(float const a) 2.354 + { 2.355 + m[0] *= a; m[3] *= a; m[6] *= a; 2.356 + m[1] *= a; m[4] *= a; m[7] *= a; 2.357 + m[2] *= a; m[5] *= a; m[8] *= a; 2.358 + return *this; 2.359 + } 2.360 + inline Matrix33<T>& operator*=(double const a) 2.361 + { 2.362 + m[0] *= a; m[3] *= a; m[6] *= a; 2.363 + m[1] *= a; m[4] *= a; m[7] *= a; 2.364 + m[2] *= a; m[5] *= a; m[8] *= a; 2.365 + return *this; 2.366 + } 2.367 + 2.368 + // Scalar division 2.369 + inline Matrix33<T>& operator/=(int const a) 2.370 + { 2.371 + assert(a!=0); 2.372 + m[0] /= a; m[3] /= a; m[6] /= a; 2.373 + m[1] /= a; m[4] /= a; m[7] /= a; 2.374 + m[2] /= a; m[5] /= a; m[8] /= a; 2.375 + return *this; 2.376 + } 2.377 + inline Matrix33<T>& operator/=(float const a) 2.378 + { 2.379 + assert(a!=0); 2.380 + m[0] /= a; m[3] /= a; m[6] /= a; 2.381 + m[1] /= a; m[4] /= a; m[7] /= a; 2.382 + m[2] /= a; m[5] /= a; m[8] /= a; 2.383 + return *this; 2.384 + } 2.385 + inline Matrix33<T>& operator/=(double const a) 2.386 + { 2.387 + assert(a!=0); 2.388 + m[0] /= a; m[3] /= a; m[6] /= a; 2.389 + m[1] /= a; m[4] /= a; m[7] /= a; 2.390 + m[2] /= a; m[5] /= a; m[8] /= a; 2.391 + return *this; 2.392 + } 2.393 + inline Matrix33<T> operator/(int const a) 2.394 + { return Matrix33<T>(*this) /= a; } 2.395 + inline Matrix33<T> operator/(float const a) 2.396 + { return Matrix33<T>(*this) /= a; } 2.397 + inline Matrix33<T> operator/(double const a) 2.398 + { return Matrix33<T>(*this) /= a; } 2.399 + 2.400 + // Matrix multiplication 2.401 + // Not sure if this should be inlined at all. Sure the compiler will 2.402 + // probably ignore the inline request here, but maybe it won't and maybe 2.403 + // that would be bad. Needs real testing. 2.404 + inline Matrix33<T>& operator*=(Matrix33<T> const & m2) 2.405 + { 2.406 + const int size=3; 2.407 + Matrix33<T> mres(0); 2.408 + int i, j, k; 2.409 + for (i=0; i<size; ++i) 2.410 + for (j=0; j<size; ++j) 2.411 + for (k=0; k<size; ++k) 2.412 + mres[size*i+j] += (*this)[size*k+j] * m2[size*i+k]; 2.413 + *this = mres; 2.414 + return *this; 2.415 + } 2.416 + inline Matrix33<T> operator*(Matrix33<T> const & m2) const 2.417 + { return Matrix33<T>(*this) *= m2; } 2.418 + 2.419 + 2.420 + inline Vector3<T> getcol(unsigned int const i) const 2.421 + { 2.422 + assert(i<3); 2.423 + const int size=3; 2.424 + return Vector3<T>(m[i*size], m[i*size+1], m[i*size+2]); 2.425 + } 2.426 + 2.427 + inline Vector3<T> getrow(unsigned int const i) const 2.428 + { 2.429 + assert(i<3); 2.430 + const int size=3; 2.431 + return Vector3<T>(m[i], m[i+size], m[i+2*size]); 2.432 + } 2.433 + 2.434 + inline Matrix33<T>& setcol(unsigned int const i, Vector3<T> const & v) 2.435 + { 2.436 + assert(i<3); 2.437 + const int size=3; 2.438 + m[i*size] = v[0]; 2.439 + m[i*size+1] = v[1]; 2.440 + m[i*size+2] = v[2]; 2.441 + return *this; 2.442 + } 2.443 + 2.444 + inline Matrix33<T>& setcol(unsigned int const i, 2.445 + T const a0, T const a1, T const a2) 2.446 + { 2.447 + assert(i<3); 2.448 + const int size=3; 2.449 + m[i*size] = a0; 2.450 + m[i*size+1] = a1; 2.451 + m[i*size+2] = a2; 2.452 + return *this; 2.453 + } 2.454 + 2.455 + inline Matrix33<T>& setrow(unsigned int const i, Vector3<T> const & v) 2.456 + { 2.457 + assert(i<3); 2.458 + const int size=3; 2.459 + m[i] = v[0]; 2.460 + m[i+size] = v[1]; 2.461 + m[i+2*size] = v[2]; 2.462 + return *this; 2.463 + } 2.464 + 2.465 + inline Matrix33<T>& setrow(unsigned int const i, 2.466 + T const a0, T const a1, T const a2) 2.467 + { 2.468 + assert(i<3); 2.469 + const int size=3; 2.470 + m[i] = a0; 2.471 + m[i+size] = a1; 2.472 + m[i+2*size] = a2; 2.473 + return *this; 2.474 + } 2.475 + 2.476 + std::string & to_string(std::string & s) const; 2.477 + 2.478 + inline Matrix33<T>& setidentity() 2.479 + { 2.480 + memset(m, 0, sizeof(m)); 2.481 + m[0] = m[4] = m[8] = 1; 2.482 + return *this; 2.483 + } 2.484 + 2.485 + }; 2.486 + 2.487 + // Scalar multiplication continued 2.488 + template <typename T> 2.489 + inline Matrix33<T> operator*(Matrix33<T> const & m, int const a) 2.490 + { return Matrix33<T>(m) *= a; } 2.491 + 2.492 + template <typename T> 2.493 + inline Matrix33<T> operator*(int const a, Matrix33<T> const & m) 2.494 + { return Matrix33<T>(m) *= a; } 2.495 + 2.496 + template <typename T> 2.497 + inline Matrix33<T> operator*(Matrix33<T> const & m, float const a) 2.498 + { return Matrix33<T>(m) *= a; } 2.499 + 2.500 + template <typename T> 2.501 + inline Matrix33<T> operator*(float const a, Matrix33<T> const & m) 2.502 + { return Matrix33<T>(m) *= a; } 2.503 + 2.504 + template <typename T> 2.505 + inline Matrix33<T> operator*(Matrix33<T> const & m, double const a) 2.506 + { return Matrix33<T>(m) *= a; } 2.507 + 2.508 + template <typename T> 2.509 + inline Matrix33<T> operator*(double const a, Matrix33<T> const & m) 2.510 + { return Matrix33<T>(m) *= a; } 2.511 + 2.512 + 2.513 + 2.514 + 2.515 + ////////////////////////////////////////////////////////////////////////// 2.516 + template <typename T> 2.517 + class Matrix44 2.518 + { 2.519 + public: 2.520 + T m[16]; 2.521 + 2.522 + // Constructors 2.523 + Matrix44() {} 2.524 + explicit Matrix44(T a) 2.525 + { 2.526 + // TODO: Is this really more efficient than memset? 2.527 + m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = m[6] = m[7] = m[8] = 2.528 + m[9] = m[10] = m[11] = m[12] = m[13] = m[14] = m[15] = a; 2.529 + } 2.530 + Matrix44(T a0, T a1, T a2, T a3, 2.531 + T a4, T a5, T a6, T a7, 2.532 + T a8, T a9, T a10, T a11, 2.533 + T a12, T a13, T a14, T a15) 2.534 + { 2.535 + m[0] = a0; m[4] = a4; m[8] = a8; m[12] = a12; 2.536 + m[1] = a1; m[5] = a5; m[9] = a9; m[13] = a13; 2.537 + m[2] = a2; m[6] = a6; m[10] = a10; m[14] = a14; 2.538 + m[3] = a3; m[7] = a7; m[11] = a11; m[15] = a15; 2.539 + } 2.540 + 2.541 + // Array indexing 2.542 + // Remember: column major order is used. 2.543 + inline T& operator[](unsigned int const i) 2.544 + { assert (i<16); return m[i]; } 2.545 + inline T operator[](unsigned int const i) const 2.546 + { assert (i<16); return m[i]; } 2.547 + 2.548 + // Assignment 2.549 + inline Matrix44<T>& operator=(Matrix44<T> const & m2) 2.550 + { 2.551 + m[0] = m2[0]; m[4] = m2[4]; m[8] = m2[8]; m[12] = m2[12]; 2.552 + m[1] = m2[1]; m[5] = m2[5]; m[9] = m2[9]; m[13] = m2[13]; 2.553 + m[2] = m2[2]; m[6] = m2[6]; m[10] = m2[10]; m[14] = m2[14]; 2.554 + m[3] = m2[3]; m[7] = m2[7]; m[11] = m2[11]; m[15] = m2[15]; 2.555 + return *this; 2.556 + } 2.557 + inline Matrix44<T>& assign(T const a0, T const a1, T const a2, T const a3, 2.558 + T const a4, T const a5, T const a6, T const a7, 2.559 + T const a8, T const a9, T const a10, T const a11, 2.560 + T const a12, T const a13, T const a14, T const a15) 2.561 + { 2.562 + m[0] = a0; m[4] = a4; m[8] = a8; m[12] = a12; 2.563 + m[1] = a1; m[5] = a5; m[9] = a9; m[13] = a13; 2.564 + m[2] = a2; m[6] = a6; m[10] = a10; m[14] = a14; 2.565 + m[3] = a3; m[7] = a7; m[11] = a11; m[15] = a15; 2.566 + return *this; 2.567 + } 2.568 + 2.569 + // Comparison 2.570 + inline bool operator==(Matrix44<T> const & m2) const 2.571 + { 2.572 + // TODO: Should this use memcmp? 2.573 + return 2.574 + m[0] == m2[0] && m[4] == m2[4] && m[8] == m2[8] && m[12] == m2[12] && 2.575 + m[1] == m2[1] && m[5] == m2[5] && m[9] == m2[9] && m[13] == m2[13] && 2.576 + m[2] == m2[2] && m[6] == m2[6] && m[10] == m2[10] && m[14] == m2[14] && 2.577 + m[3] == m2[3] && m[7] == m2[7] && m[11] == m2[11] && m[15] == m2[15]; 2.578 + } 2.579 + inline bool operator!=(Matrix44<T> const & m2) const 2.580 + { return ! (*this == m2); } 2.581 + 2.582 + // Matrix addition 2.583 + inline Matrix44<T>& operator+=(Matrix44<T> const & m2) 2.584 + { 2.585 + m[0] += m2[0]; m[4] += m2[4]; m[8] += m2[8]; m[12] += m2[12]; 2.586 + m[1] += m2[1]; m[5] += m2[5]; m[9] += m2[9]; m[13] += m2[13]; 2.587 + m[2] += m2[2]; m[6] += m2[6]; m[10] += m2[10]; m[14] += m2[14]; 2.588 + m[3] += m2[3]; m[7] += m2[7]; m[11] += m2[11]; m[15] += m2[15]; 2.589 + return *this; 2.590 + } 2.591 + inline Matrix44<T> operator+(Matrix44<T> const & m2) const 2.592 + { return Matrix44<T>(*this) += m2; } 2.593 + 2.594 + // Matrix subtraction 2.595 + inline Matrix44<T>& operator-=(Matrix44<T> const & m2) 2.596 + { 2.597 + m[0] -= m2[0]; m[4] -= m2[4]; m[8] -= m2[8]; m[12] -= m2[12]; 2.598 + m[1] -= m2[1]; m[5] -= m2[5]; m[9] -= m2[9]; m[13] -= m2[13]; 2.599 + m[2] -= m2[2]; m[6] -= m2[6]; m[10] -= m2[10]; m[14] -= m2[14]; 2.600 + m[3] -= m2[3]; m[7] -= m2[7]; m[11] -= m2[11]; m[15] -= m2[15]; 2.601 + return *this; 2.602 + } 2.603 + inline Matrix44<T> operator-(Matrix44<T> const & m2) const 2.604 + { return Matrix44<T>(*this) -= m2; } 2.605 + 2.606 + // Scalar multiplication 2.607 + inline Matrix44<T>& operator*=(int const a) 2.608 + { 2.609 + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; 2.610 + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; 2.611 + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; 2.612 + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; 2.613 + return *this; 2.614 + } 2.615 + inline Matrix44<T>& operator*=(float const a) 2.616 + { 2.617 + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; 2.618 + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; 2.619 + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; 2.620 + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; 2.621 + return *this; 2.622 + } 2.623 + inline Matrix44<T>& operator*=(double const a) 2.624 + { 2.625 + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; 2.626 + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; 2.627 + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; 2.628 + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; 2.629 + return *this; 2.630 + } 2.631 + 2.632 + // Scalar division 2.633 + inline Matrix44<T>& operator/=(int const a) 2.634 + { 2.635 + assert(a!=0); 2.636 + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; 2.637 + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; 2.638 + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; 2.639 + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; 2.640 + return *this; 2.641 + } 2.642 + inline Matrix44<T>& operator/=(float const a) 2.643 + { 2.644 + assert(a!=0); 2.645 + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; 2.646 + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; 2.647 + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; 2.648 + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; 2.649 + return *this; 2.650 + } 2.651 + inline Matrix44<T>& operator/=(double const a) 2.652 + { 2.653 + assert(a!=0); 2.654 + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; 2.655 + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; 2.656 + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; 2.657 + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; 2.658 + return *this; 2.659 + } 2.660 + inline Matrix44<T> operator/(int const a) 2.661 + { return Matrix44<T>(*this) /= a; } 2.662 + inline Matrix44<T> operator/(float const a) 2.663 + { return Matrix44<T>(*this) /= a; } 2.664 + inline Matrix44<T> operator/(double const a) 2.665 + { return Matrix44<T>(*this) /= a; } 2.666 + 2.667 + // Matrix multiplication 2.668 + // Not sure if this should be inlined at all. Sure the compiler will 2.669 + // probably ignore the inline request here, but maybe it won't and maybe 2.670 + // that would be bad. Needs real testing. 2.671 + inline Matrix44<T>& operator*=(Matrix44<T> const & m2) 2.672 + { 2.673 + const int size=4; 2.674 + Matrix44<T> mres(0); 2.675 + int i, j, k; 2.676 + for (i=0; i<size; ++i) 2.677 + for (j=0; j<size; ++j) 2.678 + for (k=0; k<size; ++k) 2.679 + mres[size*i+j] += (*this)[size*k+j] * m2[size*i+k]; 2.680 + *this = mres; 2.681 + return *this; 2.682 + } 2.683 + inline Matrix44<T> operator*(Matrix44<T> const & m2) const 2.684 + { return Matrix44<T>(*this) *= m2; } 2.685 + 2.686 + 2.687 + inline Vector4<T> getcol(unsigned int const i) const 2.688 + { 2.689 + assert(i<4); 2.690 + const int size=4; 2.691 + return Vector4<T>(m[i*size], m[i*size+1], m[i*size+2], m[i*size+3]); 2.692 + } 2.693 + 2.694 + inline Vector4<T> getrow(unsigned int const i) const 2.695 + { 2.696 + assert(i<4); 2.697 + const int size=4; 2.698 + return Vector4<T>(m[i], m[i+size], m[i+2*size], m[i+3*size]); 2.699 + } 2.700 + 2.701 + inline Matrix44<T>& setcol(unsigned int const i, Vector4<T> const & v) 2.702 + { 2.703 + assert(i<4); 2.704 + const int size=4; 2.705 + m[i*size] = v[0]; 2.706 + m[i*size+1] = v[1]; 2.707 + m[i*size+2] = v[2]; 2.708 + m[i*size+3] = v[3]; 2.709 + return *this; 2.710 + } 2.711 + 2.712 + inline Matrix44<T>& setcol(unsigned int const i, 2.713 + T const a0, T const a1, T const a2, T const a3) 2.714 + { 2.715 + assert(i<4); 2.716 + const int size=4; 2.717 + m[i*size] = a0; 2.718 + m[i*size+1] = a1; 2.719 + m[i*size+2] = a2; 2.720 + m[i*size+3] = a3; 2.721 + return *this; 2.722 + } 2.723 + 2.724 + inline Matrix44<T>& setrow(unsigned int const i, Vector4<T> const & v) 2.725 + { 2.726 + assert(i<4); 2.727 + const int size=4; 2.728 + m[i] = v[0]; 2.729 + m[i+size] = v[1]; 2.730 + m[i+2*size] = v[2]; 2.731 + m[i+3*size] = v[3]; 2.732 + return *this; 2.733 + } 2.734 + 2.735 + inline Matrix44<T>& setrow(unsigned int const i, 2.736 + T const a0, T const a1, T const a2, T const a3) 2.737 + { 2.738 + assert(i<4); 2.739 + const int size=4; 2.740 + m[i] = a0; 2.741 + m[i+size] = a1; 2.742 + m[i+2*size] = a2; 2.743 + m[i+3*size] = a3; 2.744 + return *this; 2.745 + } 2.746 + 2.747 + std::string & to_string(std::string & s) const; 2.748 + 2.749 + inline Matrix44<T>& setidentity() 2.750 + { 2.751 + memset(m, 0, sizeof(m)); 2.752 + m[0] = m[5] = m[10] = m[15] = 1; 2.753 + return *this; 2.754 + } 2.755 + 2.756 + }; 2.757 + 2.758 + // Scalar multiplication continued 2.759 + template <typename T> 2.760 + inline Matrix44<T> operator*(Matrix44<T> const & m, int const a) 2.761 + { return Matrix44<T>(m) *= a; } 2.762 + 2.763 + template <typename T> 2.764 + inline Matrix44<T> operator*(int const a, Matrix44<T> const & m) 2.765 + { return Matrix44<T>(m) *= a; } 2.766 + 2.767 + template <typename T> 2.768 + inline Matrix44<T> operator*(Matrix44<T> const & m, float const a) 2.769 + { return Matrix44<T>(m) *= a; } 2.770 + 2.771 + template <typename T> 2.772 + inline Matrix44<T> operator*(float const a, Matrix44<T> const & m) 2.773 + { return Matrix44<T>(m) *= a; } 2.774 + 2.775 + template <typename T> 2.776 + inline Matrix44<T> operator*(Matrix44<T> const & m, double const a) 2.777 + { return Matrix44<T>(m) *= a; } 2.778 + 2.779 + template <typename T> 2.780 + inline Matrix44<T> operator*(double const a, Matrix44<T> const & m) 2.781 + { return Matrix44<T>(m) *= a; } 2.782 + 2.783 + 2.784 + 2.785 + 2.786 + ////////////////////////////////////////////////////////////////////////// 2.787 typedef Matrix22<int> Matrix22i; 2.788 typedef Matrix22<float> Matrix22f; 2.789 typedef Matrix22<double> Matrix22d; 2.790 2.791 -#ifdef NOTHING 2.792 typedef Matrix33<int> Matrix33i; 2.793 typedef Matrix33<float> Matrix33f; 2.794 typedef Matrix33<double> Matrix33d; 2.795 @@ -275,18 +809,23 @@ 2.796 typedef Matrix44<int> Matrix44i; 2.797 typedef Matrix44<float> Matrix44f; 2.798 typedef Matrix44<double> Matrix44d; 2.799 - 2.800 -#endif 2.801 - 2.802 2.803 2.804 ////////////////////////////////////////////////////////////////////////// 2.805 // Matrix functions 2.806 + // TODO: The determinant functions suffer from some bad round off error. 2.807 + // If it significant? I don't know. None of the other game engines 2.808 + // I've checked bother to do anything to calculate det more accurately. 2.809 + // So maybe it just doesn't matter enough for game purposes. 2.810 2.811 - template <typename T> inline double det(const Matrix22<T> m) 2.812 - { return (double) (m[0] * m[3]) - (double) (m[1] * m[2]); } 2.813 + template <typename T> 2.814 + inline double det(Matrix22<T> const & m) 2.815 + { 2.816 + return (double) (m[0] * m[3]) - (double) (m[1] * m[2]); 2.817 + } 2.818 2.819 - template <typename T> inline Matrix22<T> transpose(const Matrix22<T>& m) 2.820 + template <typename T> 2.821 + inline Matrix22<T> transpose(Matrix22<T> const & m) 2.822 { 2.823 const int size=2; 2.824 Matrix22<T> mres(0); 2.825 @@ -297,6 +836,53 @@ 2.826 return mres; 2.827 } 2.828 2.829 + template <typename T> 2.830 + inline double det(Matrix33<T> const & m) 2.831 + { 2.832 + return m[0] * ( (double) m[4] * m[8] - (double) m[5] * m[7]) 2.833 + - m[3] * ( (double) m[1] * m[8] - (double) m[2] * m[7]) 2.834 + + m[6] * ( (double) m[1] * m[5] - (double) m[2] * m[4]); 2.835 + } 2.836 + template <typename T> 2.837 + inline Matrix33<T> transpose(Matrix33<T> const & m) 2.838 + { 2.839 + const int size=3; 2.840 + Matrix33<T> mres(0); 2.841 + int i, j; 2.842 + for (i=0; i<size; ++i) 2.843 + for (j=0; j<size; j++) 2.844 + mres[size*i+j] = m[size*j+i]; 2.845 + return mres; 2.846 + } 2.847 + 2.848 + template <typename T> 2.849 + inline double det(Matrix44<T> const & m) 2.850 + { 2.851 + return m[0] * ( m[5] * (m[10] * m[15] - m[11] * m[14]) 2.852 + - m[9] * (m[6] * m[15] - m[7] * m[14]) 2.853 + + m[13] * (m[6] * m[11] - m[7] * m[10])) 2.854 + - m[4] * ( m[1] * (m[10] * m[15] - m[11] * m[14]) 2.855 + - m[9] * (m[2] * m[15] - m[3] * m[14]) 2.856 + + m[13] * (m[2] * m[11] - m[3] * m[10])) 2.857 + + m[8] * ( m[1] * (m[6] * m[15] - m[7] * m[14]) 2.858 + - m[5] * (m[2] * m[15] - m[3] * m[14]) 2.859 + + m[13] * (m[2] * m[7] - m[3] * m[6])) 2.860 + + m[12] * ( m[1] * (m[6] * m[11] - m[7] * m[10]) 2.861 + - m[5] * (m[2] * m[11] - m[3] * m[10]) 2.862 + + m[9] * (m[2] * m[7] - m[3] * m[6])); 2.863 + } 2.864 + template <typename T> 2.865 + inline Matrix44<T> transpose(Matrix44<T> const & m) 2.866 + { 2.867 + const int size=4; 2.868 + Matrix44<T> mres(0); 2.869 + int i, j; 2.870 + for (i=0; i<size; ++i) 2.871 + for (j=0; j<size; j++) 2.872 + mres[size*i+j] = m[size*j+i]; 2.873 + return mres; 2.874 + } 2.875 + 2.876 } // namespace Math 2.877 } // namespace arda 2.878 2.879 @@ -304,7 +890,8 @@ 2.880 //////////////////////////////////////////////////////////////////////////////// 2.881 // Matrix methods 2.882 2.883 -template <typename T> std::string & arda::Math::Matrix22<T>::getstring(std::string & s) const 2.884 +template <typename T> 2.885 +std::string & arda::Math::Matrix22<T>::to_string(std::string & s) const 2.886 { 2.887 s.clear(); 2.888 std::stringstream ss; 2.889 @@ -315,98 +902,32 @@ 2.890 return s; 2.891 } 2.892 2.893 - 2.894 - 2.895 - 2.896 - 2.897 - 2.898 - 2.899 - 2.900 - 2.901 - 2.902 - 2.903 - 2.904 -#ifdef NOTHING 2.905 - ////////////////////////////////////////////////////////////////////////// 2.906 - // det*(Matrix m) 2.907 - // Computer the determinant of a matrix. 2.908 - // Returns the determinant. 2.909 - 2.910 - inline double det3(Matrix3i m) 2.911 - { return m[0] * ( m[4] * m[8] 2.912 - - m[5] * m[7]) 2.913 - - m[3] * ( m[1] * m[8] 2.914 - - m[2] * m[7]) 2.915 - + m[6] * ( m[1] * m[5] 2.916 - - m[2] * m[4]); } 2.917 - 2.918 - inline double det4(Matrix4i m) 2.919 - { return m[0] * (m[5] * (m[10] * m[15] - 2.920 - m[11] * m[14]) - 2.921 - m[9] * (m[6] * m[15] - 2.922 - m[7] * m[14]) + 2.923 - m[13] * (m[6] * m[11] - 2.924 - m[7] * m[10])) - 2.925 - m[4] * (m[1] * (m[10] * m[15] - 2.926 - m[11] * m[14]) - 2.927 - m[9] * (m[2] * m[15] - 2.928 - m[3] * m[14]) + 2.929 - m[13] * (m[2] * m[11] - 2.930 - m[3] * m[10])) + 2.931 - m[8] * (m[1] * (m[6] * m[15] - 2.932 - m[7] * m[14]) - 2.933 - m[5] * (m[2] * m[15] - 2.934 - m[3] * m[14]) + 2.935 - m[13] * (m[2] * m[7] - 2.936 - m[3] * m[6])) + 2.937 - m[12] * (m[1] * (m[6] * m[11] - 2.938 - m[7] * m[10]) - 2.939 - m[5] * (m[2] * m[11] - 2.940 - m[3] * m[10]) + 2.941 - m[9] * (m[2] * m[7] - 2.942 - m[3] * m[6])); } 2.943 - 2.944 -//////////////////////////////////////////////////////////////////////////////// 2.945 -int * arda::Matrix::multvec3mv(Matrix3i m, Vector3i v, Vector3i vres) 2.946 +template <typename T> 2.947 +std::string & arda::Math::Matrix33<T>::to_string(std::string & s) const 2.948 { 2.949 - vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; 2.950 - vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; 2.951 - vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; 2.952 - return vres; 2.953 + s.clear(); 2.954 + std::stringstream ss; 2.955 + ss << "[ " 2.956 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], " 2.957 + "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], " 2.958 + "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ], ""]"; 2.959 + s = ss.str(); 2.960 + return s; 2.961 } 2.962 2.963 2.964 -//////////////////////////////////////////////////////////////////////////////// 2.965 -int * arda::Matrix::multvec4mv(Matrix4i m, Vector4i v, Vector4i vres) 2.966 +template <typename T> 2.967 +std::string & arda::Math::Matrix44<T>::to_string(std::string & s) const 2.968 { 2.969 - vres[0] = m[0]*v[0] + m[4]*v[1] + m[8] *v[2] + m[12]*v[3]; 2.970 - vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; 2.971 - vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; 2.972 - vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; 2.973 - return vres; 2.974 + s.clear(); 2.975 + std::stringstream ss; 2.976 + ss << "[ " 2.977 + "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], " 2.978 + "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], " 2.979 + "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], " 2.980 + "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ], ""]"; 2.981 + s = ss.str(); 2.982 + return s; 2.983 } 2.984 2.985 -//////////////////////////////////////////////////////////////////////////////// 2.986 -int * arda::Matrix::multvec3vm(Vector3i v, Matrix3i m, Vector3i vres) 2.987 - { 2.988 - vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; 2.989 - vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; 2.990 - vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; 2.991 - return vres; 2.992 - } 2.993 - 2.994 -//////////////////////////////////////////////////////////////////////////////// 2.995 -float * arda::Matrix::multvec4vm(Vector4f v, Matrix4f m, Vector4f vres) 2.996 - { 2.997 - vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; 2.998 - vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; 2.999 - vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; 2.1000 - vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; 2.1001 - return vres; 2.1002 - } 2.1003 -#endif 2.1004 - 2.1005 - 2.1006 - 2.1007 - 2.1008 #endif // MATRIX_H_
3.1 --- a/include/Vector.h Fri Oct 07 13:33:48 2011 -0500 3.2 +++ b/include/Vector.h Mon May 06 01:06:12 2013 -0500 3.3 @@ -51,14 +51,14 @@ 3.4 // get_anglen(Vector& v2) 3.5 // Like get_angle(), but the vectors must already be normalized. 3.6 // Not meaningful for int vectors. 3.7 - // getstring(std::string & s) 3.8 + // to_string(std::string & s) 3.9 // Returns a C string representation of the vector. 3.10 // This is one of the few non-inline Vector functions. 3.11 // length() 3.12 // Get the length of a vector. 3.13 // Returns a double for all vector types. 3.14 // normalize() 3.15 - // Normalizes the vecor. 3.16 + // Normalizes the vector. 3.17 // Not meaningful for int vectors. 3.18 // proj(Vector& v2, Vector& vres) 3.19 // Calculates the projection of the vector onto v2 and returns the result 3.20 @@ -103,192 +103,207 @@ 3.21 3.22 3.23 ///////////////////////////////////////////////////////////////////////////// 3.24 - template <typename T> class Vector2 3.25 + template <typename T> 3.26 + class Vector2 3.27 { 3.28 public: 3.29 T x, y; 3.30 3.31 // Constructors 3.32 Vector2() {} 3.33 - explicit Vector2(const T a) : x (a), y(a) {} 3.34 - Vector2(const T a, const T b) : x (a), y(b) {} 3.35 + explicit Vector2(T a) : x (a), y(a) {} 3.36 + Vector2(T a, T b) : x (a), y(b) {} 3.37 3.38 // Array indexing 3.39 - inline T& operator[](unsigned int i) 3.40 + inline T& operator[](unsigned int const i) 3.41 { assert (i<2); if (i==0) return x; return y; } 3.42 - inline T operator[](unsigned int i) const 3.43 + inline T operator[](unsigned int const i) const 3.44 { assert (i<2); if (i==0) return x; return y; } 3.45 3.46 // Assignment 3.47 - inline Vector2<T>& operator=(const Vector2<T>& v2) 3.48 + inline Vector2<T>& operator=(Vector2<T> const & v2) 3.49 { x = v2.x; y = v2.y; return *this; } 3.50 - inline Vector2<T>& assign(const T a, const T b) 3.51 + inline Vector2<T>& assign(T const a, T const b) 3.52 { x = a; y = b; return *this; } 3.53 3.54 // Comparison 3.55 - inline bool operator==(Vector2<T>& v2) const 3.56 + inline bool operator==(Vector2<T> const & v2) const 3.57 { return ((x == v2.x) && (y == v2.y)); } 3.58 - inline bool operator!=(Vector2<T>& v2) const 3.59 + inline bool operator!=(Vector2<T> const & v2) const 3.60 { return ! (*this == v2); } 3.61 3.62 // Vector addition 3.63 - inline Vector2<T>& operator+=(const Vector2<T>& v2) 3.64 + inline Vector2<T>& operator+=(Vector2<T> const & v2) 3.65 { x += v2.x; y += v2.y; return *this; } 3.66 - inline Vector2<T> operator+(const Vector2<T>& v2) const 3.67 + inline Vector2<T> operator+(Vector2<T> const & v2) const 3.68 { return Vector2<T>(*this) += v2; } 3.69 3.70 // Vector subtraction 3.71 - inline Vector2<T>& operator-=(const Vector2<T>& v2) 3.72 + inline Vector2<T>& operator-=(Vector2<T> const & v2) 3.73 { x -= v2.x; y -= v2.y; return *this; } 3.74 - inline Vector2<T> operator-(const Vector2<T>& v2) const 3.75 + inline Vector2<T> operator-(Vector2<T> const & v2) const 3.76 { return Vector2<T>(*this) -= v2; } 3.77 3.78 // Scalar multiplication 3.79 - inline Vector2<T>& operator*=(const int a) 3.80 + inline Vector2<T>& operator*=(int const a) 3.81 { x *= a; y *= a; return *this; } 3.82 - inline Vector2<T>& operator*=(const float a) 3.83 + inline Vector2<T>& operator*=(float const a) 3.84 { x *= a; y *= a; return *this; } 3.85 - inline Vector2<T>& operator*=(const double a) 3.86 + inline Vector2<T>& operator*=(double const a) 3.87 { x *= a; y *= a; return *this; } 3.88 - inline Vector2<T> operator*(const int a) 3.89 + 3.90 + inline Vector2<T> operator*(int const a) const 3.91 { return Vector2<T>(*this) *= a;} 3.92 - inline Vector2<T> operator*(const float a) 3.93 + inline Vector2<T> operator*(float const a) const 3.94 { return Vector2<T>(*this) *= a;} 3.95 - inline Vector2<T> operator*(const double a) 3.96 + inline Vector2<T> operator*(double const a) const 3.97 { return Vector2<T>(*this) *= a;} 3.98 3.99 // Scalar division 3.100 - inline Vector2<T>& operator/=(const int a) 3.101 + inline Vector2<T>& operator/=(int const a) 3.102 { assert(a!=0); x /= a; y /= a; return *this; } 3.103 - inline Vector2<T>& operator/=(const float a) 3.104 + inline Vector2<T>& operator/=(float const a) 3.105 { assert(a!=0); x /= a; y /= a; return *this; } 3.106 - inline Vector2<T>& operator/=(const double a) 3.107 + inline Vector2<T>& operator/=(double const a) 3.108 { assert(a!=0); x /= a; y /= a; return *this; } 3.109 - inline Vector2<T> operator/(const int a) 3.110 + 3.111 + inline Vector2<T> operator/(int const a) const 3.112 { return Vector2<T>(*this) /= a;} 3.113 - inline Vector2<T> operator/(const float a) 3.114 + inline Vector2<T> operator/(float const a) const 3.115 { return Vector2<T>(*this) /= a;} 3.116 - inline Vector2<T> operator/(const double a) 3.117 + inline Vector2<T> operator/(double const a) const 3.118 { return Vector2<T>(*this) /= a;} 3.119 3.120 3.121 // methods 3.122 3.123 - inline T dot(const Vector2<T>& v2) const 3.124 + inline T dot(Vector2<T> const & v2) const 3.125 { return x*v2.x + y*v2.y; } 3.126 3.127 - inline double get_angle(Vector2<T>& v2) 3.128 + inline double get_angle(Vector2<T> const & v2) 3.129 { 3.130 double tmp = dot(v2); 3.131 return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); 3.132 } 3.133 3.134 - inline double get_anglen(Vector2<T>& v2) 3.135 + inline double get_anglen(Vector2<T> const & v2) 3.136 { return acos((double) dot(v2)); } 3.137 3.138 - std::string & getstring(std::string & s) const; 3.139 + std::string & to_string(std::string & s) const; 3.140 3.141 inline double length(void) const 3.142 { return sqrt((dot(*this))); } 3.143 3.144 inline Vector2<T>& normalize() 3.145 - { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; return *this; } 3.146 + { 3.147 + double l = length(); 3.148 + if (l == 0.0) return *this; 3.149 + x /= l; y /= l; 3.150 + return *this; } 3.151 3.152 - inline Vector2<T> proj(Vector2<T>& v2) 3.153 - { Vector2<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.154 - inline Vector2<T>& proj(Vector2<T>& v2, Vector2<T>& vres) 3.155 + inline Vector2<T> proj(Vector2<T> const & v2) 3.156 + { Vector2<T> vres; vres = v2 * (dot(v2)/v2.dot(v2)); return vres; } 3.157 + inline Vector2<T>& proj(Vector2<T> const & v2, Vector2<T>& vres) 3.158 { vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.159 }; 3.160 3.161 // Scalar multiplication, continued 3.162 - template <typename T> inline Vector2<T> operator*(const int a, const Vector2<T>& v) 3.163 - { return Vector2<T>(v) *= a;} 3.164 - template <typename T> inline Vector2<T> operator*(const float a, const Vector2<T> v) 3.165 - { return Vector2<T>(v) *= a;} 3.166 - template <typename T> inline Vector2<T> operator*(const double a, const Vector2<T>& v) 3.167 + template <typename T> 3.168 + inline Vector2<T> operator*(int const a, Vector2<T> const & v) 3.169 { return Vector2<T>(v) *= a;} 3.170 3.171 + template <typename T> 3.172 + inline Vector2<T> operator*(float const a, Vector2<T> const & v) 3.173 + { return Vector2<T>(v) *= a;} 3.174 + 3.175 + template <typename T> 3.176 + inline Vector2<T> operator*(double const a, Vector2<T> const & v) 3.177 + { return Vector2<T>(v) *= a;} 3.178 + 3.179 3.180 ///////////////////////////////////////////////////////////////////////////// 3.181 - template <typename T> class Vector3 3.182 + template <typename T> 3.183 + class Vector3 3.184 { 3.185 public: 3.186 T x, y, z; 3.187 3.188 // Constructors 3.189 Vector3() {} 3.190 - explicit Vector3(const T a) : x (a), y(a), z(a) {} 3.191 - Vector3(const T a, const T b, const T c) : x (a), y(b), z(c) {} 3.192 + explicit Vector3(T a) : x (a), y(a), z(a) {} 3.193 + Vector3(T a, T b, T c) : x (a), y(b), z(c) {} 3.194 3.195 // Array indexing 3.196 - inline T& operator[](unsigned int i) 3.197 + inline T& operator[](unsigned int const i) 3.198 { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } 3.199 - inline T operator[](unsigned int i) const 3.200 + inline T operator[](unsigned int const i) const 3.201 { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } 3.202 3.203 // Assignment 3.204 - inline Vector3<T>& operator=(const Vector3<T>& v2) 3.205 + inline Vector3<T>& operator=(Vector3<T> const & v2) 3.206 { x = v2.x; y = v2.y; z = v2.z; return *this; } 3.207 - inline Vector3<T>& assign(const T a, const T b, const T c) 3.208 + inline Vector3<T>& assign(T const a, T const b, T const c) 3.209 { x = a; y = b; z = c; return *this; } 3.210 3.211 // Comparison 3.212 - inline bool operator==(Vector3<T>& v2) const 3.213 + inline bool operator==(Vector3<T> const & v2) const 3.214 { return ((x == v2.x) && (y == v2.y) && (z == v2.z)); } 3.215 - inline bool operator!=(Vector3<T>& v2) const 3.216 + inline bool operator!=(Vector3<T> const & v2) const 3.217 { return ! (*this == v2); } 3.218 3.219 // Vector addition 3.220 - inline Vector3<T>& operator+=(const Vector3<T>& v2) 3.221 + inline Vector3<T>& operator+=(Vector3<T> const & v2) 3.222 { x += v2.x; y += v2.y; z += v2.z; return *this; } 3.223 - inline Vector3<T> operator+(const Vector3<T>& v2) const 3.224 + inline Vector3<T> operator+(Vector3<T> const & v2) const 3.225 { return Vector3<T>(*this) += v2; } 3.226 3.227 // Vector subtraction 3.228 - inline Vector3<T>& operator-=(const Vector3<T>& v2) 3.229 + inline Vector3<T>& operator-=(Vector3<T> const & v2) 3.230 { x -= v2.x; y -= v2.y; z -= v2.z; return *this; } 3.231 - inline Vector3<T> operator-(const Vector3<T>& v2) const 3.232 + inline Vector3<T> operator-(Vector3<T> const & v2) const 3.233 { return Vector3<T>(*this) -= v2; } 3.234 3.235 // Scalar multiplication 3.236 - inline Vector3<T>& operator*=(const int a) 3.237 + inline Vector3<T>& operator*=(int const a) 3.238 { x *= a; y *= a; z *= a; return *this; } 3.239 - inline Vector3<T>& operator*=(const float a) 3.240 + inline Vector3<T>& operator*=(float const a) 3.241 { x *= a; y *= a; z *= a; return *this; } 3.242 - inline Vector3<T>& operator*=(const double a) 3.243 + inline Vector3<T>& operator*=(double const a) 3.244 { x *= a; y *= a; z *= a; return *this; } 3.245 - inline Vector3<T> operator*(const int a) 3.246 + 3.247 + inline Vector3<T> operator*(int const a) const 3.248 { return Vector3<T>(*this) *= a;} 3.249 - inline Vector3<T> operator*(const float a) 3.250 + inline Vector3<T> operator*(float const a) const 3.251 { return Vector3<T>(*this) *= a;} 3.252 - inline Vector3<T> operator*(const double a) 3.253 + inline Vector3<T> operator*(double const a) const 3.254 { return Vector3<T>(*this) *= a;} 3.255 3.256 // Scalar division 3.257 - inline Vector3<T>& operator/=(const int a) 3.258 + inline Vector3<T>& operator/=(int const a) 3.259 { assert(a!=0); x /= a; y /= a; z /= a; return *this; } 3.260 - inline Vector3<T>& operator/=(const float a) 3.261 + inline Vector3<T>& operator/=(float const a) 3.262 { assert(a!=0); x /= a; y /= a; z /= a; return *this; } 3.263 - inline Vector3<T>& operator/=(const double a) 3.264 + inline Vector3<T>& operator/=(double const a) 3.265 { assert(a!=0); x /= a; y /= a; z /= a; return *this; } 3.266 - inline Vector3<T> operator/(const int a) 3.267 + 3.268 + inline Vector3<T> operator/(int const a) const 3.269 { return Vector3<T>(*this) /= a;} 3.270 - inline Vector3<T> operator/(const float a) 3.271 + inline Vector3<T> operator/(float const a) const 3.272 { return Vector3<T>(*this) /= a;} 3.273 - inline Vector3<T> operator/(const double a) 3.274 + inline Vector3<T> operator/(double const a) const 3.275 { return Vector3<T>(*this) /= a;} 3.276 3.277 3.278 // methods 3.279 3.280 - inline Vector3<T>& cross(Vector3<T>& v2, Vector3<T>& vres) 3.281 + inline Vector3<T>& cross(Vector3<T> const & v2, Vector3<T>& vres) 3.282 { 3.283 vres.x = y*v2.z - v2.y*z; 3.284 vres.y = -x*v2.z + v2.x*z; 3.285 vres.z = x*v2.y - v2.x*y; 3.286 return vres; 3.287 } 3.288 - inline Vector3<T> cross(Vector3<T>& v2) 3.289 + inline Vector3<T> cross(Vector3<T> const & v2) 3.290 { 3.291 Vector3<T> vres; 3.292 vres.x = y*v2.z - v2.y*z; 3.293 @@ -297,19 +312,19 @@ 3.294 return vres; 3.295 } 3.296 3.297 - inline T dot(const Vector3<T>& v2) const 3.298 + inline T dot(Vector3<T> const & v2) const 3.299 { return x*v2.x + y*v2.y + z*v2.z; } 3.300 3.301 - inline double get_angle(Vector3<T>& v2) 3.302 + inline double get_angle(Vector3<T> const & v2) 3.303 { 3.304 double tmp = dot(v2); 3.305 return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); 3.306 } 3.307 3.308 - inline double get_anglen(Vector3<T>& v2) 3.309 + inline double get_anglen(Vector3<T> const & v2) 3.310 { return acos((double) dot(v2)); } 3.311 3.312 - std::string & getstring(std::string & s) const; 3.313 + std::string & to_string(std::string & s) const; 3.314 3.315 inline double length(void) const 3.316 { return sqrt((dot(*this))); } 3.317 @@ -317,105 +332,113 @@ 3.318 inline Vector3<T>& normalize() 3.319 { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; return *this; } 3.320 3.321 - inline Vector3<T> proj(Vector3<T>& v2) 3.322 + inline Vector3<T> proj(Vector3<T> const & v2) 3.323 { Vector3<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.324 - inline Vector3<T>& proj(Vector3<T>& v2, Vector3<T>& vres) 3.325 + inline Vector3<T>& proj(Vector3<T> const & v2, Vector3<T>& vres) 3.326 { vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.327 }; 3.328 3.329 // Scalar multiplication, continued 3.330 - template <typename T> inline Vector3<T> operator*(const int a, const Vector3<T>& v) 3.331 + template <typename T> 3.332 + inline Vector3<T> operator*(int const a, Vector3<T> const & v) 3.333 { return Vector3<T>(v) *= a;} 3.334 - template <typename T> inline Vector3<T> operator*(const float a, const Vector3<T> v) 3.335 + 3.336 + template <typename T> 3.337 + inline Vector3<T> operator*(float const a, Vector3<T> const & v) 3.338 { return Vector3<T>(v) *= a;} 3.339 - template <typename T> inline Vector3<T> operator*(const double a, const Vector3<T>& v) 3.340 + 3.341 + template <typename T> 3.342 + inline Vector3<T> operator*(double const a, Vector3<T> const & v) 3.343 { return Vector3<T>(v) *= a;} 3.344 3.345 ///////////////////////////////////////////////////////////////////////////// 3.346 - template <typename T> class Vector4 3.347 + template <typename T> 3.348 + class Vector4 3.349 { 3.350 public: 3.351 T x, y, z, w; 3.352 3.353 // Constructors 3.354 Vector4() {} 3.355 - explicit Vector4(const T a) : x (a), y(a), z(a), w(a) {} 3.356 - Vector4(const T a, const T b, const T c, const T d) : x (a), y(b), z(c), w(d) {} 3.357 + explicit Vector4(T a) : x (a), y(a), z(a), w(a) {} 3.358 + Vector4(T a, T b, T c, T d) : x (a), y(b), z(c), w(d) {} 3.359 3.360 // Array indexing 3.361 - inline T& operator[](unsigned int i) 3.362 + inline T& operator[](unsigned int const i) 3.363 { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } 3.364 - inline T operator[](unsigned int i) const 3.365 + inline T operator[](unsigned int const i) const 3.366 { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } 3.367 3.368 // Assignment 3.369 - inline Vector4<T>& operator=(const Vector4<T>& v2) 3.370 + inline Vector4<T>& operator=(Vector4<T> const & v2) 3.371 { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; } 3.372 - inline Vector4<T>& assign(const T a, const T b, const T c, const T d) 3.373 + inline Vector4<T>& assign(T const a, T const b, T const c, T const d) 3.374 { x = a; y = b; z = c; w = d; return *this; } 3.375 3.376 // Comparison 3.377 - inline bool operator==(Vector4<T>& v2) const 3.378 + inline bool operator==(Vector4<T> const & v2) const 3.379 { return ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); } 3.380 - inline bool operator!=(Vector4<T>& v2) const 3.381 + inline bool operator!=(Vector4<T> const & v2) const 3.382 { return ! (*this == v2); } 3.383 3.384 // Vector addition 3.385 - inline Vector4<T>& operator+=(const Vector4<T>& v2) 3.386 + inline Vector4<T>& operator+=(Vector4<T> const & v2) 3.387 { x += v2.x; y += v2.y; z += v2.z; w += v2.w; return *this; } 3.388 - inline Vector4<T> operator+(const Vector4<T>& v2) const 3.389 + inline Vector4<T> operator+(Vector4<T> const & v2) const 3.390 { return Vector4<T>(*this) += v2; } 3.391 3.392 // Vector subtraction 3.393 - inline Vector4<T>& operator-=(const Vector4<T>& v2) 3.394 + inline Vector4<T>& operator-=(Vector4<T> const & v2) 3.395 { x -= v2.x; y -= v2.y; z -= v2.z; w -= v2.w; return *this; } 3.396 - inline Vector4<T> operator-(const Vector4<T>& v2) const 3.397 + inline Vector4<T> operator-(Vector4<T> const & v2) const 3.398 { return Vector4<T>(*this) -= v2; } 3.399 3.400 // Scalar multiplication 3.401 - inline Vector4<T>& operator*=(const int a) 3.402 + inline Vector4<T>& operator*=(int const a) 3.403 { x *= a; y *= a; z *= a; w *= a; return *this; } 3.404 - inline Vector4<T>& operator*=(const float a) 3.405 + inline Vector4<T>& operator*=(float const a) 3.406 { x *= a; y *= a; z *= a; w *= a; return *this; } 3.407 - inline Vector4<T>& operator*=(const double a) 3.408 + inline Vector4<T>& operator*=(double const a) 3.409 { x *= a; y *= a; z *= a; w *= a; return *this; } 3.410 - inline Vector4<T> operator*(const int a) 3.411 + 3.412 + inline Vector4<T> operator*(int const a) const 3.413 { return Vector4<T>(*this) *= a;} 3.414 - inline Vector4<T> operator*(const float a) 3.415 + inline Vector4<T> operator*(float const a) const 3.416 { return Vector4<T>(*this) *= a;} 3.417 - inline Vector4<T> operator*(const double a) 3.418 + inline Vector4<T> operator*(double const a) const 3.419 { return Vector4<T>(*this) *= a;} 3.420 3.421 // Scalar division 3.422 - inline Vector4<T>& operator/=(const int a) 3.423 + inline Vector4<T>& operator/=(int const a) 3.424 { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } 3.425 - inline Vector4<T>& operator/=(const float a) 3.426 + inline Vector4<T>& operator/=(float const a) 3.427 { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } 3.428 - inline Vector4<T>& operator/=(const double a) 3.429 + inline Vector4<T>& operator/=(double const a) 3.430 { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } 3.431 - inline Vector4<T> operator/(const int a) 3.432 + 3.433 + inline Vector4<T> operator/(int const a) const 3.434 { return Vector4<T>(*this) /= a;} 3.435 - inline Vector4<T> operator/(const float a) 3.436 + inline Vector4<T> operator/(float const a) const 3.437 { return Vector4<T>(*this) /= a;} 3.438 - inline Vector4<T> operator/(const double a) 3.439 + inline Vector4<T> operator/(double const a) const 3.440 { return Vector4<T>(*this) /= a;} 3.441 3.442 3.443 // methods 3.444 3.445 - inline T dot(const Vector4<T>& v2) const 3.446 + inline T dot(Vector4<T> const & v2) const 3.447 { return x*v2.x + y*v2.y + z*v2.z + w*v2.w; } 3.448 3.449 - inline double get_angle(Vector4<T>& v2) 3.450 + inline double get_angle(Vector4<T> const & v2) 3.451 { 3.452 double tmp = dot(v2); 3.453 return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); 3.454 } 3.455 3.456 - inline double get_anglen(Vector4<T>& v2) 3.457 + inline double get_anglen(Vector4<T> const & v2) 3.458 { return acos((double) dot(v2)); } 3.459 3.460 - std::string & getstring(std::string & s) const; 3.461 + std::string & to_string(std::string & s) const; 3.462 3.463 inline double length(void) const 3.464 { return sqrt((dot(*this))); } 3.465 @@ -423,18 +446,23 @@ 3.466 inline Vector4<T>& normalize() 3.467 { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; w /= l; return *this; } 3.468 3.469 - inline Vector4<T> proj(Vector4<T>& v2) 3.470 + inline Vector4<T> proj(Vector4<T> const & v2) 3.471 { Vector4<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.472 - inline Vector4<T>& proj(Vector4<T>& v2, Vector4<T>& vres) 3.473 + inline Vector4<T>& proj(Vector4<T> const & v2, Vector4<T>& vres) 3.474 { vres = v2 * dot(v2)/v2.dot(v2); return vres; } 3.475 }; 3.476 3.477 // Scalar multiplication, continued 3.478 - template <typename T> inline Vector4<T> operator*(const int a, const Vector4<T>& v) 3.479 + template <typename T> 3.480 + inline Vector4<T> operator*(int const a, Vector4<T> const & v) 3.481 { return Vector4<T>(v) *= a;} 3.482 - template <typename T> inline Vector4<T> operator*(const float a, const Vector4<T> v) 3.483 + 3.484 + template <typename T> 3.485 + inline Vector4<T> operator*(float const a, Vector4<T> const & v) 3.486 { return Vector4<T>(v) *= a;} 3.487 - template <typename T> inline Vector4<T> operator*(const double a, const Vector4<T>& v) 3.488 + 3.489 + template <typename T> 3.490 + inline Vector4<T> operator*(double const a, Vector4<T> const & v) 3.491 { return Vector4<T>(v) *= a;} 3.492 3.493 ///////////////////////////////////////////////////////////////////////////// 3.494 @@ -456,7 +484,8 @@ 3.495 } // namespace arda 3.496 3.497 //////////////////////////////////////////////////////////////////////////////// 3.498 -template <typename T> std::string & arda::Math::Vector2<T>::getstring(std::string & s) const 3.499 +template <typename T> 3.500 +std::string & arda::Math::Vector2<T>::to_string(std::string & s) const 3.501 { 3.502 s.clear(); 3.503 std::stringstream ss; 3.504 @@ -466,7 +495,8 @@ 3.505 } 3.506 3.507 //////////////////////////////////////////////////////////////////////////////// 3.508 -template <typename T> std::string & arda::Math::Vector3<T>::getstring(std::string & s) const 3.509 +template <typename T> 3.510 +std::string & arda::Math::Vector3<T>::to_string(std::string & s) const 3.511 { 3.512 s.clear(); 3.513 std::stringstream ss; 3.514 @@ -476,7 +506,8 @@ 3.515 } 3.516 3.517 //////////////////////////////////////////////////////////////////////////////// 3.518 -template <typename T> std::string & arda::Math::Vector4<T>::getstring(std::string & s) const 3.519 +template <typename T> 3.520 +std::string & arda::Math::Vector4<T>::to_string(std::string & s) const 3.521 { 3.522 s.clear(); 3.523 std::stringstream ss;
4.1 --- a/src/main.cpp Fri Oct 07 13:33:48 2011 -0500 4.2 +++ b/src/main.cpp Mon May 06 01:06:12 2013 -0500 4.3 @@ -21,30 +21,30 @@ 4.4 Vector2i v2i_3(1, 2); 4.5 Vector2i v2i_4(v2i_3); 4.6 4.7 - cout << setw(40) << "v2i_1: " << v2i_1.getstring(s1) << endl; 4.8 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.9 - cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl; 4.10 - cout << setw(40) << "v2i_4: " << v2i_4.getstring(s1) << endl; 4.11 + cout << setw(40) << "v2i_1: " << v2i_1.to_string(s1) << endl; 4.12 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.13 + cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; 4.14 + cout << setw(40) << "v2i_4: " << v2i_4.to_string(s1) << endl; 4.15 4.16 Vector3f v3f_1(0); 4.17 Vector3f v3f_2(1); 4.18 Vector3f v3f_3(1, 2, 3); 4.19 Vector3f v3f_4(v3f_3); 4.20 4.21 - cout << setw(40) << "v3f_1: " << v3f_1.getstring(s1) << endl; 4.22 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.23 - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; 4.24 - cout << setw(40) << "v3f_4: " << v3f_4.getstring(s1) << endl; 4.25 + cout << setw(40) << "v3f_1: " << v3f_1.to_string(s1) << endl; 4.26 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.27 + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 4.28 + cout << setw(40) << "v3f_4: " << v3f_4.to_string(s1) << endl; 4.29 4.30 Vector4d v4d_1(0); 4.31 Vector4d v4d_2(1); 4.32 Vector4d v4d_3(1, 2, 3, 4); 4.33 Vector4d v4d_4(v4d_3); 4.34 4.35 - cout << setw(40) << "v4d_1: " << v4d_1.getstring(s1) << endl; 4.36 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.37 - cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl; 4.38 - cout << setw(40) << "v4d_4: " << v4d_4.getstring(s1) << endl; 4.39 + cout << setw(40) << "v4d_1: " << v4d_1.to_string(s1) << endl; 4.40 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.41 + cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; 4.42 + cout << setw(40) << "v4d_4: " << v4d_4.to_string(s1) << endl; 4.43 } 4.44 4.45 { 4.46 @@ -70,28 +70,28 @@ 4.47 Vector4d v4d_2(0); 4.48 4.49 cout << "Before assignment" << endl; 4.50 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.51 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.52 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.53 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.54 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.55 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.56 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.57 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.58 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.59 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.60 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.61 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.62 4.63 v2i_2 = v2i; 4.64 v3f_2 = v3f; 4.65 v4d_2 = v4d; 4.66 cout << "After assignment by =" << endl; 4.67 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.68 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.69 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.70 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.71 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.72 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.73 4.74 v2i_2.assign(1, 1); 4.75 v3f_2.assign(2.2, 2.2, 2.2); 4.76 v4d_2.assign(3.3, 3.3, 3.3, 3.3); 4.77 cout << "After assignment by assign()" << endl; 4.78 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.79 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.80 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.81 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.82 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.83 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.84 } 4.85 4.86 { 4.87 @@ -107,15 +107,15 @@ 4.88 Vector3f v3f_3(0); 4.89 Vector4d v4d_3(0); 4.90 4.91 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.92 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.93 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.94 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.95 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.96 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.97 - cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl; 4.98 - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; 4.99 - cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl; 4.100 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.101 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.102 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.103 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.104 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.105 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.106 + cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; 4.107 + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 4.108 + cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; 4.109 cout << boolalpha; 4.110 cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl; 4.111 cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl; 4.112 @@ -144,24 +144,24 @@ 4.113 Vector3f v3f_3(0); 4.114 Vector4d v4d_3(0); 4.115 4.116 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.117 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.118 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.119 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.120 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.121 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.122 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.123 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.124 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.125 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.126 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.127 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.128 v2i_3 = v2i + v2i_2; 4.129 v3f_3 = v3f + v3f_2; 4.130 v4d_3 = v4d + v4d_2; 4.131 - cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.getstring(s1) << endl; 4.132 - cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.getstring(s1) << endl; 4.133 - cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.getstring(s1) << endl; 4.134 + cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string(s1) << endl; 4.135 + cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string(s1) << endl; 4.136 + cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string(s1) << endl; 4.137 v2i_3 += v2i_2; 4.138 v3f_3 += v3f_2; 4.139 v4d_3 += v4d_3; 4.140 - cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.getstring(s1) << endl; 4.141 - cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.getstring(s1) << endl; 4.142 - cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.getstring(s1) << endl; 4.143 + cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string(s1) << endl; 4.144 + cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string(s1) << endl; 4.145 + cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string(s1) << endl; 4.146 } 4.147 4.148 { 4.149 @@ -177,24 +177,24 @@ 4.150 Vector3f v3f_3(0); 4.151 Vector4d v4d_3(0); 4.152 4.153 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.154 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.155 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.156 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.157 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.158 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.159 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.160 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.161 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.162 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.163 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.164 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.165 v2i_3 = v2i - v2i_2; 4.166 v3f_3 = v3f - v3f_2; 4.167 v4d_3 = v4d - v4d_2; 4.168 - cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.getstring(s1) << endl; 4.169 - cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.getstring(s1) << endl; 4.170 - cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.getstring(s1) << endl; 4.171 + cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string(s1) << endl; 4.172 + cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string(s1) << endl; 4.173 + cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string(s1) << endl; 4.174 v2i_3 -= v2i_2; 4.175 v3f_3 -= v3f_2; 4.176 v4d_3 -= v4d_3; 4.177 - cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.getstring(s1) << endl; 4.178 - cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.getstring(s1) << endl; 4.179 - cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.getstring(s1) << endl; 4.180 + cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string(s1) << endl; 4.181 + cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string(s1) << endl; 4.182 + cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string(s1) << endl; 4.183 } 4.184 4.185 { 4.186 @@ -213,24 +213,24 @@ 4.187 cout << setw(40) << "i: " << i << endl; 4.188 cout << setw(40) << "f: " << f << endl; 4.189 cout << setw(40) << "d: " << d << endl; 4.190 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.191 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.192 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.193 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.194 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.195 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.196 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.197 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.198 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.199 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.200 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.201 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.202 v2i_2 = v2i * i; 4.203 v3f_2 = v3f * f; 4.204 v4d_2 = v4d * d; 4.205 - cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.getstring(s1) << endl; 4.206 - cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.getstring(s1) << endl; 4.207 - cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.getstring(s1) << endl; 4.208 + cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string(s1) << endl; 4.209 + cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string(s1) << endl; 4.210 + cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string(s1) << endl; 4.211 v2i_2 *= i; 4.212 v3f_2 *= f; 4.213 v4d_2 *= d; 4.214 - cout << setw(40) << "v2i_2 *= i: " << v2i_2.getstring(s1) << endl; 4.215 - cout << setw(40) << "v3f_2 *= f: " << v3f_2.getstring(s1) << endl; 4.216 - cout << setw(40) << "v4d_2 *= d: " << v4d_2.getstring(s1) << endl; 4.217 + cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string(s1) << endl; 4.218 + cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string(s1) << endl; 4.219 + cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string(s1) << endl; 4.220 } 4.221 4.222 { 4.223 @@ -246,24 +246,24 @@ 4.224 float f = 2.f; 4.225 double d = 2.0; 4.226 4.227 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.228 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.229 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.230 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.231 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.232 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.233 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.234 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.235 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.236 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.237 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.238 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.239 v2i_2 = v2i / i; 4.240 v3f_2 = v3f / f; 4.241 v4d_2 = v4d / d; 4.242 - cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.getstring(s1) << endl; 4.243 - cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.getstring(s1) << endl; 4.244 - cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.getstring(s1) << endl; 4.245 + cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string(s1) << endl; 4.246 + cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string(s1) << endl; 4.247 + cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string(s1) << endl; 4.248 v2i_2 /= i; 4.249 v3f_2 /= f; 4.250 v4d_2 /= d; 4.251 - cout << setw(40) << "v2i_2 /= i: " << v2i_2.getstring(s1) << endl; 4.252 - cout << setw(40) << "v3f_2 /= f: " << v3f_2.getstring(s1) << endl; 4.253 - cout << setw(40) << "v4d_2 /= d: " << v4d_2.getstring(s1) << endl; 4.254 + cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string(s1) << endl; 4.255 + cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string(s1) << endl; 4.256 + cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string(s1) << endl; 4.257 } 4.258 4.259 { 4.260 @@ -273,16 +273,16 @@ 4.261 Vector3f v3f_2(4.4, 5.5, 6.6); 4.262 Vector3f v3f_3(0); 4.263 Vector3f v3f_4(0); 4.264 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.265 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.266 - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; 4.267 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.268 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.269 + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; 4.270 v3f.cross(v3f_2, v3f_3); 4.271 - cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; 4.272 + cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; 4.273 v3f_4 = 2.0 * v3f.cross(v3f_2); 4.274 - cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.getstring(s1) << endl; 4.275 + cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string(s1) << endl; 4.276 v3f_4.assign(0,0,0); 4.277 v3f.cross(v3f_2, v3f_4); 4.278 - cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.getstring(s1) << endl; 4.279 + cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string(s1) << endl; 4.280 } 4.281 4.282 { 4.283 @@ -297,12 +297,12 @@ 4.284 int i; 4.285 float f; 4.286 double d; 4.287 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.288 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.289 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.290 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.291 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.292 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.293 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.294 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.295 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.296 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.297 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.298 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.299 i = v2i.dot(v2i_2); 4.300 cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl; 4.301 f = v3f.dot(v3f_2); 4.302 @@ -317,9 +317,9 @@ 4.303 Vector2i v2i(1, 2); 4.304 Vector3f v3f(1.1f, 2.2f, 3.3f); 4.305 Vector4d v4d(1.1, 2.2, 3.3, 4.4); 4.306 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.307 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.308 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.309 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.310 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.311 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.312 cout << setw(40) << "v2i.length(): " << v2i.length() << endl; 4.313 cout << setw(40) << "v3f.length(): " << v3f.length() << endl; 4.314 cout << setw(40) << "v4d.length(): " << v4d.length() << endl; 4.315 @@ -331,15 +331,15 @@ 4.316 Vector2f v2f(1.1, 2.2); 4.317 Vector3f v3f(1.1f, 2.2f, 3.3f); 4.318 Vector4d v4d(1.1, 2.2, 3.3, 4.4); 4.319 - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; 4.320 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.321 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.322 + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 4.323 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.324 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.325 v2f.normalize(); 4.326 - cout << setw(40) << "v2f.normalize() " << v2f.getstring(s1) << endl; 4.327 + cout << setw(40) << "v2f.normalize() " << v2f.to_string(s1) << endl; 4.328 v3f.normalize(); 4.329 - cout << setw(40) << "v3f.normalize() " << v3f.getstring(s1) << endl; 4.330 + cout << setw(40) << "v3f.normalize() " << v3f.to_string(s1) << endl; 4.331 v4d.normalize(); 4.332 - cout << setw(40) << "v4d.normalize() " << v4d.getstring(s1) << endl; 4.333 + cout << setw(40) << "v4d.normalize() " << v4d.to_string(s1) << endl; 4.334 cout << setw(40) << "v2f.length(): " << v2f.length() << endl; 4.335 cout << setw(40) << "v3f.length(): " << v3f.length() << endl; 4.336 cout << setw(40) << "v4d.length(): " << v4d.length() << endl; 4.337 @@ -355,12 +355,12 @@ 4.338 Vector4d v4d(1.1, 2.2, 3.3, 4.4); 4.339 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 4.340 double d; 4.341 - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; 4.342 - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; 4.343 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.344 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.345 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.346 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.347 + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; 4.348 + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; 4.349 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.350 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.351 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.352 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.353 d = v2i.get_angle(v2i_2); 4.354 cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl; 4.355 d = v3f.get_angle(v3f_2); 4.356 @@ -385,12 +385,12 @@ 4.357 v3f_2.normalize(); 4.358 v4d.normalize(); 4.359 v4d_2.normalize(); 4.360 - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; 4.361 - cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; 4.362 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.363 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.364 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.365 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.366 + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 4.367 + cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; 4.368 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.369 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.370 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.371 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.372 d = v2f.get_anglen(v2f_2); 4.373 cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl; 4.374 d = v3f.get_anglen(v3f_2); 4.375 @@ -411,27 +411,27 @@ 4.376 Vector4d v4d(1.1, 2.2, 3.3, 4.4); 4.377 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); 4.378 Vector4d v4d_3(0); 4.379 - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; 4.380 - cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; 4.381 - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; 4.382 - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; 4.383 - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; 4.384 - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; 4.385 + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; 4.386 + cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; 4.387 + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; 4.388 + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; 4.389 + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; 4.390 + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; 4.391 v2f_3 = v2f.proj(v2f_2); 4.392 - cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.getstring(s1) << endl; 4.393 + cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string(s1) << endl; 4.394 v3f_3 = v3f.proj(v3f_2); 4.395 - cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.getstring(s1) << endl; 4.396 + cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string(s1) << endl; 4.397 v4d_3 = v4d.proj(v4d_2); 4.398 - cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.getstring(s1) << endl; 4.399 + cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string(s1) << endl; 4.400 v2f_3.assign(0,0); 4.401 v3f_3.assign(0,0,0); 4.402 v4d_3.assign(0,0,0,0); 4.403 v2f.proj(v2f_2, v2f_3); 4.404 - cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.getstring(s1) << endl; 4.405 + cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string(s1) << endl; 4.406 v3f.proj(v3f_2, v3f_3); 4.407 - cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; 4.408 + cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; 4.409 v4d.proj(v4d_2, v4d_3); 4.410 - cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.getstring(s1) << endl; 4.411 + cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string(s1) << endl; 4.412 } 4.413 4.414 } 4.415 @@ -449,10 +449,31 @@ 4.416 Matrix22i m22i_3(1, 2, 3, 4); 4.417 Matrix22i m22i_4(m22i_3); 4.418 4.419 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.420 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.421 - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; 4.422 - cout << setw(40) << "m22i_4: " << m22i_4.getstring(s1) << endl; 4.423 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.424 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.425 + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 4.426 + cout << setw(40) << "m22i_4: " << m22i_4.to_string(s1) << endl; 4.427 + 4.428 + Matrix33f m33f_1(0.0f); 4.429 + Matrix33f m33f_2(1.1f); 4.430 + Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.431 + Matrix33f m33f_4(m33f_3); 4.432 + 4.433 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.434 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.435 + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 4.436 + cout << setw(40) << "m33f_4: " << m33f_4.to_string(s1) << endl; 4.437 + 4.438 + Matrix44d m44d_1(0.0); 4.439 + Matrix44d m44d_2(1.1); 4.440 + Matrix44d m44d_3(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.441 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.442 + Matrix44d m44d_4(m44d_3); 4.443 + 4.444 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.445 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.446 + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 4.447 + cout << setw(40) << "m44d_4: " << m44d_4.to_string(s1) << endl; 4.448 } 4.449 4.450 { 4.451 @@ -461,25 +482,65 @@ 4.452 Matrix22i m22i(1, 2, 3, 4); 4.453 4.454 cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl; 4.455 + 4.456 + Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.457 + 4.458 + cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl; 4.459 + 4.460 + Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.461 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.462 + 4.463 + cout << setw(40) << "m44d: " << m44d[0] << " " << m44d[1] << " " << m44d[2] << " " << m44d[3] << " " << m44d[4] << " " << m44d[5] << " " << m44d[6] << " " << m44d[7] << " " << m44d[8] << " " << m44d[9] << " " << m44d[10] << " " << m44d[11] << " " << m44d[12] << " " << m44d[13] << " " << m44d[14] << " " << m44d[15] << endl; 4.464 } 4.465 4.466 { 4.467 cout << "===============================================================" << endl << 4.468 - "Testing Maxtrix array assignment" << endl; 4.469 + "Testing Maxtrix assignment" << endl; 4.470 Matrix22i m22i_1(1, 2, 3, 4); 4.471 Matrix22i m22i_2(5, 6, 7, 8); 4.472 4.473 - cout << "Before assignment" << endl; 4.474 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.475 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.476 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.477 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.478 4.479 m22i_2 = m22i_1; 4.480 - cout << "After assignment by = " << endl; 4.481 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.482 + cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string(s1) << endl; 4.483 4.484 m22i_2.assign(9, 10, 11, 12); 4.485 - cout << "After assignment by assign" << endl; 4.486 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.487 + cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): " 4.488 + << m22i_2.to_string(s1) << endl; 4.489 + 4.490 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.491 + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 4.492 + 4.493 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.494 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.495 + 4.496 + m33f_2 = m33f_1; 4.497 + cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string(s1) << endl; 4.498 + 4.499 + m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f); 4.500 + cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): " 4.501 + << m33f_2.to_string(s1) << endl; 4.502 + 4.503 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.504 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.505 + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 4.506 + 20.20, 21.21, 22.22, 23.23, 4.507 + 24.24, 25.25, 26.26, 27.27, 4.508 + 28.28, 29.29, 30.30, 31.31); 4.509 + 4.510 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.511 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.512 + 4.513 + m44d_2 = m44d_1; 4.514 + cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string(s1) << endl; 4.515 + 4.516 + m44d_2.assign(32.32, 33.33, 34.34, 35.35, 4.517 + 36.36, 37.37, 38.38, 39.39, 4.518 + 40.40, 41.41, 42.42, 43.43, 4.519 + 44.44, 45.45, 46.46, 47.47); 4.520 + cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): " 4.521 + << m44d_2.to_string(s1) << endl; 4.522 } 4.523 4.524 { 4.525 @@ -489,14 +550,42 @@ 4.526 Matrix22i m22i_2(1, 2, 3, 4); 4.527 Matrix22i m22i_3(0); 4.528 4.529 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.530 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.531 - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; 4.532 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.533 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.534 + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 4.535 cout << boolalpha; 4.536 cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl; 4.537 cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl; 4.538 cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl; 4.539 cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl; 4.540 + 4.541 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.542 + Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.543 + Matrix33f m33f_3(0.0f); 4.544 + 4.545 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.546 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.547 + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 4.548 + cout << boolalpha; 4.549 + cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl; 4.550 + cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl; 4.551 + cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl; 4.552 + cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl; 4.553 + 4.554 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.555 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.556 + Matrix44d m44d_2(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.557 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.558 + Matrix44d m44d_3(0.0); 4.559 + 4.560 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.561 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.562 + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 4.563 + cout << boolalpha; 4.564 + cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl; 4.565 + cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl; 4.566 + cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl; 4.567 + cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl; 4.568 } 4.569 4.570 { 4.571 @@ -506,14 +595,44 @@ 4.572 Matrix22i m22i_2(5, 6, 7, 8); 4.573 Matrix22i m22i_3(0); 4.574 4.575 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.576 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.577 - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; 4.578 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.579 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.580 + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 4.581 m22i_3 = m22i_1 + m22i_2; 4.582 - cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.getstring(s1) << endl; 4.583 + cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string(s1) << endl; 4.584 4.585 m22i_3 += m22i_1; 4.586 - cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.getstring(s1) << endl; 4.587 + cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string(s1) << endl; 4.588 + 4.589 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.590 + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 4.591 + Matrix33f m33f_3(0.0f); 4.592 + 4.593 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.594 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.595 + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 4.596 + m33f_3 = m33f_1 + m33f_2; 4.597 + cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string(s1) << endl; 4.598 + 4.599 + m33f_3 += m33f_1; 4.600 + cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string(s1) << endl; 4.601 + 4.602 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.603 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.604 + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 4.605 + 20.20, 21.21, 22.22, 23.23, 4.606 + 24.24, 25.25, 26.26, 27.27, 4.607 + 28.28, 29.29, 30.30, 31.31); 4.608 + Matrix44d m44d_3(0.0); 4.609 + 4.610 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.611 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.612 + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 4.613 + m44d_3 = m44d_1 + m44d_2; 4.614 + cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string(s1) << endl; 4.615 + 4.616 + m44d_3 += m44d_1; 4.617 + cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string(s1) << endl; 4.618 } 4.619 4.620 { 4.621 @@ -523,14 +642,44 @@ 4.622 Matrix22i m22i_2(5, 6, 7, 8); 4.623 Matrix22i m22i_3(0); 4.624 4.625 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.626 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.627 - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; 4.628 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.629 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.630 + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 4.631 m22i_3 = m22i_1 - m22i_2; 4.632 - cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.getstring(s1) << endl; 4.633 + cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string(s1) << endl; 4.634 4.635 m22i_3 -= m22i_1; 4.636 - cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.getstring(s1) << endl; 4.637 + cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string(s1) << endl; 4.638 + 4.639 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.640 + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 4.641 + Matrix33f m33f_3(0.0f); 4.642 + 4.643 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.644 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.645 + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 4.646 + m33f_3 = m33f_1 - m33f_2; 4.647 + cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string(s1) << endl; 4.648 + 4.649 + m33f_3 -= m33f_1; 4.650 + cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string(s1) << endl; 4.651 + 4.652 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.653 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.654 + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 4.655 + 20.20, 21.21, 22.22, 23.23, 4.656 + 24.24, 25.25, 26.26, 27.27, 4.657 + 28.28, 29.29, 30.30, 31.31); 4.658 + Matrix44d m44d_3(0.0); 4.659 + 4.660 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.661 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.662 + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 4.663 + m44d_3 = m44d_1 - m44d_2; 4.664 + cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string(s1) << endl; 4.665 + 4.666 + m44d_3 -= m44d_1; 4.667 + cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string(s1) << endl; 4.668 } 4.669 4.670 { 4.671 @@ -541,14 +690,43 @@ 4.672 int i = 2; 4.673 4.674 cout << setw(40) << "i: " << i << endl; 4.675 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.676 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.677 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.678 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.679 m22i_2 = m22i_1 *i; 4.680 - cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.getstring(s1) << endl; 4.681 + cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string(s1) << endl; 4.682 m22i_2 = i * m22i_1; 4.683 - cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.getstring(s1) << endl; 4.684 + cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string(s1) << endl; 4.685 m22i_2 *= i; 4.686 - cout << setw(40) << "m22i_2 *= i: " << m22i_2.getstring(s1) << endl; 4.687 + cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string(s1) << endl; 4.688 + 4.689 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.690 + Matrix33f m33f_2(0.0f); 4.691 + float f = 2.0f; 4.692 + 4.693 + cout << setw(40) << "f: " << f << endl; 4.694 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.695 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.696 + m33f_2 = m33f_1 * f; 4.697 + cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string(s1) << endl; 4.698 + m33f_2 = f * m33f_1; 4.699 + cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string(s1) << endl; 4.700 + m33f_2 *= f; 4.701 + cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string(s1) << endl; 4.702 + 4.703 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.704 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.705 + Matrix44d m44d_2(0.0); 4.706 + double d = 2.0f; 4.707 + 4.708 + cout << setw(40) << "d: " << d << endl; 4.709 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.710 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.711 + m44d_2 = m44d_1 * d; 4.712 + cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string(s1) << endl; 4.713 + m44d_2 = d * m44d_1; 4.714 + cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string(s1) << endl; 4.715 + m44d_2 *= d; 4.716 + cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string(s1) << endl; 4.717 } 4.718 4.719 { 4.720 @@ -559,12 +737,37 @@ 4.721 int i = 2; 4.722 4.723 cout << setw(40) << "i: " << i << endl; 4.724 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.725 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.726 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.727 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.728 m22i_2 = m22i_1 / i; 4.729 - cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.getstring(s1) << endl; 4.730 + cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string(s1) << endl; 4.731 m22i_1 /= i; 4.732 - cout << setw(40) << "m22i_1 /= i: " << m22i_2.getstring(s1) << endl; 4.733 + cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string(s1) << endl; 4.734 + 4.735 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.736 + Matrix33f m33f_2(0.0f); 4.737 + float f = 2.0f; 4.738 + 4.739 + cout << setw(40) << "f: " << f << endl; 4.740 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.741 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.742 + m33f_2 = m33f_1 / f; 4.743 + cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string(s1) << endl; 4.744 + m33f_1 /= f; 4.745 + cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string(s1) << endl; 4.746 + 4.747 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.748 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.749 + Matrix44d m44d_2(0.0); 4.750 + double d = 2.0f; 4.751 + 4.752 + cout << setw(40) << "d: " << d << endl; 4.753 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.754 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.755 + m44d_2 = m44d_1 / d; 4.756 + cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string(s1) << endl; 4.757 + m44d_1 /= d; 4.758 + cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string(s1) << endl; 4.759 } 4.760 4.761 { 4.762 @@ -574,11 +777,35 @@ 4.763 Matrix22i m22i_2(5, 6, 7, 8); 4.764 Matrix22i m22i_3(0); 4.765 4.766 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.767 - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; 4.768 - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; 4.769 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.770 + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; 4.771 + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; 4.772 m22i_3 = m22i_1 * m22i_2; 4.773 - cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.getstring(s1) << endl; 4.774 + cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string(s1) << endl; 4.775 + 4.776 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.777 + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); 4.778 + Matrix33f m33f_3(0.0f); 4.779 + 4.780 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.781 + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; 4.782 + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; 4.783 + m33f_3 = m33f_1 * m33f_2; 4.784 + cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string(s1) << endl; 4.785 + 4.786 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.787 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.788 + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, 4.789 + 20.20, 21.21, 22.22, 23.23, 4.790 + 24.24, 25.25, 26.26, 27.27, 4.791 + 28.28, 29.29, 30.30, 31.31); 4.792 + Matrix44d m44d_3(0.0); 4.793 + 4.794 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.795 + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; 4.796 + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; 4.797 + m44d_3 = m44d_1 * m44d_2; 4.798 + cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string(s1) << endl; 4.799 } 4.800 4.801 { 4.802 @@ -587,9 +814,25 @@ 4.803 Matrix22i m22i_1(1, 2, 3, 4); 4.804 double d; 4.805 4.806 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.807 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.808 d = det(m22i_1); 4.809 cout << setw(40) << "d = det(m22i_1): " << d << endl; 4.810 + 4.811 + // Note: singular matrix. The real determinant is exactly zero. 4.812 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.813 + 4.814 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.815 + d = det(m33f_1); 4.816 + cout << setw(40) << "d = det(m33f_1): " << d << endl; 4.817 + 4.818 + // Note: singular matrix. The real determinant is exactly zero. 4.819 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.820 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.821 + 4.822 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.823 + d = det(m44d_1); 4.824 + cout << setw(40) << "d = det(m44d_1): " << d << endl; 4.825 + 4.826 } 4.827 4.828 { 4.829 @@ -598,9 +841,24 @@ 4.830 Matrix22i m22i_1(1, 2, 3, 4); 4.831 Matrix22i m22i_2; 4.832 4.833 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.834 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.835 m22i_2 = transpose(m22i_1); 4.836 - cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.getstring(s1) << endl; 4.837 + cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string(s1) << endl; 4.838 + 4.839 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.840 + Matrix33f m33f_2(0.0f); 4.841 + 4.842 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.843 + m33f_2 = transpose(m33f_1); 4.844 + cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string(s1) << endl; 4.845 + 4.846 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.847 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.848 + Matrix44d m44d_2(0.0); 4.849 + 4.850 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.851 + m44d_2 = transpose(m44d_1); 4.852 + cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string(s1) << endl; 4.853 } 4.854 4.855 { 4.856 @@ -608,9 +866,22 @@ 4.857 "Testing Maxtrix setidentity" << endl; 4.858 Matrix22i m22i_1(1, 2, 3, 4); 4.859 4.860 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.861 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.862 m22i_1.setidentity(); 4.863 - cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.getstring(s1) << endl; 4.864 + cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string(s1) << endl; 4.865 + 4.866 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.867 + 4.868 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.869 + m33f_1.setidentity(); 4.870 + cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string(s1) << endl; 4.871 + 4.872 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.873 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.874 + 4.875 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.876 + m44d_1.setidentity(); 4.877 + cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string(s1) << endl; 4.878 } 4.879 4.880 { 4.881 @@ -619,15 +890,55 @@ 4.882 Matrix22i m22i_1(1, 2, 3, 4); 4.883 Vector2i v2i_1(0); 4.884 4.885 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.886 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.887 v2i_1 = m22i_1.getrow(0); 4.888 - cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.getstring(s1) << endl; 4.889 + cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string(s1) << endl; 4.890 v2i_1 = m22i_1.getrow(1); 4.891 - cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.getstring(s1) << endl; 4.892 + cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string(s1) << endl; 4.893 v2i_1 = m22i_1.getcol(0); 4.894 - cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.getstring(s1) << endl; 4.895 + cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string(s1) << endl; 4.896 v2i_1 = m22i_1.getcol(1); 4.897 - cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.getstring(s1) << endl; 4.898 + cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string(s1) << endl; 4.899 + 4.900 + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); 4.901 + Vector3f v3f_1(0); 4.902 + 4.903 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.904 + v3f_1 = m33f_1.getrow(0); 4.905 + cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string(s1) << endl; 4.906 + v3f_1 = m33f_1.getrow(1); 4.907 + cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string(s1) << endl; 4.908 + v3f_1 = m33f_1.getrow(2); 4.909 + cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string(s1) << endl; 4.910 + v3f_1 = m33f_1.getcol(0); 4.911 + cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string(s1) << endl; 4.912 + v3f_1 = m33f_1.getcol(1); 4.913 + cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string(s1) << endl; 4.914 + v3f_1 = m33f_1.getcol(2); 4.915 + cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string(s1) << endl; 4.916 + 4.917 + Matrix44d m44d_1(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 4.918 + 12.12, 13.13, 14.14, 15.15, 16.16); 4.919 + Vector4d v4d_1(0); 4.920 + 4.921 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.922 + v4d_1 = m44d_1.getrow(0); 4.923 + cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string(s1) << endl; 4.924 + v4d_1 = m44d_1.getrow(1); 4.925 + cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string(s1) << endl; 4.926 + v4d_1 = m44d_1.getrow(2); 4.927 + cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string(s1) << endl; 4.928 + v4d_1 = m44d_1.getrow(3); 4.929 + cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string(s1) << endl; 4.930 + 4.931 + v4d_1 = m44d_1.getcol(0); 4.932 + cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string(s1) << endl; 4.933 + v4d_1 = m44d_1.getcol(1); 4.934 + cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string(s1) << endl; 4.935 + v4d_1 = m44d_1.getcol(2); 4.936 + cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string(s1) << endl; 4.937 + v4d_1 = m44d_1.getcol(3); 4.938 + cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string(s1) << endl; 4.939 } 4.940 4.941 { 4.942 @@ -637,29 +948,89 @@ 4.943 Vector2i v2i_1(2, 3); 4.944 4.945 m22i_1.setidentity(); 4.946 - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; 4.947 + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; 4.948 m22i_1.setrow(0, v2i_1); 4.949 - cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.getstring(s1) << endl; 4.950 + cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string(s1) << endl; 4.951 4.952 m22i_1.setidentity(); 4.953 m22i_1.setrow(1, v2i_1); 4.954 - cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.getstring(s1) << endl; 4.955 + cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string(s1) << endl; 4.956 4.957 m22i_1.setidentity(); 4.958 m22i_1.setrow(1, 4, 5); 4.959 - cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.getstring(s1) << endl; 4.960 + cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string(s1) << endl; 4.961 4.962 m22i_1.setidentity(); 4.963 m22i_1.setcol(0, v2i_1); 4.964 - cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.getstring(s1) << endl; 4.965 + cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string(s1) << endl; 4.966 4.967 m22i_1.setidentity(); 4.968 m22i_1.setcol(1, v2i_1); 4.969 - cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.getstring(s1) << endl; 4.970 + cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string(s1) << endl; 4.971 4.972 m22i_1.setidentity(); 4.973 m22i_1.setcol(1, 4, 5); 4.974 - cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.getstring(s1) << endl; 4.975 + cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string(s1) << endl; 4.976 + 4.977 + Matrix33f m33f_1; 4.978 + Vector3f v3f_1(0); 4.979 + 4.980 + m33f_1.setidentity(); 4.981 + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; 4.982 + m33f_1.setrow(0, v3f_1); 4.983 + cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string(s1) << endl; 4.984 + 4.985 + m33f_1.setidentity(); 4.986 + m33f_1.setrow(1, v3f_1); 4.987 + cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string(s1) << endl; 4.988 + 4.989 + m33f_1.setidentity(); 4.990 + m33f_1.setrow(1, 2.2f, 3.3f, 4.4f); 4.991 + cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): " 4.992 + << m33f_1.to_string(s1) << endl; 4.993 + 4.994 + m33f_1.setidentity(); 4.995 + m33f_1.setcol(0, v3f_1); 4.996 + cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string(s1) << endl; 4.997 + 4.998 + m33f_1.setidentity(); 4.999 + m33f_1.setcol(1, v3f_1); 4.1000 + cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string(s1) << endl; 4.1001 + 4.1002 + m33f_1.setidentity(); 4.1003 + m33f_1.setcol(1, 2.2f, 3.3f, 4.4f); 4.1004 + cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: " 4.1005 + << m33f_1.to_string(s1) << endl; 4.1006 + 4.1007 + Matrix44d m44d_1; 4.1008 + Vector4d v4d_1(0); 4.1009 + 4.1010 + m44d_1.setidentity(); 4.1011 + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; 4.1012 + m44d_1.setrow(0, v4d_1); 4.1013 + cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string(s1) << endl; 4.1014 + 4.1015 + m44d_1.setidentity(); 4.1016 + m44d_1.setrow(1, v4d_1); 4.1017 + cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string(s1) << endl; 4.1018 + 4.1019 + m44d_1.setidentity(); 4.1020 + m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5); 4.1021 + cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): " 4.1022 + << m44d_1.to_string(s1) << endl; 4.1023 + 4.1024 + m44d_1.setidentity(); 4.1025 + m44d_1.setcol(0, v4d_1); 4.1026 + cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string(s1) << endl; 4.1027 + 4.1028 + m44d_1.setidentity(); 4.1029 + m44d_1.setcol(1, v4d_1); 4.1030 + cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string(s1) << endl; 4.1031 + 4.1032 + m44d_1.setidentity(); 4.1033 + m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5); 4.1034 + cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: " 4.1035 + << m44d_1.to_string(s1) << endl; 4.1036 } 4.1037 } 4.1038 4.1039 @@ -687,6 +1058,9 @@ 4.1040 { 4.1041 int retval = 0; 4.1042 4.1043 + test_all(); 4.1044 + return 0; 4.1045 + 4.1046 try 4.1047 { 4.1048 int choice = -1;