Mercurial > Math
changeset 15:ea32c94fc495
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)
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Sun, 19 May 2013 20:17:16 -0500 |
parents | c029247daf0e |
children | 2ac83ae9129b |
files | include/Math.h include/Matrix.h include/Transform.h include/Vector.h |
diffstat | 4 files changed, 28 insertions(+), 20 deletions(-) [+] |
line diff
1.1 --- a/include/Math.h Sun May 12 03:05:37 2013 -0500 1.2 +++ b/include/Math.h Sun May 19 20:17:16 2013 -0500 1.3 @@ -25,10 +25,11 @@ 1.4 { 1.5 // This many decimals is enough to cover even IEEE quad precision (128 bit) 1.6 // reals. Run on PA-RISC lately? :) 1.7 - long double const PI = 3.14159265358979323846264338327950288; 1.8 - long double const TWO_PI = 6.28318530717958647692528676655900577; 1.9 - long double const PI_DIV_180 = 0.01745329251994329576923690768488613; 1.10 - long double const INV_PI_DIV_180 = 57.29577951308232087679815481410517033; 1.11 + // Should these be #defines? I'm starting to think that they should be. 1.12 + static long double const PI = 3.14159265358979323846264338327950288; 1.13 + static long double const TWO_PI = 6.28318530717958647692528676655900577; 1.14 + static long double const PI_DIV_180 = 0.01745329251994329576923690768488613; 1.15 + static long double const INV_PI_DIV_180 = 57.29577951308232087679815481410517033; 1.16 1.17 ////////////////////////////////////////////////////////////////////////// 1.18 // Mixed Vector / Matrix operations.
2.1 --- a/include/Matrix.h Sun May 12 03:05:37 2013 -0500 2.2 +++ b/include/Matrix.h Sun May 19 20:17:16 2013 -0500 2.3 @@ -24,6 +24,10 @@ 2.4 // first row. 2.5 // == != + += - -= 2.6 // Defined for operations on two matrices of the same type. 2.7 + // TODO Is there a better way to do this? With integer types this is fine, 2.8 + // but with floating point types this == and != are really worthless. Is it possible to 2.9 + // create variant methods in a template class that vary by the type? Or do I just have 2.10 + // to suck it up and create type specific external functions for comparing Matrices? 2.11 // * *= / /= 2.12 // Defined for scalar multiplication/division with int, float, and double. 2.13 // * is defined as a standalone template operator for the scalar * Matrix 2.14 @@ -241,7 +245,7 @@ 2.15 inline Matrix22<T>& setidentity() 2.16 { 2.17 memset(m, 0, sizeof(m)); 2.18 - m[0] = m[3] = 1; 2.19 + m[0] = m[3] = T(1); 2.20 return *this; 2.21 } 2.22 2.23 @@ -492,7 +496,7 @@ 2.24 inline Matrix33<T>& setidentity() 2.25 { 2.26 memset(m, 0, sizeof(m)); 2.27 - m[0] = m[4] = m[8] = 1; 2.28 + m[0] = m[4] = m[8] = T(1); 2.29 return *this; 2.30 } 2.31 2.32 @@ -763,7 +767,7 @@ 2.33 inline Matrix44<T>& setidentity() 2.34 { 2.35 memset(m, 0, sizeof(m)); 2.36 - m[0] = m[5] = m[10] = m[15] = 1; 2.37 + m[0] = m[5] = m[10] = m[15] = T(1); 2.38 return *this; 2.39 } 2.40
3.1 --- a/include/Transform.h Sun May 12 03:05:37 2013 -0500 3.2 +++ b/include/Transform.h Sun May 19 20:17:16 2013 -0500 3.3 @@ -11,7 +11,7 @@ 3.4 3.5 ////////////////////////////////////////////////////////////////////////// 3.6 3.7 - // Transformation by distance vector d 3.8 + // Transformation by distance d 3.9 template <typename T> 3.10 void get_trans_mat44(arda::Math::Matrix44<T> & M, arda::Math::Vector4<T> d); 3.11 3.12 @@ -30,7 +30,7 @@ 3.13 template <typename T> 3.14 void get_scale_mat44(arda::Math::Matrix44<T> & M, arda::Math::Vector3<T> s); 3.15 3.16 - // Non-uniform scaling along arbitrary axes 3.17 + // Non-uniform scaling along arbitrary axis 3.18 template <typename T> 3.19 void get_scale_mat44(arda::Math::Matrix44<T> & M, arda::Math::Vector3<T> s, 3.20 arda::Math::Vector3<T> x, arda::Math::Vector3<T> y, arda::Math::Vector3<T> z); 3.21 @@ -41,11 +41,9 @@ 3.22 void get_shear_mat44(arda::Math::Matrix44<T> & M, int i, int j, float s); 3.23 3.24 template <typename T> 3.25 - void get_transform_mat44(arda::Math::Matrix44<T> & M, 3.26 - float angle, arda::Math::Vector3<T> v, 3.27 - arda::Math::Vector3<T> d); 3.28 + void get_transform_mat44(arda::Math::Matrix44<T> & M, float angle, arda::Math::Vector3<T> v, arda::Math::Vector3<T> d); 3.29 3.30 - // 3.31 + // Rotate by angle around v with center of rotation p. 3.32 template <typename T> 3.33 void get_rot_about_point_mat44(arda::Math::Matrix33<T> & M, float angle, arda::Math::Vector3<T> v, arda::Math::Vector3<T> p); 3.34 3.35 @@ -82,6 +80,7 @@ 3.36 float s = sin(angle); 3.37 float one_minus_c = 1.0f - c; 3.38 3.39 + // Remember: the "rows" as written here are actually the columns of the matrix. 3.40 M.assign( 3.41 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 , 3.42 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 , 3.43 @@ -179,22 +178,22 @@ 3.44 M[0] = M33[0]; 3.45 M[1] = M33[1]; 3.46 M[2] = M33[2]; 3.47 - M[3] = 0; 3.48 + M[3] = T(0); 3.49 3.50 M[4] = M33[3]; 3.51 M[5] = M33[4]; 3.52 M[6] = M33[5]; 3.53 - M[7] = 0; 3.54 + M[7] = T(0); 3.55 3.56 M[8] = M33[6]; 3.57 M[9] = M33[7]; 3.58 M[10] = M33[8]; 3.59 - M[11] = 0; 3.60 + M[11] = T(0); 3.61 3.62 M[12] = p.x - p1.x; 3.63 M[13] = p.y - p1.y; 3.64 M[14] = p.z - p1.z; 3.65 - M[15] = 1; 3.66 + M[15] = T(1); 3.67 } 3.68 3.69 #endif
4.1 --- a/include/Vector.h Sun May 12 03:05:37 2013 -0500 4.2 +++ b/include/Vector.h Sun May 19 20:17:16 2013 -0500 4.3 @@ -32,6 +32,10 @@ 4.4 // v[0], v[1], v[2], and v[3]. in addtion to v.x, v.y, v.z, and v.w 4.5 // == != + += - -= 4.6 // Defined for operations on two vectors of the same type. 4.7 + // TODO Is there a better way to do this? With integer types this is fine, 4.8 + // but with floating point types this == and != are really worthless. Is it possible to 4.9 + // create variant methods in a template class that vary by the type? Or do I just have 4.10 + // to suck it up and create type specific external functions for comparing vectors? 4.11 // * *= / /= 4.12 // Defined for scalar multiplication/division with int, float, and double. 4.13 // * is defined as a standalone template operator for the scalar * Vector form. 4.14 @@ -242,7 +246,7 @@ 4.15 4.16 // Assignment 4.17 inline Vector3<T>& operator=(Vector2<T> const & v2) 4.18 - { x = v2.x; y = v2.y; z = 0; return *this; } 4.19 + { x = v2.x; y = v2.y; z = T(0); return *this; } 4.20 inline Vector3<T>& operator=(Vector3<T> const & v2) 4.21 { x = v2.x; y = v2.y; z = v2.z; return *this; } 4.22 4.23 @@ -377,9 +381,9 @@ 4.24 4.25 // Assignment 4.26 inline Vector4<T>& operator=(Vector2<T> const & v2) 4.27 - { x = v2.x; y = v2.y; z = 0; w = 0; return *this; } 4.28 + { x = v2.x; y = v2.y; z = T(0); w = T(0); return *this; } 4.29 inline Vector4<T>& operator=(Vector3<T> const & v2) 4.30 - { x = v2.x; y = v2.y; z = v2.z; w = 0; return *this; } 4.31 + { x = v2.x; y = v2.y; z = v2.z; w = T(0); return *this; } 4.32 inline Vector4<T>& operator=(Vector4<T> const & v2) 4.33 { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; } 4.34