# HG changeset patch # User Eris Caffee # Date 1369012636 18000 # Node ID ea32c94fc4951219e35efb91306d26045eb36b2b # Parent c029247daf0e4347c65fe6646e0ede8062c4392c General minor improvements. - Spelling corrections. - Made the top level constants like PI static. - Changed instances of literal 1 and 0 to T(1) and T(0) diff -r c029247daf0e -r ea32c94fc495 include/Math.h --- a/include/Math.h Sun May 12 03:05:37 2013 -0500 +++ b/include/Math.h Sun May 19 20:17:16 2013 -0500 @@ -25,10 +25,11 @@ { // This many decimals is enough to cover even IEEE quad precision (128 bit) // reals. Run on PA-RISC lately? :) - 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; + // Should these be #defines? I'm starting to think that they should be. + static long double const PI = 3.14159265358979323846264338327950288; + static long double const TWO_PI = 6.28318530717958647692528676655900577; + static long double const PI_DIV_180 = 0.01745329251994329576923690768488613; + static long double const INV_PI_DIV_180 = 57.29577951308232087679815481410517033; ////////////////////////////////////////////////////////////////////////// // Mixed Vector / Matrix operations. diff -r c029247daf0e -r ea32c94fc495 include/Matrix.h --- a/include/Matrix.h Sun May 12 03:05:37 2013 -0500 +++ b/include/Matrix.h Sun May 19 20:17:16 2013 -0500 @@ -24,6 +24,10 @@ // first row. // == != + += - -= // Defined for operations on two matrices of the same type. + // TODO Is there a better way to do this? With integer types this is fine, + // but with floating point types this == and != are really worthless. Is it possible to + // create variant methods in a template class that vary by the type? Or do I just have + // to suck it up and create type specific external functions for comparing Matrices? // * *= / /= // Defined for scalar multiplication/division with int, float, and double. // * is defined as a standalone template operator for the scalar * Matrix @@ -241,7 +245,7 @@ inline Matrix22& setidentity() { memset(m, 0, sizeof(m)); - m[0] = m[3] = 1; + m[0] = m[3] = T(1); return *this; } @@ -492,7 +496,7 @@ inline Matrix33& setidentity() { memset(m, 0, sizeof(m)); - m[0] = m[4] = m[8] = 1; + m[0] = m[4] = m[8] = T(1); return *this; } @@ -763,7 +767,7 @@ inline Matrix44& setidentity() { memset(m, 0, sizeof(m)); - m[0] = m[5] = m[10] = m[15] = 1; + m[0] = m[5] = m[10] = m[15] = T(1); return *this; } diff -r c029247daf0e -r ea32c94fc495 include/Transform.h --- a/include/Transform.h Sun May 12 03:05:37 2013 -0500 +++ b/include/Transform.h Sun May 19 20:17:16 2013 -0500 @@ -11,7 +11,7 @@ ////////////////////////////////////////////////////////////////////////// - // Transformation by distance vector d + // Transformation by distance d template void get_trans_mat44(arda::Math::Matrix44 & M, arda::Math::Vector4 d); @@ -30,7 +30,7 @@ template void get_scale_mat44(arda::Math::Matrix44 & M, arda::Math::Vector3 s); - // Non-uniform scaling along arbitrary axes + // Non-uniform scaling along arbitrary axis template void get_scale_mat44(arda::Math::Matrix44 & M, arda::Math::Vector3 s, arda::Math::Vector3 x, arda::Math::Vector3 y, arda::Math::Vector3 z); @@ -41,11 +41,9 @@ void get_shear_mat44(arda::Math::Matrix44 & M, int i, int j, float s); template - void get_transform_mat44(arda::Math::Matrix44 & M, - float angle, arda::Math::Vector3 v, - arda::Math::Vector3 d); + void get_transform_mat44(arda::Math::Matrix44 & M, float angle, arda::Math::Vector3 v, arda::Math::Vector3 d); - // + // Rotate by angle around v with center of rotation p. template void get_rot_about_point_mat44(arda::Math::Matrix33 & M, float angle, arda::Math::Vector3 v, arda::Math::Vector3 p); @@ -82,6 +80,7 @@ float s = sin(angle); float one_minus_c = 1.0f - c; + // Remember: the "rows" as written here are actually the columns of the matrix. 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 , @@ -179,22 +178,22 @@ M[0] = M33[0]; M[1] = M33[1]; M[2] = M33[2]; - M[3] = 0; + M[3] = T(0); M[4] = M33[3]; M[5] = M33[4]; M[6] = M33[5]; - M[7] = 0; + M[7] = T(0); M[8] = M33[6]; M[9] = M33[7]; M[10] = M33[8]; - M[11] = 0; + M[11] = T(0); M[12] = p.x - p1.x; M[13] = p.y - p1.y; M[14] = p.z - p1.z; - M[15] = 1; + M[15] = T(1); } #endif diff -r c029247daf0e -r ea32c94fc495 include/Vector.h --- a/include/Vector.h Sun May 12 03:05:37 2013 -0500 +++ b/include/Vector.h Sun May 19 20:17:16 2013 -0500 @@ -32,6 +32,10 @@ // v[0], v[1], v[2], and v[3]. in addtion to v.x, v.y, v.z, and v.w // == != + += - -= // Defined for operations on two vectors of the same type. + // TODO Is there a better way to do this? With integer types this is fine, + // but with floating point types this == and != are really worthless. Is it possible to + // create variant methods in a template class that vary by the type? Or do I just have + // to suck it up and create type specific external functions for comparing vectors? // * *= / /= // Defined for scalar multiplication/division with int, float, and double. // * is defined as a standalone template operator for the scalar * Vector form. @@ -242,7 +246,7 @@ // Assignment inline Vector3& operator=(Vector2 const & v2) - { x = v2.x; y = v2.y; z = 0; return *this; } + { x = v2.x; y = v2.y; z = T(0); return *this; } inline Vector3& operator=(Vector3 const & v2) { x = v2.x; y = v2.y; z = v2.z; return *this; } @@ -377,9 +381,9 @@ // Assignment inline Vector4& operator=(Vector2 const & v2) - { x = v2.x; y = v2.y; z = 0; w = 0; return *this; } + { x = v2.x; y = v2.y; z = T(0); w = T(0); return *this; } inline Vector4& operator=(Vector3 const & v2) - { x = v2.x; y = v2.y; z = v2.z; w = 0; return *this; } + { x = v2.x; y = v2.y; z = v2.z; w = T(0); return *this; } inline Vector4& operator=(Vector4 const & v2) { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; }