# HG changeset patch # User Eris Caffee # Date 1367820372 18000 # Node ID 1d2b25d4517f41471458a2c4e449d851ddd13b29 # Parent 398894c52b697ee927fe6be88f33f4b5150da1e4 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. diff -r 398894c52b69 -r 1d2b25d4517f include/Math.h --- a/include/Math.h Fri Oct 07 13:33:48 2011 -0500 +++ b/include/Math.h Mon May 06 01:06:12 2013 -0500 @@ -4,29 +4,30 @@ #include "Vector.h" #include "Matrix.h" +/////////////////////////////////////////////////////////////////////////////////// +// Notes for improvement +// +// The angle related constants (PI, 2PI, etc) and functions (deg_to_rad, rad_to_deg) +// could be made faster by using #define's. In fact, this would turn them into +// compile time operations. But it would also put them, effectively, in the +// global namespace. Do I want that? For now I'm leaving things as const +// variables and inline functions. I can profile things later to see if changes +// are really needed. + namespace arda { //////////////////////////////////////////////////////////////////////////////// - // General notes: - // - // As much as possible is defined inline for performance. - // Using typedef'ed arrays for vectors and matrices necessitates a lot of - // redundant function names: scale2, scale3, scale4, for example. - // This is, however, perfectly in line with the implementation of OpenGL and - // allows the library to maintain optimal memory usage and performance. (I hope!) - // In any event, I think I could do far worse than to emulate the OpenGL - // working group - a group of people who have studied this for years and are - // experts in the field. - - //////////////////////////////////////////////////////////////////////////////// // Angles namespace Math { // This many decimals is enough to cover even IEEE quad precision (128 bit) // reals. Run on PA-RISC lately? :) - const double PI = 3.14159265358979323846264338327950288; + long double const PI = 3.14159265358979323846264338327950288; + long double const TWO_PI = 6.28318530717958647692528676655900577; + long double const PI_DIV_180 = 0.01745329251994329576923690768488613; + long double const INV_PI_DIV_180 = 57.29577951308232087679815481410517033; ////////////////////////////////////////////////////////////////////////// // Mixed Vector / Matrix operations. @@ -35,8 +36,10 @@ // operators are not part of the class. They are defined independently. // - // Vector * Matrix - template inline Vector2& operator*=(Vector2& v, const Matrix22& m) + // Vector2 * Matrix22 + template + inline Vector2& operator*=(Vector2 & v, + Matrix22 const & m) { Vector2 vres(0); vres[0] = v[0]*m[0] + v[1]*m[1]; @@ -44,12 +47,16 @@ v = vres; return v; } - template inline Vector2 operator*(const Vector2& v, const Matrix22& m) + + template + inline Vector2 operator*(Vector2 const & v, + Matrix22 const & m) { return Vector2(v) *= m; } - // Matrix * Vector // Note: can't define Matrix *= Vector since the result is a Vector. - template inline Vector2 operator*(const Matrix22& m, const Vector2& v) + template + inline Vector2 operator*(Matrix22 const & m, + Vector2 const & v) { Vector2 vres(0); vres[0] = m[0]*v[0] + m[2]*v[1]; @@ -57,8 +64,110 @@ return vres; } + //////////////////////////////////////// + // Vector3 * Matrix33 + template + inline Vector3& operator*=(Vector3 & v, + Matrix33 const & m) + { + Vector3 vres(0); + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; + vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; + vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; + v = vres; + return v; + } + + template + inline Vector3 operator*(Vector3 const & v, + Matrix33 const & m) + { return Vector3(v) *= m; } + + // Matrix * Vector + // Note: can't define Matrix *= Vector since the result is a Vector. + template + inline Vector3 operator*(Matrix33 const & m, + Vector3 const & v) + { + Vector3 vres(0); + vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; + vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; + vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; + return vres; + } + + //////////////////////////////////////// + // Vector4 * Matrix44 + template + inline Vector4& operator*=(Vector4 & v, + Matrix44 const & m) + { + Vector4 vres(0); + vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; + vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; + vres[8] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; + vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; + v = vres; + return v; + } + + template + inline Vector4 operator*(Vector4 const & v, + Matrix44 const & m) + { return Vector4(v) *= m; } + + // Matrix * Vector + // Note: can't define Matrix *= Vector since the result is a Vector. + template + inline Vector4 operator*(Matrix44 const & m, + Vector4 const & v) + { + Vector4 vres(0); + vres[0] = m[0]*v[0] + m[4]*v[1] + m[8]*v[2] + m[12]*v[3]; + vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; + vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; + vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; + return vres; + } + + ////////////////////////////////////////////////////////////////////////// + + template + void get_rot_mat33(Matrix33 & m, float rot, Vector3 v); + + + ////////////////////////////////////////////////////////////////////////// + + inline double deg_to_rad(double deg) { return deg * PI_DIV_180; }; + inline double rad_to_deg(double rad) { return rad * INV_PI_DIV_180; }; + } // namespace Math } // namespace arda +//////////////////////////////////////////////////////////////////////////////// +template +void arda::Math::get_rot_mat33(arda::Math::Matrix33 & m, float theta, arda::Math::Vector3 v) + { + m.setidentity(); + if (0.0 == v.length()) + return; + + // TODO: I should also immediately return identity if theta is a multiple of 2*PI but I'm not + // yet sure how I should I check for that (taking into account floating point imprecision). + + + v.normalize(); + + float c = cos(theta); + float s = sin(theta); + float one_minus_c = 1.0f - c; + + m.assign( + 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 , + 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 , + 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 + ); + } + #endif diff -r 398894c52b69 -r 1d2b25d4517f include/Matrix.h --- a/include/Matrix.h Fri Oct 07 13:33:48 2011 -0500 +++ b/include/Matrix.h Mon May 06 01:06:12 2013 -0500 @@ -33,7 +33,7 @@ // // assign() Assign the value of one matrix to another. // getcol() Returns the vector that is column n of the matrix. - // getstring() Returns a printable string representation of the matrix. + // to_string() Returns a printable string representation of the matrix. // setcol() Set the vector that is column n of the matrix. // Overloaded so that you can set from a vector or from // specific values. @@ -50,7 +50,8 @@ // transpose() Returns the transpose of a matrix. ////////////////////////////////////////////////////////////////////////// - template class Matrix22 + template + class Matrix22 { public: T m[4]; @@ -66,19 +67,20 @@ // Array indexing // Remember: column major order is used. - inline T& operator[](unsigned int i) + inline T& operator[](unsigned int const i) { assert (i<4); return m[i]; } - inline T operator[](unsigned int i) const + inline T operator[](unsigned int const i) const { assert (i<4); return m[i]; } // Assignment - inline Matrix22& operator=(const Matrix22& m2) + inline Matrix22& operator=(Matrix22 const & m2) { m[0] = m2[0]; m[2] = m2[2]; m[1] = m2[1]; m[3] = m2[3]; return *this; } - inline Matrix22& assign(T a0, T a1, T a2, T a3) + inline Matrix22& assign(T const a0, T const a1, + T const a2, T const a3) { m[0] = a0; m[2] = a2; m[1] = a1; m[3] = a3; @@ -86,49 +88,49 @@ } // Comparison - inline bool operator==(Matrix22& m2) const + inline bool operator==(Matrix22 const & m2) const { return m[0] == m2[0] && m[2] == m2[2] && m[1] == m2[1] && m[3] == m2[3]; } - inline bool operator!=(Matrix22& m2) const + inline bool operator!=(Matrix22 const & m2) const { return ! (*this == m2); } // Matrix addition - inline Matrix22& operator+=(const Matrix22& m2) + inline Matrix22& operator+=(Matrix22 const & m2) { m[0] += m2[0]; m[2] += m2[2]; m[1] += m2[1]; m[3] += m2[3]; return *this; } - inline Matrix22 operator+(const Matrix22& m2) const + inline Matrix22 operator+(Matrix22 const & m2) const { return Matrix22(*this) += m2; } // Matrix subtraction - inline Matrix22& operator-=(const Matrix22& m2) + inline Matrix22& operator-=(Matrix22 const & m2) { m[0] -= m2[0]; m[2] -= m2[2]; m[1] -= m2[1]; m[3] -= m2[3]; return *this; } - inline Matrix22 operator-(const Matrix22& m2) const + inline Matrix22 operator-(Matrix22 const & m2) const { return Matrix22(*this) -= m2; } // Scalar multiplication - inline Matrix22& operator*=(const int a) + inline Matrix22& operator*=(int const a) { m[0] *= a; m[2] *= a; m[1] *= a; m[3] *= a; return *this; } - inline Matrix22& operator*=(const float a) + inline Matrix22& operator*=(float const a) { m[0] *= a; m[2] *= a; m[1] *= a; m[3] *= a; return *this; } - inline Matrix22& operator*=(const double a) + inline Matrix22& operator*=(double const a) { m[0] *= a; m[2] *= a; m[1] *= a; m[3] *= a; @@ -136,39 +138,39 @@ } // Scalar division - inline Matrix22& operator/=(const int a) + inline Matrix22& operator/=(int const a) { assert(a!=0); m[0] /= a; m[2] /= a; m[1] /= a; m[3] /= a; return *this; } - inline Matrix22& operator/=(const float a) + inline Matrix22& operator/=(float const a) { assert(a!=0); m[0] /= a; m[2] /= a; m[1] /= a; m[3] /= a; return *this; } - inline Matrix22& operator/=(const double a) + inline Matrix22& operator/=(double const a) { assert(a!=0); m[0] /= a; m[2] /= a; m[1] /= a; m[3] /= a; return *this; } - inline Matrix22 operator/(const int a) + inline Matrix22 operator/(int const a) { return Matrix22(*this) /= a; } - inline Matrix22 operator/(const float a) + inline Matrix22 operator/(float const a) { return Matrix22(*this) /= a; } - inline Matrix22 operator/(const double a) + inline Matrix22 operator/(double const a) { return Matrix22(*this) /= a; } // Matrix multiplication // Not sure if this should be inlined at all. Sure the compiler will // probably ignore the inline request here, but maybe it won't and maybe // that would be bad. Needs real testing. - inline Matrix22& operator*=(Matrix22 m2) + inline Matrix22& operator*=(Matrix22 const & m2) { const int size=2; Matrix22 mres(0); @@ -180,34 +182,34 @@ *this = mres; return *this; } - inline Matrix22 operator*(Matrix22 m2) const + inline Matrix22 operator*(Matrix22 const & m2) const { return Matrix22(*this) *= m2; } - inline Vector2 getcol(const unsigned int i) const + inline Vector2 getcol(unsigned int const i) const { assert(i<2); - const int size=2; + int const size=2; return Vector2(m[i*size], m[i*size+1]); } - inline Vector2 getrow(const unsigned int i) const + inline Vector2 getrow(unsigned int const i) const { assert(i<2); - const int size=2; + int const size=2; return Vector2(m[i], m[i+size]); } - inline Matrix22& setcol(const unsigned int i, const Vector2& v) + inline Matrix22& setcol(unsigned int const i, Vector2 const & v) { assert(i<2); - const int size=2; + int const size=2; m[i*size] = v[0]; m[i*size+1] = v[1]; return *this; } - inline Matrix22& setcol(const unsigned int i, const T a, const T b) + inline Matrix22& setcol(unsigned int const i, T const a, T const b) { assert(i<2); const int size=2; @@ -216,25 +218,25 @@ return *this; } - inline Matrix22& setrow(const unsigned int i, const Vector2& v) + inline Matrix22& setrow(unsigned int const i, Vector2 const & v) { assert(i<2); - const int size=2; + int const size=2; m[i] = v[0]; m[i+size] = v[1]; return *this; } - inline Matrix22& setrow(const unsigned int i, const T a, const T b) + inline Matrix22& setrow(unsigned int const i, T const a, T const b) { assert(i<2); - const int size=2; + int const size=2; m[i] = a; m[i+size] = b; return *this; } - std::string & getstring(std::string & s) const; + std::string & to_string(std::string & s) const; inline Matrix22& setidentity() { @@ -246,28 +248,560 @@ }; // Scalar multiplication continued - template inline Matrix22 operator*(const Matrix22& m, const int a) + template + inline Matrix22 operator*(Matrix22 const & m, int const a) { return Matrix22(m) *= a; } - template inline Matrix22 operator*(const int a, const Matrix22& m) + + template + inline Matrix22 operator*(int const a, Matrix22 const & m) { return Matrix22(m) *= a; } - template inline Matrix22 operator*(const Matrix22& m, const float a) + + template + inline Matrix22 operator*(Matrix22 const & m, float const a) { return Matrix22(m) *= a; } - template inline Matrix22 operator*(const float a, const Matrix22& m) + + template + inline Matrix22 operator*(float const a, Matrix22 const & m) { return Matrix22(m) *= a; } - template inline Matrix22 operator*(const Matrix22& m, const double a) + + template + inline Matrix22 operator*(Matrix22 const & m, double const a) { return Matrix22(m) *= a; } - template inline Matrix22 operator*(const double a, const Matrix22& m) + + template + inline Matrix22 operator*(double const a, Matrix22 const & m) { return Matrix22(m) *= a; } ////////////////////////////////////////////////////////////////////////// + template + class Matrix33 + { + public: + T m[9]; + + // Constructors + Matrix33() {} + explicit Matrix33(T a) + { + // TODO: Is this really more efficient than memset? + m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = m[6] = m[7] = m[8] = a; + } + Matrix33(T a0, T a1, T a2, + T a3, T a4, T a5, + T a6, T a7, T a8) + { + m[0] = a0; m[3] = a3; m[6] = a6; + m[1] = a1; m[4] = a4; m[7] = a7; + m[2] = a2; m[5] = a5; m[8] = a8; + } + + // Array indexing + // Remember: column major order is used. + inline T& operator[](unsigned int const i) + { assert (i<9); return m[i]; } + inline T operator[](unsigned int const i) const + { assert (i<9); return m[i]; } + + // Assignment + inline Matrix33& operator=(Matrix33 const & m2) + { + m[0] = m2[0]; m[3] = m2[3]; m[6] = m2[6]; + m[1] = m2[1]; m[4] = m2[4]; m[7] = m2[7]; + m[2] = m2[2]; m[5] = m2[5]; m[8] = m2[8]; + return *this; + } + inline Matrix33& assign(T const a0, T const a1, T const a2, + T const a3, T const a4, T const a5, + T const a6, T const a7, T const a8) + { + m[0] = a0; m[3] = a3; m[6] = a6; + m[1] = a1; m[4] = a4; m[7] = a7; + m[2] = a2; m[5] = a5; m[8] = a8; + return *this; + } + + // Comparison + inline bool operator==(Matrix33 const & m2) const + { + return + m[0] == m2[0] && m[3] == m2[3] && m[6] == m2[6] && + m[1] == m2[1] && m[4] == m2[4] && m[7] == m2[7] && + m[2] == m2[2] && m[5] == m2[5] && m[8] == m2[8]; + } + inline bool operator!=(Matrix33 const & m2) const + { return ! (*this == m2); } + + // Matrix addition + inline Matrix33& operator+=(Matrix33 const & m2) + { + m[0] += m2[0]; m[3] += m2[3]; m[6] += m2[6]; + m[1] += m2[1]; m[4] += m2[4]; m[7] += m2[7]; + m[2] += m2[2]; m[5] += m2[5]; m[8] += m2[8]; + return *this; + } + inline Matrix33 operator+(Matrix33 const & m2) const + { return Matrix33(*this) += m2; } + + // Matrix subtraction + inline Matrix33& operator-=(Matrix33 const & m2) + { + m[0] -= m2[0]; m[3] -= m2[3]; m[6] -= m2[6]; + m[1] -= m2[1]; m[4] -= m2[4]; m[7] -= m2[7]; + m[2] -= m2[2]; m[5] -= m2[5]; m[8] -= m2[8]; + return *this; + } + inline Matrix33 operator-(Matrix33 const & m2) const + { return Matrix33(*this) -= m2; } + + // Scalar multiplication + inline Matrix33& operator*=(int const a) + { + m[0] *= a; m[3] *= a; m[6] *= a; + m[1] *= a; m[4] *= a; m[7] *= a; + m[2] *= a; m[5] *= a; m[8] *= a; + return *this; + } + inline Matrix33& operator*=(float const a) + { + m[0] *= a; m[3] *= a; m[6] *= a; + m[1] *= a; m[4] *= a; m[7] *= a; + m[2] *= a; m[5] *= a; m[8] *= a; + return *this; + } + inline Matrix33& operator*=(double const a) + { + m[0] *= a; m[3] *= a; m[6] *= a; + m[1] *= a; m[4] *= a; m[7] *= a; + m[2] *= a; m[5] *= a; m[8] *= a; + return *this; + } + + // Scalar division + inline Matrix33& operator/=(int const a) + { + assert(a!=0); + m[0] /= a; m[3] /= a; m[6] /= a; + m[1] /= a; m[4] /= a; m[7] /= a; + m[2] /= a; m[5] /= a; m[8] /= a; + return *this; + } + inline Matrix33& operator/=(float const a) + { + assert(a!=0); + m[0] /= a; m[3] /= a; m[6] /= a; + m[1] /= a; m[4] /= a; m[7] /= a; + m[2] /= a; m[5] /= a; m[8] /= a; + return *this; + } + inline Matrix33& operator/=(double const a) + { + assert(a!=0); + m[0] /= a; m[3] /= a; m[6] /= a; + m[1] /= a; m[4] /= a; m[7] /= a; + m[2] /= a; m[5] /= a; m[8] /= a; + return *this; + } + inline Matrix33 operator/(int const a) + { return Matrix33(*this) /= a; } + inline Matrix33 operator/(float const a) + { return Matrix33(*this) /= a; } + inline Matrix33 operator/(double const a) + { return Matrix33(*this) /= a; } + + // Matrix multiplication + // Not sure if this should be inlined at all. Sure the compiler will + // probably ignore the inline request here, but maybe it won't and maybe + // that would be bad. Needs real testing. + inline Matrix33& operator*=(Matrix33 const & m2) + { + const int size=3; + Matrix33 mres(0); + int i, j, k; + for (i=0; i operator*(Matrix33 const & m2) const + { return Matrix33(*this) *= m2; } + + + inline Vector3 getcol(unsigned int const i) const + { + assert(i<3); + const int size=3; + return Vector3(m[i*size], m[i*size+1], m[i*size+2]); + } + + inline Vector3 getrow(unsigned int const i) const + { + assert(i<3); + const int size=3; + return Vector3(m[i], m[i+size], m[i+2*size]); + } + + inline Matrix33& setcol(unsigned int const i, Vector3 const & v) + { + assert(i<3); + const int size=3; + m[i*size] = v[0]; + m[i*size+1] = v[1]; + m[i*size+2] = v[2]; + return *this; + } + + inline Matrix33& setcol(unsigned int const i, + T const a0, T const a1, T const a2) + { + assert(i<3); + const int size=3; + m[i*size] = a0; + m[i*size+1] = a1; + m[i*size+2] = a2; + return *this; + } + + inline Matrix33& setrow(unsigned int const i, Vector3 const & v) + { + assert(i<3); + const int size=3; + m[i] = v[0]; + m[i+size] = v[1]; + m[i+2*size] = v[2]; + return *this; + } + + inline Matrix33& setrow(unsigned int const i, + T const a0, T const a1, T const a2) + { + assert(i<3); + const int size=3; + m[i] = a0; + m[i+size] = a1; + m[i+2*size] = a2; + return *this; + } + + std::string & to_string(std::string & s) const; + + inline Matrix33& setidentity() + { + memset(m, 0, sizeof(m)); + m[0] = m[4] = m[8] = 1; + return *this; + } + + }; + + // Scalar multiplication continued + template + inline Matrix33 operator*(Matrix33 const & m, int const a) + { return Matrix33(m) *= a; } + + template + inline Matrix33 operator*(int const a, Matrix33 const & m) + { return Matrix33(m) *= a; } + + template + inline Matrix33 operator*(Matrix33 const & m, float const a) + { return Matrix33(m) *= a; } + + template + inline Matrix33 operator*(float const a, Matrix33 const & m) + { return Matrix33(m) *= a; } + + template + inline Matrix33 operator*(Matrix33 const & m, double const a) + { return Matrix33(m) *= a; } + + template + inline Matrix33 operator*(double const a, Matrix33 const & m) + { return Matrix33(m) *= a; } + + + + + ////////////////////////////////////////////////////////////////////////// + template + class Matrix44 + { + public: + T m[16]; + + // Constructors + Matrix44() {} + explicit Matrix44(T a) + { + // TODO: Is this really more efficient than memset? + m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = m[6] = m[7] = m[8] = + m[9] = m[10] = m[11] = m[12] = m[13] = m[14] = m[15] = a; + } + Matrix44(T a0, T a1, T a2, T a3, + T a4, T a5, T a6, T a7, + T a8, T a9, T a10, T a11, + T a12, T a13, T a14, T a15) + { + m[0] = a0; m[4] = a4; m[8] = a8; m[12] = a12; + m[1] = a1; m[5] = a5; m[9] = a9; m[13] = a13; + m[2] = a2; m[6] = a6; m[10] = a10; m[14] = a14; + m[3] = a3; m[7] = a7; m[11] = a11; m[15] = a15; + } + + // Array indexing + // Remember: column major order is used. + inline T& operator[](unsigned int const i) + { assert (i<16); return m[i]; } + inline T operator[](unsigned int const i) const + { assert (i<16); return m[i]; } + + // Assignment + inline Matrix44& operator=(Matrix44 const & m2) + { + m[0] = m2[0]; m[4] = m2[4]; m[8] = m2[8]; m[12] = m2[12]; + m[1] = m2[1]; m[5] = m2[5]; m[9] = m2[9]; m[13] = m2[13]; + m[2] = m2[2]; m[6] = m2[6]; m[10] = m2[10]; m[14] = m2[14]; + m[3] = m2[3]; m[7] = m2[7]; m[11] = m2[11]; m[15] = m2[15]; + return *this; + } + inline Matrix44& assign(T const a0, T const a1, T const a2, T const a3, + T const a4, T const a5, T const a6, T const a7, + T const a8, T const a9, T const a10, T const a11, + T const a12, T const a13, T const a14, T const a15) + { + m[0] = a0; m[4] = a4; m[8] = a8; m[12] = a12; + m[1] = a1; m[5] = a5; m[9] = a9; m[13] = a13; + m[2] = a2; m[6] = a6; m[10] = a10; m[14] = a14; + m[3] = a3; m[7] = a7; m[11] = a11; m[15] = a15; + return *this; + } + + // Comparison + inline bool operator==(Matrix44 const & m2) const + { + // TODO: Should this use memcmp? + return + m[0] == m2[0] && m[4] == m2[4] && m[8] == m2[8] && m[12] == m2[12] && + m[1] == m2[1] && m[5] == m2[5] && m[9] == m2[9] && m[13] == m2[13] && + m[2] == m2[2] && m[6] == m2[6] && m[10] == m2[10] && m[14] == m2[14] && + m[3] == m2[3] && m[7] == m2[7] && m[11] == m2[11] && m[15] == m2[15]; + } + inline bool operator!=(Matrix44 const & m2) const + { return ! (*this == m2); } + + // Matrix addition + inline Matrix44& operator+=(Matrix44 const & m2) + { + m[0] += m2[0]; m[4] += m2[4]; m[8] += m2[8]; m[12] += m2[12]; + m[1] += m2[1]; m[5] += m2[5]; m[9] += m2[9]; m[13] += m2[13]; + m[2] += m2[2]; m[6] += m2[6]; m[10] += m2[10]; m[14] += m2[14]; + m[3] += m2[3]; m[7] += m2[7]; m[11] += m2[11]; m[15] += m2[15]; + return *this; + } + inline Matrix44 operator+(Matrix44 const & m2) const + { return Matrix44(*this) += m2; } + + // Matrix subtraction + inline Matrix44& operator-=(Matrix44 const & m2) + { + m[0] -= m2[0]; m[4] -= m2[4]; m[8] -= m2[8]; m[12] -= m2[12]; + m[1] -= m2[1]; m[5] -= m2[5]; m[9] -= m2[9]; m[13] -= m2[13]; + m[2] -= m2[2]; m[6] -= m2[6]; m[10] -= m2[10]; m[14] -= m2[14]; + m[3] -= m2[3]; m[7] -= m2[7]; m[11] -= m2[11]; m[15] -= m2[15]; + return *this; + } + inline Matrix44 operator-(Matrix44 const & m2) const + { return Matrix44(*this) -= m2; } + + // Scalar multiplication + inline Matrix44& operator*=(int const a) + { + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; + return *this; + } + inline Matrix44& operator*=(float const a) + { + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; + return *this; + } + inline Matrix44& operator*=(double const a) + { + m[0] *= a; m[4] *= a; m[8] *= a; m[12] *= a; + m[1] *= a; m[5] *= a; m[9] *= a; m[13] *= a; + m[2] *= a; m[6] *= a; m[10] *= a; m[14] *= a; + m[3] *= a; m[7] *= a; m[11] *= a; m[15] *= a; + return *this; + } + + // Scalar division + inline Matrix44& operator/=(int const a) + { + assert(a!=0); + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; + return *this; + } + inline Matrix44& operator/=(float const a) + { + assert(a!=0); + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; + return *this; + } + inline Matrix44& operator/=(double const a) + { + assert(a!=0); + m[0] /= a; m[4] /= a; m[8] /= a; m[12] /= a; + m[1] /= a; m[5] /= a; m[9] /= a; m[13] /= a; + m[2] /= a; m[6] /= a; m[10] /= a; m[14] /= a; + m[3] /= a; m[7] /= a; m[11] /= a; m[15] /= a; + return *this; + } + inline Matrix44 operator/(int const a) + { return Matrix44(*this) /= a; } + inline Matrix44 operator/(float const a) + { return Matrix44(*this) /= a; } + inline Matrix44 operator/(double const a) + { return Matrix44(*this) /= a; } + + // Matrix multiplication + // Not sure if this should be inlined at all. Sure the compiler will + // probably ignore the inline request here, but maybe it won't and maybe + // that would be bad. Needs real testing. + inline Matrix44& operator*=(Matrix44 const & m2) + { + const int size=4; + Matrix44 mres(0); + int i, j, k; + for (i=0; i operator*(Matrix44 const & m2) const + { return Matrix44(*this) *= m2; } + + + inline Vector4 getcol(unsigned int const i) const + { + assert(i<4); + const int size=4; + return Vector4(m[i*size], m[i*size+1], m[i*size+2], m[i*size+3]); + } + + inline Vector4 getrow(unsigned int const i) const + { + assert(i<4); + const int size=4; + return Vector4(m[i], m[i+size], m[i+2*size], m[i+3*size]); + } + + inline Matrix44& setcol(unsigned int const i, Vector4 const & v) + { + assert(i<4); + const int size=4; + m[i*size] = v[0]; + m[i*size+1] = v[1]; + m[i*size+2] = v[2]; + m[i*size+3] = v[3]; + return *this; + } + + inline Matrix44& setcol(unsigned int const i, + T const a0, T const a1, T const a2, T const a3) + { + assert(i<4); + const int size=4; + m[i*size] = a0; + m[i*size+1] = a1; + m[i*size+2] = a2; + m[i*size+3] = a3; + return *this; + } + + inline Matrix44& setrow(unsigned int const i, Vector4 const & v) + { + assert(i<4); + const int size=4; + m[i] = v[0]; + m[i+size] = v[1]; + m[i+2*size] = v[2]; + m[i+3*size] = v[3]; + return *this; + } + + inline Matrix44& setrow(unsigned int const i, + T const a0, T const a1, T const a2, T const a3) + { + assert(i<4); + const int size=4; + m[i] = a0; + m[i+size] = a1; + m[i+2*size] = a2; + m[i+3*size] = a3; + return *this; + } + + std::string & to_string(std::string & s) const; + + inline Matrix44& setidentity() + { + memset(m, 0, sizeof(m)); + m[0] = m[5] = m[10] = m[15] = 1; + return *this; + } + + }; + + // Scalar multiplication continued + template + inline Matrix44 operator*(Matrix44 const & m, int const a) + { return Matrix44(m) *= a; } + + template + inline Matrix44 operator*(int const a, Matrix44 const & m) + { return Matrix44(m) *= a; } + + template + inline Matrix44 operator*(Matrix44 const & m, float const a) + { return Matrix44(m) *= a; } + + template + inline Matrix44 operator*(float const a, Matrix44 const & m) + { return Matrix44(m) *= a; } + + template + inline Matrix44 operator*(Matrix44 const & m, double const a) + { return Matrix44(m) *= a; } + + template + inline Matrix44 operator*(double const a, Matrix44 const & m) + { return Matrix44(m) *= a; } + + + + + ////////////////////////////////////////////////////////////////////////// typedef Matrix22 Matrix22i; typedef Matrix22 Matrix22f; typedef Matrix22 Matrix22d; -#ifdef NOTHING typedef Matrix33 Matrix33i; typedef Matrix33 Matrix33f; typedef Matrix33 Matrix33d; @@ -275,18 +809,23 @@ typedef Matrix44 Matrix44i; typedef Matrix44 Matrix44f; typedef Matrix44 Matrix44d; - -#endif - ////////////////////////////////////////////////////////////////////////// // Matrix functions + // TODO: The determinant functions suffer from some bad round off error. + // If it significant? I don't know. None of the other game engines + // I've checked bother to do anything to calculate det more accurately. + // So maybe it just doesn't matter enough for game purposes. - template inline double det(const Matrix22 m) - { return (double) (m[0] * m[3]) - (double) (m[1] * m[2]); } + template + inline double det(Matrix22 const & m) + { + return (double) (m[0] * m[3]) - (double) (m[1] * m[2]); + } - template inline Matrix22 transpose(const Matrix22& m) + template + inline Matrix22 transpose(Matrix22 const & m) { const int size=2; Matrix22 mres(0); @@ -297,6 +836,53 @@ return mres; } + template + inline double det(Matrix33 const & m) + { + return m[0] * ( (double) m[4] * m[8] - (double) m[5] * m[7]) + - m[3] * ( (double) m[1] * m[8] - (double) m[2] * m[7]) + + m[6] * ( (double) m[1] * m[5] - (double) m[2] * m[4]); + } + template + inline Matrix33 transpose(Matrix33 const & m) + { + const int size=3; + Matrix33 mres(0); + int i, j; + for (i=0; i + inline double det(Matrix44 const & m) + { + return m[0] * ( m[5] * (m[10] * m[15] - m[11] * m[14]) + - m[9] * (m[6] * m[15] - m[7] * m[14]) + + m[13] * (m[6] * m[11] - m[7] * m[10])) + - m[4] * ( m[1] * (m[10] * m[15] - m[11] * m[14]) + - m[9] * (m[2] * m[15] - m[3] * m[14]) + + m[13] * (m[2] * m[11] - m[3] * m[10])) + + m[8] * ( m[1] * (m[6] * m[15] - m[7] * m[14]) + - m[5] * (m[2] * m[15] - m[3] * m[14]) + + m[13] * (m[2] * m[7] - m[3] * m[6])) + + m[12] * ( m[1] * (m[6] * m[11] - m[7] * m[10]) + - m[5] * (m[2] * m[11] - m[3] * m[10]) + + m[9] * (m[2] * m[7] - m[3] * m[6])); + } + template + inline Matrix44 transpose(Matrix44 const & m) + { + const int size=4; + Matrix44 mres(0); + int i, j; + for (i=0; i std::string & arda::Math::Matrix22::getstring(std::string & s) const +template +std::string & arda::Math::Matrix22::to_string(std::string & s) const { s.clear(); std::stringstream ss; @@ -315,98 +902,32 @@ return s; } - - - - - - - - - - - -#ifdef NOTHING - ////////////////////////////////////////////////////////////////////////// - // det*(Matrix m) - // Computer the determinant of a matrix. - // Returns the determinant. - - inline double det3(Matrix3i m) - { return m[0] * ( m[4] * m[8] - - m[5] * m[7]) - - m[3] * ( m[1] * m[8] - - m[2] * m[7]) - + m[6] * ( m[1] * m[5] - - m[2] * m[4]); } - - inline double det4(Matrix4i m) - { return m[0] * (m[5] * (m[10] * m[15] - - m[11] * m[14]) - - m[9] * (m[6] * m[15] - - m[7] * m[14]) + - m[13] * (m[6] * m[11] - - m[7] * m[10])) - - m[4] * (m[1] * (m[10] * m[15] - - m[11] * m[14]) - - m[9] * (m[2] * m[15] - - m[3] * m[14]) + - m[13] * (m[2] * m[11] - - m[3] * m[10])) + - m[8] * (m[1] * (m[6] * m[15] - - m[7] * m[14]) - - m[5] * (m[2] * m[15] - - m[3] * m[14]) + - m[13] * (m[2] * m[7] - - m[3] * m[6])) + - m[12] * (m[1] * (m[6] * m[11] - - m[7] * m[10]) - - m[5] * (m[2] * m[11] - - m[3] * m[10]) + - m[9] * (m[2] * m[7] - - m[3] * m[6])); } - -//////////////////////////////////////////////////////////////////////////////// -int * arda::Matrix::multvec3mv(Matrix3i m, Vector3i v, Vector3i vres) +template +std::string & arda::Math::Matrix33::to_string(std::string & s) const { - vres[0] = m[0]*v[0] + m[3]*v[1] + m[6]*v[2]; - vres[1] = m[1]*v[0] + m[4]*v[1] + m[7]*v[2]; - vres[2] = m[2]*v[0] + m[5]*v[1] + m[8]*v[2]; - return vres; + s.clear(); + std::stringstream ss; + ss << "[ " + "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], " + "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], " + "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ], ""]"; + s = ss.str(); + return s; } -//////////////////////////////////////////////////////////////////////////////// -int * arda::Matrix::multvec4mv(Matrix4i m, Vector4i v, Vector4i vres) +template +std::string & arda::Math::Matrix44::to_string(std::string & s) const { - vres[0] = m[0]*v[0] + m[4]*v[1] + m[8] *v[2] + m[12]*v[3]; - vres[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; - vres[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; - vres[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; - return vres; + s.clear(); + std::stringstream ss; + ss << "[ " + "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], " + "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], " + "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], " + "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ], ""]"; + s = ss.str(); + return s; } -//////////////////////////////////////////////////////////////////////////////// -int * arda::Matrix::multvec3vm(Vector3i v, Matrix3i m, Vector3i vres) - { - vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2]; - vres[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5]; - vres[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8]; - return vres; - } - -//////////////////////////////////////////////////////////////////////////////// -float * arda::Matrix::multvec4vm(Vector4f v, Matrix4f m, Vector4f vres) - { - vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3]; - vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7]; - vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11]; - vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15]; - return vres; - } -#endif - - - - #endif // MATRIX_H_ diff -r 398894c52b69 -r 1d2b25d4517f include/Vector.h --- a/include/Vector.h Fri Oct 07 13:33:48 2011 -0500 +++ b/include/Vector.h Mon May 06 01:06:12 2013 -0500 @@ -51,14 +51,14 @@ // get_anglen(Vector& v2) // Like get_angle(), but the vectors must already be normalized. // Not meaningful for int vectors. - // getstring(std::string & s) + // to_string(std::string & s) // Returns a C string representation of the vector. // This is one of the few non-inline Vector functions. // length() // Get the length of a vector. // Returns a double for all vector types. // normalize() - // Normalizes the vecor. + // Normalizes the vector. // Not meaningful for int vectors. // proj(Vector& v2, Vector& vres) // Calculates the projection of the vector onto v2 and returns the result @@ -103,192 +103,207 @@ ///////////////////////////////////////////////////////////////////////////// - template class Vector2 + template + class Vector2 { public: T x, y; // Constructors Vector2() {} - explicit Vector2(const T a) : x (a), y(a) {} - Vector2(const T a, const T b) : x (a), y(b) {} + explicit Vector2(T a) : x (a), y(a) {} + Vector2(T a, T b) : x (a), y(b) {} // Array indexing - inline T& operator[](unsigned int i) + inline T& operator[](unsigned int const i) { assert (i<2); if (i==0) return x; return y; } - inline T operator[](unsigned int i) const + inline T operator[](unsigned int const i) const { assert (i<2); if (i==0) return x; return y; } // Assignment - inline Vector2& operator=(const Vector2& v2) + inline Vector2& operator=(Vector2 const & v2) { x = v2.x; y = v2.y; return *this; } - inline Vector2& assign(const T a, const T b) + inline Vector2& assign(T const a, T const b) { x = a; y = b; return *this; } // Comparison - inline bool operator==(Vector2& v2) const + inline bool operator==(Vector2 const & v2) const { return ((x == v2.x) && (y == v2.y)); } - inline bool operator!=(Vector2& v2) const + inline bool operator!=(Vector2 const & v2) const { return ! (*this == v2); } // Vector addition - inline Vector2& operator+=(const Vector2& v2) + inline Vector2& operator+=(Vector2 const & v2) { x += v2.x; y += v2.y; return *this; } - inline Vector2 operator+(const Vector2& v2) const + inline Vector2 operator+(Vector2 const & v2) const { return Vector2(*this) += v2; } // Vector subtraction - inline Vector2& operator-=(const Vector2& v2) + inline Vector2& operator-=(Vector2 const & v2) { x -= v2.x; y -= v2.y; return *this; } - inline Vector2 operator-(const Vector2& v2) const + inline Vector2 operator-(Vector2 const & v2) const { return Vector2(*this) -= v2; } // Scalar multiplication - inline Vector2& operator*=(const int a) + inline Vector2& operator*=(int const a) { x *= a; y *= a; return *this; } - inline Vector2& operator*=(const float a) + inline Vector2& operator*=(float const a) { x *= a; y *= a; return *this; } - inline Vector2& operator*=(const double a) + inline Vector2& operator*=(double const a) { x *= a; y *= a; return *this; } - inline Vector2 operator*(const int a) + + inline Vector2 operator*(int const a) const { return Vector2(*this) *= a;} - inline Vector2 operator*(const float a) + inline Vector2 operator*(float const a) const { return Vector2(*this) *= a;} - inline Vector2 operator*(const double a) + inline Vector2 operator*(double const a) const { return Vector2(*this) *= a;} // Scalar division - inline Vector2& operator/=(const int a) + inline Vector2& operator/=(int const a) { assert(a!=0); x /= a; y /= a; return *this; } - inline Vector2& operator/=(const float a) + inline Vector2& operator/=(float const a) { assert(a!=0); x /= a; y /= a; return *this; } - inline Vector2& operator/=(const double a) + inline Vector2& operator/=(double const a) { assert(a!=0); x /= a; y /= a; return *this; } - inline Vector2 operator/(const int a) + + inline Vector2 operator/(int const a) const { return Vector2(*this) /= a;} - inline Vector2 operator/(const float a) + inline Vector2 operator/(float const a) const { return Vector2(*this) /= a;} - inline Vector2 operator/(const double a) + inline Vector2 operator/(double const a) const { return Vector2(*this) /= a;} // methods - inline T dot(const Vector2& v2) const + inline T dot(Vector2 const & v2) const { return x*v2.x + y*v2.y; } - inline double get_angle(Vector2& v2) + inline double get_angle(Vector2 const & v2) { double tmp = dot(v2); return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); } - inline double get_anglen(Vector2& v2) + inline double get_anglen(Vector2 const & v2) { return acos((double) dot(v2)); } - std::string & getstring(std::string & s) const; + std::string & to_string(std::string & s) const; inline double length(void) const { return sqrt((dot(*this))); } inline Vector2& normalize() - { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; return *this; } + { + double l = length(); + if (l == 0.0) return *this; + x /= l; y /= l; + return *this; } - inline Vector2 proj(Vector2& v2) - { Vector2 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } - inline Vector2& proj(Vector2& v2, Vector2& vres) + inline Vector2 proj(Vector2 const & v2) + { Vector2 vres; vres = v2 * (dot(v2)/v2.dot(v2)); return vres; } + inline Vector2& proj(Vector2 const & v2, Vector2& vres) { vres = v2 * dot(v2)/v2.dot(v2); return vres; } }; // Scalar multiplication, continued - template inline Vector2 operator*(const int a, const Vector2& v) - { return Vector2(v) *= a;} - template inline Vector2 operator*(const float a, const Vector2 v) - { return Vector2(v) *= a;} - template inline Vector2 operator*(const double a, const Vector2& v) + template + inline Vector2 operator*(int const a, Vector2 const & v) { return Vector2(v) *= a;} + template + inline Vector2 operator*(float const a, Vector2 const & v) + { return Vector2(v) *= a;} + + template + inline Vector2 operator*(double const a, Vector2 const & v) + { return Vector2(v) *= a;} + ///////////////////////////////////////////////////////////////////////////// - template class Vector3 + template + class Vector3 { public: T x, y, z; // Constructors Vector3() {} - explicit Vector3(const T a) : x (a), y(a), z(a) {} - Vector3(const T a, const T b, const T c) : x (a), y(b), z(c) {} + explicit Vector3(T a) : x (a), y(a), z(a) {} + Vector3(T a, T b, T c) : x (a), y(b), z(c) {} // Array indexing - inline T& operator[](unsigned int i) + inline T& operator[](unsigned int const i) { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } - inline T operator[](unsigned int i) const + inline T operator[](unsigned int const i) const { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } // Assignment - inline Vector3& operator=(const Vector3& v2) + inline Vector3& operator=(Vector3 const & v2) { x = v2.x; y = v2.y; z = v2.z; return *this; } - inline Vector3& assign(const T a, const T b, const T c) + inline Vector3& assign(T const a, T const b, T const c) { x = a; y = b; z = c; return *this; } // Comparison - inline bool operator==(Vector3& v2) const + inline bool operator==(Vector3 const & v2) const { return ((x == v2.x) && (y == v2.y) && (z == v2.z)); } - inline bool operator!=(Vector3& v2) const + inline bool operator!=(Vector3 const & v2) const { return ! (*this == v2); } // Vector addition - inline Vector3& operator+=(const Vector3& v2) + inline Vector3& operator+=(Vector3 const & v2) { x += v2.x; y += v2.y; z += v2.z; return *this; } - inline Vector3 operator+(const Vector3& v2) const + inline Vector3 operator+(Vector3 const & v2) const { return Vector3(*this) += v2; } // Vector subtraction - inline Vector3& operator-=(const Vector3& v2) + inline Vector3& operator-=(Vector3 const & v2) { x -= v2.x; y -= v2.y; z -= v2.z; return *this; } - inline Vector3 operator-(const Vector3& v2) const + inline Vector3 operator-(Vector3 const & v2) const { return Vector3(*this) -= v2; } // Scalar multiplication - inline Vector3& operator*=(const int a) + inline Vector3& operator*=(int const a) { x *= a; y *= a; z *= a; return *this; } - inline Vector3& operator*=(const float a) + inline Vector3& operator*=(float const a) { x *= a; y *= a; z *= a; return *this; } - inline Vector3& operator*=(const double a) + inline Vector3& operator*=(double const a) { x *= a; y *= a; z *= a; return *this; } - inline Vector3 operator*(const int a) + + inline Vector3 operator*(int const a) const { return Vector3(*this) *= a;} - inline Vector3 operator*(const float a) + inline Vector3 operator*(float const a) const { return Vector3(*this) *= a;} - inline Vector3 operator*(const double a) + inline Vector3 operator*(double const a) const { return Vector3(*this) *= a;} // Scalar division - inline Vector3& operator/=(const int a) + inline Vector3& operator/=(int const a) { assert(a!=0); x /= a; y /= a; z /= a; return *this; } - inline Vector3& operator/=(const float a) + inline Vector3& operator/=(float const a) { assert(a!=0); x /= a; y /= a; z /= a; return *this; } - inline Vector3& operator/=(const double a) + inline Vector3& operator/=(double const a) { assert(a!=0); x /= a; y /= a; z /= a; return *this; } - inline Vector3 operator/(const int a) + + inline Vector3 operator/(int const a) const { return Vector3(*this) /= a;} - inline Vector3 operator/(const float a) + inline Vector3 operator/(float const a) const { return Vector3(*this) /= a;} - inline Vector3 operator/(const double a) + inline Vector3 operator/(double const a) const { return Vector3(*this) /= a;} // methods - inline Vector3& cross(Vector3& v2, Vector3& vres) + inline Vector3& cross(Vector3 const & v2, Vector3& vres) { vres.x = y*v2.z - v2.y*z; vres.y = -x*v2.z + v2.x*z; vres.z = x*v2.y - v2.x*y; return vres; } - inline Vector3 cross(Vector3& v2) + inline Vector3 cross(Vector3 const & v2) { Vector3 vres; vres.x = y*v2.z - v2.y*z; @@ -297,19 +312,19 @@ return vres; } - inline T dot(const Vector3& v2) const + inline T dot(Vector3 const & v2) const { return x*v2.x + y*v2.y + z*v2.z; } - inline double get_angle(Vector3& v2) + inline double get_angle(Vector3 const & v2) { double tmp = dot(v2); return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); } - inline double get_anglen(Vector3& v2) + inline double get_anglen(Vector3 const & v2) { return acos((double) dot(v2)); } - std::string & getstring(std::string & s) const; + std::string & to_string(std::string & s) const; inline double length(void) const { return sqrt((dot(*this))); } @@ -317,105 +332,113 @@ inline Vector3& normalize() { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; return *this; } - inline Vector3 proj(Vector3& v2) + inline Vector3 proj(Vector3 const & v2) { Vector3 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } - inline Vector3& proj(Vector3& v2, Vector3& vres) + inline Vector3& proj(Vector3 const & v2, Vector3& vres) { vres = v2 * dot(v2)/v2.dot(v2); return vres; } }; // Scalar multiplication, continued - template inline Vector3 operator*(const int a, const Vector3& v) + template + inline Vector3 operator*(int const a, Vector3 const & v) { return Vector3(v) *= a;} - template inline Vector3 operator*(const float a, const Vector3 v) + + template + inline Vector3 operator*(float const a, Vector3 const & v) { return Vector3(v) *= a;} - template inline Vector3 operator*(const double a, const Vector3& v) + + template + inline Vector3 operator*(double const a, Vector3 const & v) { return Vector3(v) *= a;} ///////////////////////////////////////////////////////////////////////////// - template class Vector4 + template + class Vector4 { public: T x, y, z, w; // Constructors Vector4() {} - explicit Vector4(const T a) : x (a), y(a), z(a), w(a) {} - Vector4(const T a, const T b, const T c, const T d) : x (a), y(b), z(c), w(d) {} + explicit Vector4(T a) : x (a), y(a), z(a), w(a) {} + Vector4(T a, T b, T c, T d) : x (a), y(b), z(c), w(d) {} // Array indexing - inline T& operator[](unsigned int i) + inline T& operator[](unsigned int const i) { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } - inline T operator[](unsigned int i) const + inline T operator[](unsigned int const i) const { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } // Assignment - inline Vector4& operator=(const Vector4& v2) + inline Vector4& operator=(Vector4 const & v2) { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; } - inline Vector4& assign(const T a, const T b, const T c, const T d) + inline Vector4& assign(T const a, T const b, T const c, T const d) { x = a; y = b; z = c; w = d; return *this; } // Comparison - inline bool operator==(Vector4& v2) const + inline bool operator==(Vector4 const & v2) const { return ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); } - inline bool operator!=(Vector4& v2) const + inline bool operator!=(Vector4 const & v2) const { return ! (*this == v2); } // Vector addition - inline Vector4& operator+=(const Vector4& v2) + inline Vector4& operator+=(Vector4 const & v2) { x += v2.x; y += v2.y; z += v2.z; w += v2.w; return *this; } - inline Vector4 operator+(const Vector4& v2) const + inline Vector4 operator+(Vector4 const & v2) const { return Vector4(*this) += v2; } // Vector subtraction - inline Vector4& operator-=(const Vector4& v2) + inline Vector4& operator-=(Vector4 const & v2) { x -= v2.x; y -= v2.y; z -= v2.z; w -= v2.w; return *this; } - inline Vector4 operator-(const Vector4& v2) const + inline Vector4 operator-(Vector4 const & v2) const { return Vector4(*this) -= v2; } // Scalar multiplication - inline Vector4& operator*=(const int a) + inline Vector4& operator*=(int const a) { x *= a; y *= a; z *= a; w *= a; return *this; } - inline Vector4& operator*=(const float a) + inline Vector4& operator*=(float const a) { x *= a; y *= a; z *= a; w *= a; return *this; } - inline Vector4& operator*=(const double a) + inline Vector4& operator*=(double const a) { x *= a; y *= a; z *= a; w *= a; return *this; } - inline Vector4 operator*(const int a) + + inline Vector4 operator*(int const a) const { return Vector4(*this) *= a;} - inline Vector4 operator*(const float a) + inline Vector4 operator*(float const a) const { return Vector4(*this) *= a;} - inline Vector4 operator*(const double a) + inline Vector4 operator*(double const a) const { return Vector4(*this) *= a;} // Scalar division - inline Vector4& operator/=(const int a) + inline Vector4& operator/=(int const a) { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } - inline Vector4& operator/=(const float a) + inline Vector4& operator/=(float const a) { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } - inline Vector4& operator/=(const double a) + inline Vector4& operator/=(double const a) { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } - inline Vector4 operator/(const int a) + + inline Vector4 operator/(int const a) const { return Vector4(*this) /= a;} - inline Vector4 operator/(const float a) + inline Vector4 operator/(float const a) const { return Vector4(*this) /= a;} - inline Vector4 operator/(const double a) + inline Vector4 operator/(double const a) const { return Vector4(*this) /= a;} // methods - inline T dot(const Vector4& v2) const + inline T dot(Vector4 const & v2) const { return x*v2.x + y*v2.y + z*v2.z + w*v2.w; } - inline double get_angle(Vector4& v2) + inline double get_angle(Vector4 const & v2) { double tmp = dot(v2); return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); } - inline double get_anglen(Vector4& v2) + inline double get_anglen(Vector4 const & v2) { return acos((double) dot(v2)); } - std::string & getstring(std::string & s) const; + std::string & to_string(std::string & s) const; inline double length(void) const { return sqrt((dot(*this))); } @@ -423,18 +446,23 @@ inline Vector4& normalize() { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; w /= l; return *this; } - inline Vector4 proj(Vector4& v2) + inline Vector4 proj(Vector4 const & v2) { Vector4 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } - inline Vector4& proj(Vector4& v2, Vector4& vres) + inline Vector4& proj(Vector4 const & v2, Vector4& vres) { vres = v2 * dot(v2)/v2.dot(v2); return vres; } }; // Scalar multiplication, continued - template inline Vector4 operator*(const int a, const Vector4& v) + template + inline Vector4 operator*(int const a, Vector4 const & v) { return Vector4(v) *= a;} - template inline Vector4 operator*(const float a, const Vector4 v) + + template + inline Vector4 operator*(float const a, Vector4 const & v) { return Vector4(v) *= a;} - template inline Vector4 operator*(const double a, const Vector4& v) + + template + inline Vector4 operator*(double const a, Vector4 const & v) { return Vector4(v) *= a;} ///////////////////////////////////////////////////////////////////////////// @@ -456,7 +484,8 @@ } // namespace arda //////////////////////////////////////////////////////////////////////////////// -template std::string & arda::Math::Vector2::getstring(std::string & s) const +template +std::string & arda::Math::Vector2::to_string(std::string & s) const { s.clear(); std::stringstream ss; @@ -466,7 +495,8 @@ } //////////////////////////////////////////////////////////////////////////////// -template std::string & arda::Math::Vector3::getstring(std::string & s) const +template +std::string & arda::Math::Vector3::to_string(std::string & s) const { s.clear(); std::stringstream ss; @@ -476,7 +506,8 @@ } //////////////////////////////////////////////////////////////////////////////// -template std::string & arda::Math::Vector4::getstring(std::string & s) const +template +std::string & arda::Math::Vector4::to_string(std::string & s) const { s.clear(); std::stringstream ss; diff -r 398894c52b69 -r 1d2b25d4517f src/main.cpp --- a/src/main.cpp Fri Oct 07 13:33:48 2011 -0500 +++ b/src/main.cpp Mon May 06 01:06:12 2013 -0500 @@ -21,30 +21,30 @@ Vector2i v2i_3(1, 2); Vector2i v2i_4(v2i_3); - cout << setw(40) << "v2i_1: " << v2i_1.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v2i_4: " << v2i_4.getstring(s1) << endl; + cout << setw(40) << "v2i_1: " << v2i_1.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v2i_4: " << v2i_4.to_string(s1) << endl; Vector3f v3f_1(0); Vector3f v3f_2(1); Vector3f v3f_3(1, 2, 3); Vector3f v3f_4(v3f_3); - cout << setw(40) << "v3f_1: " << v3f_1.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v3f_4: " << v3f_4.getstring(s1) << endl; + cout << setw(40) << "v3f_1: " << v3f_1.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v3f_4: " << v3f_4.to_string(s1) << endl; Vector4d v4d_1(0); Vector4d v4d_2(1); Vector4d v4d_3(1, 2, 3, 4); Vector4d v4d_4(v4d_3); - cout << setw(40) << "v4d_1: " << v4d_1.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; - cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl; - cout << setw(40) << "v4d_4: " << v4d_4.getstring(s1) << endl; + cout << setw(40) << "v4d_1: " << v4d_1.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; + cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; + cout << setw(40) << "v4d_4: " << v4d_4.to_string(s1) << endl; } { @@ -70,28 +70,28 @@ Vector4d v4d_2(0); cout << "Before assignment" << endl; - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_2 = v2i; v3f_2 = v3f; v4d_2 = v4d; cout << "After assignment by =" << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_2.assign(1, 1); v3f_2.assign(2.2, 2.2, 2.2); v4d_2.assign(3.3, 3.3, 3.3, 3.3); cout << "After assignment by assign()" << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; } { @@ -107,15 +107,15 @@ Vector3f v3f_3(0); Vector4d v4d_3(0); - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; - cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; + cout << setw(40) << "v2i_3: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v4d_3: " << v4d_3.to_string(s1) << endl; cout << boolalpha; cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl; cout << setw(40) << "v2i == v2i_3: " << (v2i == v2i_3) << endl; @@ -144,24 +144,24 @@ Vector3f v3f_3(0); Vector4d v4d_3(0); - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_3 = v2i + v2i_2; v3f_3 = v3f + v3f_2; v4d_3 = v4d + v4d_2; - cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.to_string(s1) << endl; v2i_3 += v2i_2; v3f_3 += v3f_2; v4d_3 += v4d_3; - cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.to_string(s1) << endl; } { @@ -177,24 +177,24 @@ Vector3f v3f_3(0); Vector4d v4d_3(0); - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_3 = v2i - v2i_2; v3f_3 = v3f - v3f_2; v4d_3 = v4d - v4d_2; - cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.to_string(s1) << endl; v2i_3 -= v2i_2; v3f_3 -= v3f_2; v4d_3 -= v4d_3; - cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.getstring(s1) << endl; - cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.getstring(s1) << endl; - cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.to_string(s1) << endl; + cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.to_string(s1) << endl; + cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.to_string(s1) << endl; } { @@ -213,24 +213,24 @@ cout << setw(40) << "i: " << i << endl; cout << setw(40) << "f: " << f << endl; cout << setw(40) << "d: " << d << endl; - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_2 = v2i * i; v3f_2 = v3f * f; v4d_2 = v4d * d; - cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.to_string(s1) << endl; v2i_2 *= i; v3f_2 *= f; v4d_2 *= d; - cout << setw(40) << "v2i_2 *= i: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2 *= f: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2 *= d: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2 *= i: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2 *= f: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2 *= d: " << v4d_2.to_string(s1) << endl; } { @@ -246,24 +246,24 @@ float f = 2.f; double d = 2.0; - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2i_2 = v2i / i; v3f_2 = v3f / f; v4d_2 = v4d / d; - cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.to_string(s1) << endl; v2i_2 /= i; v3f_2 /= f; v4d_2 /= d; - cout << setw(40) << "v2i_2 /= i: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f_2 /= f: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d_2 /= d: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i_2 /= i: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f_2 /= f: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d_2 /= d: " << v4d_2.to_string(s1) << endl; } { @@ -273,16 +273,16 @@ Vector3f v3f_2(4.4, 5.5, 6.6); Vector3f v3f_3(0); Vector3f v3f_4(0); - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v3f_3: " << v3f_3.to_string(s1) << endl; v3f.cross(v3f_2, v3f_3); - cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; v3f_4 = 2.0 * v3f.cross(v3f_2); - cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.getstring(s1) << endl; + cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.to_string(s1) << endl; v3f_4.assign(0,0,0); v3f.cross(v3f_2, v3f_4); - cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.getstring(s1) << endl; + cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.to_string(s1) << endl; } { @@ -297,12 +297,12 @@ int i; float f; double d; - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; i = v2i.dot(v2i_2); cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl; f = v3f.dot(v3f_2); @@ -317,9 +317,9 @@ Vector2i v2i(1, 2); Vector3f v3f(1.1f, 2.2f, 3.3f); Vector4d v4d(1.1, 2.2, 3.3, 4.4); - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; cout << setw(40) << "v2i.length(): " << v2i.length() << endl; cout << setw(40) << "v3f.length(): " << v3f.length() << endl; cout << setw(40) << "v4d.length(): " << v4d.length() << endl; @@ -331,15 +331,15 @@ Vector2f v2f(1.1, 2.2); Vector3f v3f(1.1f, 2.2f, 3.3f); Vector4d v4d(1.1, 2.2, 3.3, 4.4); - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; v2f.normalize(); - cout << setw(40) << "v2f.normalize() " << v2f.getstring(s1) << endl; + cout << setw(40) << "v2f.normalize() " << v2f.to_string(s1) << endl; v3f.normalize(); - cout << setw(40) << "v3f.normalize() " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f.normalize() " << v3f.to_string(s1) << endl; v4d.normalize(); - cout << setw(40) << "v4d.normalize() " << v4d.getstring(s1) << endl; + cout << setw(40) << "v4d.normalize() " << v4d.to_string(s1) << endl; cout << setw(40) << "v2f.length(): " << v2f.length() << endl; cout << setw(40) << "v3f.length(): " << v3f.length() << endl; cout << setw(40) << "v4d.length(): " << v4d.length() << endl; @@ -355,12 +355,12 @@ Vector4d v4d(1.1, 2.2, 3.3, 4.4); Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); double d; - cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; - cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2i: " << v2i.to_string(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; d = v2i.get_angle(v2i_2); cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl; d = v3f.get_angle(v3f_2); @@ -385,12 +385,12 @@ v3f_2.normalize(); v4d.normalize(); v4d_2.normalize(); - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; - cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; + cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; d = v2f.get_anglen(v2f_2); cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl; d = v3f.get_anglen(v3f_2); @@ -411,27 +411,27 @@ Vector4d v4d(1.1, 2.2, 3.3, 4.4); Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); Vector4d v4d_3(0); - cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; - cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; - cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; - cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; - cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; - cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v2f: " << v2f.to_string(s1) << endl; + cout << setw(40) << "v2f_2: " << v2f_2.to_string(s1) << endl; + cout << setw(40) << "v3f: " << v3f.to_string(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.to_string(s1) << endl; + cout << setw(40) << "v4d: " << v4d.to_string(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.to_string(s1) << endl; v2f_3 = v2f.proj(v2f_2); - cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.getstring(s1) << endl; + cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.to_string(s1) << endl; v3f_3 = v3f.proj(v3f_2); - cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.to_string(s1) << endl; v4d_3 = v4d.proj(v4d_2); - cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.to_string(s1) << endl; v2f_3.assign(0,0); v3f_3.assign(0,0,0); v4d_3.assign(0,0,0,0); v2f.proj(v2f_2, v2f_3); - cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.getstring(s1) << endl; + cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.to_string(s1) << endl; v3f.proj(v3f_2, v3f_3); - cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.to_string(s1) << endl; v4d.proj(v4d_2, v4d_3); - cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.to_string(s1) << endl; } } @@ -449,10 +449,31 @@ Matrix22i m22i_3(1, 2, 3, 4); Matrix22i m22i_4(m22i_3); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; - cout << setw(40) << "m22i_4: " << m22i_4.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; + cout << setw(40) << "m22i_4: " << m22i_4.to_string(s1) << endl; + + Matrix33f m33f_1(0.0f); + Matrix33f m33f_2(1.1f); + Matrix33f m33f_3(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_4(m33f_3); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; + cout << setw(40) << "m33f_4: " << m33f_4.to_string(s1) << endl; + + Matrix44d m44d_1(0.0); + Matrix44d m44d_2(1.1); + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_4(m44d_3); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; + cout << setw(40) << "m44d_4: " << m44d_4.to_string(s1) << endl; } { @@ -461,25 +482,65 @@ Matrix22i m22i(1, 2, 3, 4); cout << setw(40) << "m22i: " << m22i[0] << " " << m22i[1] << " " << m22i[2] << " " << m22i[3] << " "<< endl; + + Matrix33f m33f(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + + cout << setw(40) << "m33f: " << m33f[0] << " " << m33f[1] << " " << m33f[2] << " " << m33f[3] << " " << m33f[4] << " " << m33f[5] << " " << m33f[6] << " " << m33f[7] << " " << m33f[8] << endl; + + Matrix44d m44d(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, + 12.12, 13.13, 14.14, 15.15, 16.16); + + 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; } { cout << "===============================================================" << endl << - "Testing Maxtrix array assignment" << endl; + "Testing Maxtrix assignment" << endl; Matrix22i m22i_1(1, 2, 3, 4); Matrix22i m22i_2(5, 6, 7, 8); - cout << "Before assignment" << endl; - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; m22i_2 = m22i_1; - cout << "After assignment by = " << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 = m22i_1: " << m22i_2.to_string(s1) << endl; m22i_2.assign(9, 10, 11, 12); - cout << "After assignment by assign" << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2.assign(9, 10, 11, 12): " + << m22i_2.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + + m33f_2 = m33f_1; + cout << setw(40) << "m33f_2 = m33f_1: " << m33f_2.to_string(s1) << endl; + + m33f_2.assign(19.19f, 20.20f, 21.21f, 22.22f, 23.23f, 24.24f, 25.25f, 26.26f, 27.27f); + cout << setw(40) << "m33f_2.assign(19.19f, 20.20f, ... , 27.27f): " + << m33f_2.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, + 20.20, 21.21, 22.22, 23.23, + 24.24, 25.25, 26.26, 27.27, + 28.28, 29.29, 30.30, 31.31); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + + m44d_2 = m44d_1; + cout << setw(40) << "m44d_2 = m44d_1: " << m44d_2.to_string(s1) << endl; + + m44d_2.assign(32.32, 33.33, 34.34, 35.35, + 36.36, 37.37, 38.38, 39.39, + 40.40, 41.41, 42.42, 43.43, + 44.44, 45.45, 46.46, 47.47); + cout << setw(40) << "m44d_2.assign(32.32, 33.33, ... , 47.47): " + << m44d_2.to_string(s1) << endl; } { @@ -489,14 +550,42 @@ Matrix22i m22i_2(1, 2, 3, 4); Matrix22i m22i_3(0); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; cout << boolalpha; cout << setw(40) << "m22i_1 == m22i_2: " << (m22i_1 == m22i_2) << endl; cout << setw(40) << "m22i_1 == m22i_3: " << (m22i_2 == m22i_3) << endl; cout << setw(40) << "m22i_1 != m22i_2: " << (m22i_1 != m22i_2) << endl; cout << setw(40) << "m22i_1 != m22i_3: " << (m22i_2 != m22i_3) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_3(0.0f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; + cout << boolalpha; + cout << setw(40) << "m33f_1 == m33f_2: " << (m33f_1 == m33f_2) << endl; + cout << setw(40) << "m33f_1 == m33f_3: " << (m33f_2 == m33f_3) << endl; + cout << setw(40) << "m33f_1 != m33f_2: " << (m33f_1 != m33f_2) << endl; + cout << setw(40) << "m33f_1 != m33f_3: " << (m33f_2 != m33f_3) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_3(0.0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; + cout << boolalpha; + cout << setw(40) << "m44d_1 == m44d_2: " << (m44d_1 == m44d_2) << endl; + cout << setw(40) << "m44d_1 == m44d_3: " << (m44d_2 == m44d_3) << endl; + cout << setw(40) << "m44d_1 != m44d_2: " << (m44d_1 != m44d_2) << endl; + cout << setw(40) << "m44d_1 != m44d_3: " << (m44d_2 != m44d_3) << endl; } { @@ -506,14 +595,44 @@ Matrix22i m22i_2(5, 6, 7, 8); Matrix22i m22i_3(0); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; m22i_3 = m22i_1 + m22i_2; - cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_3 = m22i_1 + m22i_2: " << m22i_3.to_string(s1) << endl; m22i_3 += m22i_1; - cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_3 += m22i_1: " << m22i_3.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); + Matrix33f m33f_3(0.0f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; + m33f_3 = m33f_1 + m33f_2; + cout << setw(40) << "m33f_3 = m33f_1 + m33f_2: " << m33f_3.to_string(s1) << endl; + + m33f_3 += m33f_1; + cout << setw(40) << "m33f_3 += m33f_1: " << m33f_3.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, + 20.20, 21.21, 22.22, 23.23, + 24.24, 25.25, 26.26, 27.27, + 28.28, 29.29, 30.30, 31.31); + Matrix44d m44d_3(0.0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; + m44d_3 = m44d_1 + m44d_2; + cout << setw(40) << "m44d_3 = m44d_1 + m44d_2: " << m44d_3.to_string(s1) << endl; + + m44d_3 += m44d_1; + cout << setw(40) << "m44d_3 += m44d_1: " << m44d_3.to_string(s1) << endl; } { @@ -523,14 +642,44 @@ Matrix22i m22i_2(5, 6, 7, 8); Matrix22i m22i_3(0); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; m22i_3 = m22i_1 - m22i_2; - cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_3 = m22i_1 - m22i_2: " << m22i_3.to_string(s1) << endl; m22i_3 -= m22i_1; - cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_3 -= m22i_1: " << m22i_3.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); + Matrix33f m33f_3(0.0f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; + m33f_3 = m33f_1 - m33f_2; + cout << setw(40) << "m33f_3 = m33f_1 - m33f_2: " << m33f_3.to_string(s1) << endl; + + m33f_3 -= m33f_1; + cout << setw(40) << "m33f_3 -= m33f_1: " << m33f_3.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, + 20.20, 21.21, 22.22, 23.23, + 24.24, 25.25, 26.26, 27.27, + 28.28, 29.29, 30.30, 31.31); + Matrix44d m44d_3(0.0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; + m44d_3 = m44d_1 - m44d_2; + cout << setw(40) << "m44d_3 = m44d_1 - m44d_2: " << m44d_3.to_string(s1) << endl; + + m44d_3 -= m44d_1; + cout << setw(40) << "m44d_3 -= m44d_1: " << m44d_3.to_string(s1) << endl; } { @@ -541,14 +690,43 @@ int i = 2; cout << setw(40) << "i: " << i << endl; - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; m22i_2 = m22i_1 *i; - cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 = m22i_1 * i: " << m22i_2.to_string(s1) << endl; m22i_2 = i * m22i_1; - cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 = i * m22i_1: " << m22i_2.to_string(s1) << endl; m22i_2 *= i; - cout << setw(40) << "m22i_2 *= i: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 *= i: " << m22i_2.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(0.0f); + float f = 2.0f; + + cout << setw(40) << "f: " << f << endl; + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + m33f_2 = m33f_1 * f; + cout << setw(40) << "m33f_2 = m33f_1 * f: " << m33f_2.to_string(s1) << endl; + m33f_2 = f * m33f_1; + cout << setw(40) << "m33f_2 = f * m33f_1: " << m33f_2.to_string(s1) << endl; + m33f_2 *= f; + cout << setw(40) << "m33f_2 *= f: " << m33f_2.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(0.0); + double d = 2.0f; + + cout << setw(40) << "d: " << d << endl; + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + m44d_2 = m44d_1 * d; + cout << setw(40) << "m44d_2 = m44d_1 * d: " << m44d_2.to_string(s1) << endl; + m44d_2 = d * m44d_1; + cout << setw(40) << "m44d_2 = d * m44d_1: " << m44d_2.to_string(s1) << endl; + m44d_2 *= d; + cout << setw(40) << "m44d_2 *= d: " << m44d_2.to_string(s1) << endl; } { @@ -559,12 +737,37 @@ int i = 2; cout << setw(40) << "i: " << i << endl; - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; m22i_2 = m22i_1 / i; - cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 = m22i_1 / i: " << m22i_2.to_string(s1) << endl; m22i_1 /= i; - cout << setw(40) << "m22i_1 /= i: " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_1 /= i: " << m22i_2.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(0.0f); + float f = 2.0f; + + cout << setw(40) << "f: " << f << endl; + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + m33f_2 = m33f_1 / f; + cout << setw(40) << "m33f_2 = m33f_1 / f: " << m33f_2.to_string(s1) << endl; + m33f_1 /= f; + cout << setw(40) << "m33f_1 /= f: " << m33f_2.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(0.0); + double d = 2.0f; + + cout << setw(40) << "d: " << d << endl; + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + m44d_2 = m44d_1 / d; + cout << setw(40) << "m44d_2 = m44d_1 / d: " << m44d_2.to_string(s1) << endl; + m44d_1 /= d; + cout << setw(40) << "m44d_1 /= d: " << m44d_2.to_string(s1) << endl; } { @@ -574,11 +777,35 @@ Matrix22i m22i_2(5, 6, 7, 8); Matrix22i m22i_3(0); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; - cout << setw(40) << "m22i_2: " << m22i_2.getstring(s1) << endl; - cout << setw(40) << "m22i_3: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; + cout << setw(40) << "m22i_2: " << m22i_2.to_string(s1) << endl; + cout << setw(40) << "m22i_3: " << m22i_3.to_string(s1) << endl; m22i_3 = m22i_1 * m22i_2; - cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.getstring(s1) << endl; + cout << setw(40) << "m22i_3 = m22i_1 * m22i_2: " << m22i_3.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(10.10f, 11.11f, 12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f); + Matrix33f m33f_3(0.0f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + cout << setw(40) << "m33f_2: " << m33f_2.to_string(s1) << endl; + cout << setw(40) << "m33f_3: " << m33f_3.to_string(s1) << endl; + m33f_3 = m33f_1 * m33f_2; + cout << setw(40) << "m33f_3 = m33f_1 * m33f_2: " << m33f_3.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(16.16, 17.17, 18.18, 19.19, + 20.20, 21.21, 22.22, 23.23, + 24.24, 25.25, 26.26, 27.27, + 28.28, 29.29, 30.30, 31.31); + Matrix44d m44d_3(0.0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + cout << setw(40) << "m44d_2: " << m44d_2.to_string(s1) << endl; + cout << setw(40) << "m44d_3: " << m44d_3.to_string(s1) << endl; + m44d_3 = m44d_1 * m44d_2; + cout << setw(40) << "m44d_3 = m44d_1 * m44d_2: " << m44d_3.to_string(s1) << endl; } { @@ -587,9 +814,25 @@ Matrix22i m22i_1(1, 2, 3, 4); double d; - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; d = det(m22i_1); cout << setw(40) << "d = det(m22i_1): " << d << endl; + + // Note: singular matrix. The real determinant is exactly zero. + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + d = det(m33f_1); + cout << setw(40) << "d = det(m33f_1): " << d << endl; + + // Note: singular matrix. The real determinant is exactly zero. + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + d = det(m44d_1); + cout << setw(40) << "d = det(m44d_1): " << d << endl; + } { @@ -598,9 +841,24 @@ Matrix22i m22i_1(1, 2, 3, 4); Matrix22i m22i_2; - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; m22i_2 = transpose(m22i_1); - cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.getstring(s1) << endl; + cout << setw(40) << "m22i_2 = transpose(m22i_1): " << m22i_2.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Matrix33f m33f_2(0.0f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + m33f_2 = transpose(m33f_1); + cout << setw(40) << "m33f_2 = transpose(m33f_1): " << m33f_2.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Matrix44d m44d_2(0.0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + m44d_2 = transpose(m44d_1); + cout << setw(40) << "m44d_2 = transpose(m44d_1): " << m44d_2.to_string(s1) << endl; } { @@ -608,9 +866,22 @@ "Testing Maxtrix setidentity" << endl; Matrix22i m22i_1(1, 2, 3, 4); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); - cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setidentity(): " << m22i_1.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + m33f_1.setidentity(); + cout << setw(40) << "m33f_1.setidentity(): " << m33f_1.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + m44d_1.setidentity(); + cout << setw(40) << "m44d_1.setidentity(): " << m44d_1.to_string(s1) << endl; } { @@ -619,15 +890,55 @@ Matrix22i m22i_1(1, 2, 3, 4); Vector2i v2i_1(0); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; v2i_1 = m22i_1.getrow(0); - cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.getstring(s1) << endl; + cout << setw(40) << "v2i_1 = m22i_1.getrow(0): " << v2i_1.to_string(s1) << endl; v2i_1 = m22i_1.getrow(1); - cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.getstring(s1) << endl; + cout << setw(40) << "v2i_1 = m22i_1.getrow(1): " << v2i_1.to_string(s1) << endl; v2i_1 = m22i_1.getcol(0); - cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.getstring(s1) << endl; + cout << setw(40) << "v2i_1 = m22i_1.getcol(0): " << v2i_1.to_string(s1) << endl; v2i_1 = m22i_1.getcol(1); - cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.getstring(s1) << endl; + cout << setw(40) << "v2i_1 = m22i_1.getcol(1): " << v2i_1.to_string(s1) << endl; + + Matrix33f m33f_1(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); + Vector3f v3f_1(0); + + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getrow(0); + cout << setw(40) << "v3f_1 = m33f_1.getrow(0): " << v3f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getrow(1); + cout << setw(40) << "v3f_1 = m33f_1.getrow(1): " << v3f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getrow(2); + cout << setw(40) << "v3f_1 = m33f_1.getrow(2): " << v3f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getcol(0); + cout << setw(40) << "v3f_1 = m33f_1.getcol(0): " << v3f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getcol(1); + cout << setw(40) << "v3f_1 = m33f_1.getcol(1): " << v3f_1.to_string(s1) << endl; + v3f_1 = m33f_1.getcol(2); + cout << setw(40) << "v3f_1 = m33f_1.getcol(2): " << v3f_1.to_string(s1) << endl; + + 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, + 12.12, 13.13, 14.14, 15.15, 16.16); + Vector4d v4d_1(0); + + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getrow(0); + cout << setw(40) << "v4d_1 = m44d_1.getrow(0): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getrow(1); + cout << setw(40) << "v4d_1 = m44d_1.getrow(1): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getrow(2); + cout << setw(40) << "v4d_1 = m44d_1.getrow(2): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getrow(3); + cout << setw(40) << "v4d_1 = m44d_1.getrow(3): " << v4d_1.to_string(s1) << endl; + + v4d_1 = m44d_1.getcol(0); + cout << setw(40) << "v4d_1 = m44d_1.getcol(0): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getcol(1); + cout << setw(40) << "v4d_1 = m44d_1.getcol(1): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getcol(2); + cout << setw(40) << "v4d_1 = m44d_1.getcol(2): " << v4d_1.to_string(s1) << endl; + v4d_1 = m44d_1.getcol(3); + cout << setw(40) << "v4d_1 = m44d_1.getcol(3): " << v4d_1.to_string(s1) << endl; } { @@ -637,29 +948,89 @@ Vector2i v2i_1(2, 3); m22i_1.setidentity(); - cout << setw(40) << "m22i_1: " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1: " << m22i_1.to_string(s1) << endl; m22i_1.setrow(0, v2i_1); - cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setrow(0, v2i_1): " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); m22i_1.setrow(1, v2i_1); - cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setrow(1, v2i_1): " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); m22i_1.setrow(1, 4, 5); - cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setrow(1, 4, 5): " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); m22i_1.setcol(0, v2i_1); - cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setcol(0, v2i_1): " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); m22i_1.setcol(1, v2i_1); - cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setcol(1, v2i_1): " << m22i_1.to_string(s1) << endl; m22i_1.setidentity(); m22i_1.setcol(1, 4, 5); - cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.getstring(s1) << endl; + cout << setw(40) << "m22i_1.setcol(1, 4, 5): " << m22i_1.to_string(s1) << endl; + + Matrix33f m33f_1; + Vector3f v3f_1(0); + + m33f_1.setidentity(); + cout << setw(40) << "m33f_1: " << m33f_1.to_string(s1) << endl; + m33f_1.setrow(0, v3f_1); + cout << setw(40) << "m33f_1.setrow(0, v3f_1): " << m33f_1.to_string(s1) << endl; + + m33f_1.setidentity(); + m33f_1.setrow(1, v3f_1); + cout << setw(40) << "m33f_1.setrow(1, v3f_1): " << m33f_1.to_string(s1) << endl; + + m33f_1.setidentity(); + m33f_1.setrow(1, 2.2f, 3.3f, 4.4f); + cout << setw(40) << "m33f_1.setrow(1, 2.2f, 3.3f, 4.4f): " + << m33f_1.to_string(s1) << endl; + + m33f_1.setidentity(); + m33f_1.setcol(0, v3f_1); + cout << setw(40) << "m33f_1.setcol(0, v3f_1): " << m33f_1.to_string(s1) << endl; + + m33f_1.setidentity(); + m33f_1.setcol(1, v3f_1); + cout << setw(40) << "m33f_1.setcol(1, v3f_1): " << m33f_1.to_string(s1) << endl; + + m33f_1.setidentity(); + m33f_1.setcol(1, 2.2f, 3.3f, 4.4f); + cout << setw(40) << "m33f_1.setcol(1, 2.2f, 3.3f, 4.4f: " + << m33f_1.to_string(s1) << endl; + + Matrix44d m44d_1; + Vector4d v4d_1(0); + + m44d_1.setidentity(); + cout << setw(40) << "m44d_1: " << m44d_1.to_string(s1) << endl; + m44d_1.setrow(0, v4d_1); + cout << setw(40) << "m44d_1.setrow(0, v4d_1): " << m44d_1.to_string(s1) << endl; + + m44d_1.setidentity(); + m44d_1.setrow(1, v4d_1); + cout << setw(40) << "m44d_1.setrow(1, v4d_1): " << m44d_1.to_string(s1) << endl; + + m44d_1.setidentity(); + m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5); + cout << setw(40) << "m44d_1.setrow(1, 2.2, 3.3, 4.4, 5.5): " + << m44d_1.to_string(s1) << endl; + + m44d_1.setidentity(); + m44d_1.setcol(0, v4d_1); + cout << setw(40) << "m44d_1.setcol(0, v4d_1): " << m44d_1.to_string(s1) << endl; + + m44d_1.setidentity(); + m44d_1.setcol(1, v4d_1); + cout << setw(40) << "m44d_1.setcol(1, v4d_1): " << m44d_1.to_string(s1) << endl; + + m44d_1.setidentity(); + m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5); + cout << setw(40) << "m44d_1.setcol(1, 2.2, 3.3, 4.4, 5.5: " + << m44d_1.to_string(s1) << endl; } } @@ -687,6 +1058,9 @@ { int retval = 0; + test_all(); + return 0; + try { int choice = -1;