Matrix Operations | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | identity (Matrix< DATA_TYPE, ROWS, COLS > &result) |
Make identity matrix out the matrix. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | zero (Matrix< DATA_TYPE, ROWS, COLS > &result) |
zero out the matrix. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | mult (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, INTERNAL > &lhs, const Matrix< DATA_TYPE, INTERNAL, COLS > &rhs) |
matrix multiply. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > | operator * (const Matrix< DATA_TYPE, ROWS, INTERNAL > &lhs, const Matrix< DATA_TYPE, INTERNAL, COLS > &rhs) |
matrix * matrix. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | sub (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &lhs, const Matrix< DATA_TYPE, ROWS, COLS > &rhs) |
matrix subtraction (algebraic operation for matrix). More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | add (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &lhs, const Matrix< DATA_TYPE, ROWS, COLS > &rhs) |
matrix addition (algebraic operation for matrix). More... | |
template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & | postMult (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand) |
matrix postmultiply. More... | |
template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & | preMult (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand) |
matrix preMultiply. More... | |
template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & | operator *= (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand) |
matrix postmult (operator *=). More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | mult (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &mat, float scalar) |
matrix scalar mult. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | mult (Matrix< DATA_TYPE, ROWS, COLS > &result, DATA_TYPE scalar) |
matrix scalar mult. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | operator *= (Matrix< DATA_TYPE, ROWS, COLS > &result, DATA_TYPE scalar) |
matrix scalar mult (operator *=). More... | |
template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & | transpose (Matrix< DATA_TYPE, SIZE, SIZE > &result) |
matrix transpose in place. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | transpose (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, COLS, ROWS > &source) |
matrix transpose from one type to another (i.e. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | invertFull (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &src) |
full matrix inversion. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | invert (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &src) |
smart matrix inversion. More... | |
template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & | invert (Matrix< DATA_TYPE, ROWS, COLS > &result) |
smart matrix inversion (in place) Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through. More... | |
Plane Operations | |
template<class DATA_TYPE> DATA_TYPE | distance (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt) |
Computes the distance from the plane to the point. More... | |
template<class DATA_TYPE> PlaneSide | whichSide (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt) |
Determines which side of the plane the given point lies. More... | |
template<class DATA_TYPE> PlaneSide | whichSide (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt, const DATA_TYPE &eps) |
Determines which side of the plane the given point lies with the given epsilon tolerance. More... | |
template<class DATA_TYPE> DATA_TYPE | findNearestPt (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt, Point< DATA_TYPE, 3 > &result) |
Finds the point on the plane that is nearest to the given point. More... | |
Quat Operations | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | mult (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
product of two quaternions (quaternion product) multiplication of quats is much like multiplication of typical complex numbers. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator * (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
product of two quaternions (quaternion product) Does quaternion multiplication. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator *= (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q2) |
quaternion postmult. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | negate (Quat< DATA_TYPE > &result) |
Vector negation - negate each element in the quaternion vector. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator- (const Quat< DATA_TYPE > &quat) |
Vector negation - (operator-) return a temporary that is the negative of the given quat. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | mult (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q, DATA_TYPE s) |
vector scalar multiplication. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator * (const Quat< DATA_TYPE > &q, DATA_TYPE s) |
vector scalar multiplication. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator *= (Quat< DATA_TYPE > &q, DATA_TYPE s) |
vector scalar multiplication. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | div (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, Quat< DATA_TYPE > q2) |
quotient of two quaternions. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator/ (const Quat< DATA_TYPE > &q1, Quat< DATA_TYPE > q2) |
quotient of two quaternions. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator/= (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q2) |
quotient of two quaternions. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | div (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q, DATA_TYPE s) |
quaternion vector scale. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator/ (const Quat< DATA_TYPE > &q, DATA_TYPE s) |
vector scalar division. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator/= (const Quat< DATA_TYPE > &q, DATA_TYPE s) |
vector scalar division. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | add (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector addition. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator+ (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector addition. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator+= (Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector addition. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | sub (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector subtraction. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > | operator- (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector subtraction. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | operator-= (Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector subtraction. More... | |
template<typename DATA_TYPE> DATA_TYPE | dot (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2) |
vector dot product between two quaternions. More... | |
template<typename DATA_TYPE> DATA_TYPE | lengthSquared (const Quat< DATA_TYPE > &q) |
quaternion "norm" (also known as vector length squared) using this can be faster than using length for some operations... More... | |
template<typename DATA_TYPE> DATA_TYPE | length (const Quat< DATA_TYPE > &q) |
quaternion "absolute" (also known as vector length or magnitude) using this can be faster than using length for some operations... More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | normalize (Quat< DATA_TYPE > &result) |
set self to the normalized quaternion of self. More... | |
template<typename DATA_TYPE> bool | isNormalized (const Quat< DATA_TYPE > &q1, const DATA_TYPE eps=(DATA_TYPE) 0.0001f) |
Determines if the given quaternion is normalized within the given tolerance. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | conj (Quat< DATA_TYPE > &result) |
quaternion complex conjugate. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | invert (Quat< DATA_TYPE > &result) |
quaternion multiplicative inverse. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | exp (Quat< DATA_TYPE > &result) |
complex exponentiation. More... | |
template<typename DATA_TYPE> Quat< DATA_TYPE > & | log (Quat< DATA_TYPE > &result) |
complex logarithm. More... | |
template<typename DATA_TYPE> void | squad (Quat< DATA_TYPE > &result, DATA_TYPE t, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2, const Quat< DATA_TYPE > &a, const Quat< DATA_TYPE > &b) |
WARNING: not implemented (do not use). More... | |
template<typename DATA_TYPE> void | meanTangent (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2, const Quat< DATA_TYPE > &q3) |
WARNING: not implemented (do not use). More... | |
Triangle Operations | |
template<class DATA_TYPE> Point< DATA_TYPE, 3 > | center (const Tri< DATA_TYPE > &tri) |
Computes the point at the center of the given triangle. More... | |
template<class DATA_TYPE> Vec< DATA_TYPE, 3 > | normal (const Tri< DATA_TYPE > &tri) |
Computes the normal for this triangle. More... | |
Vector/Point Operations | |
template<typename DATA_TYPE, unsigned SIZE> Vec< DATA_TYPE, SIZE > | operator- (const VecBase< DATA_TYPE, SIZE > &v1) |
Negates v1. More... | |
template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & | operator+= (VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2) |
Adds v2 to v1 and stores the result in v1. More... | |
template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > | operator+ (const VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2) |
Adds v2 to v1 and returns the result. More... | |
template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & | operator-= (VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2) |
Subtracts v2 from v1 and stores the result in v1. More... | |
template<class DATA_TYPE, unsigned SIZE> Vec< DATA_TYPE, SIZE > | operator- (const VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2) |
Subtracts v2 from v1 and returns the result. More... | |
template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > & | operator *= (VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar) |
Multiplies v1 by a scalar value and stores the result in v1. More... | |
template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > | operator * (const VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar) |
Multiplies v1 by a scalar value and returns the result. More... | |
template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > | operator * (const SCALAR_TYPE &scalar, const VecBase< DATA_TYPE, SIZE > &v1) |
Multiplies v1 by a scalar value and returns the result. More... | |
template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > & | operator/= (VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar) |
Divides v1 by a scalar value and stores the result in v1. More... | |
template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > | operator/ (const VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar) |
Divides v1 by a scalar value and returns the result. More... | |
Vector Operations | |
template<class DATA_TYPE, unsigned SIZE> DATA_TYPE | dot (const Vec< DATA_TYPE, SIZE > &v1, const Vec< DATA_TYPE, SIZE > &v2) |
Computes dot product of v1 and v2 and returns the result. More... | |
template<class DATA_TYPE, unsigned SIZE> DATA_TYPE | length (const Vec< DATA_TYPE, SIZE > &v1) |
Computes the length of the given vector. More... | |
template<class DATA_TYPE, unsigned SIZE> DATA_TYPE | lengthSquared (const Vec< DATA_TYPE, SIZE > &v1) |
Computes the square of the length of the given vector. More... | |
template<class DATA_TYPE, unsigned SIZE> DATA_TYPE | normalize (Vec< DATA_TYPE, SIZE > &v1) |
Normalizes the given vector in place causing it to be of unit length. More... | |
template<class DATA_TYPE, unsigned SIZE> bool | isNormalized (const Vec< DATA_TYPE, SIZE > &v1, const DATA_TYPE eps=(DATA_TYPE) 0.0001) |
Determines if the given vector is normalized within the given tolerance. More... | |
template<class DATA_TYPE> Vec< DATA_TYPE, 3 > | cross (const Vec< DATA_TYPE, 3 > &v1, const Vec< DATA_TYPE, 3 > &v2) |
Computes the cross product between v1 and v2 and returns the result. More... | |
template<class DATA_TYPE> Vec< DATA_TYPE, 3 > & | cross (Vec< DATA_TYPE, 3 > &result, const Vec< DATA_TYPE, 3 > &v1, const Vec< DATA_TYPE, 3 > &v2) |
Computes the cross product between v1 and v2 and stores the result in result. More... | |
template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & | reflect (VecBase< DATA_TYPE, SIZE > &result, const VecBase< DATA_TYPE, SIZE > &vec, const Vec< DATA_TYPE, SIZE > &normal) |
Reflect a vector about a normal. More... |
|
vector addition.
Definition at line 256 of file QuatOps.h.
00257 { 00258 result[0] = q1[0] + q2[0]; 00259 result[1] = q1[1] + q2[1]; 00260 result[2] = q1[2] + q2[2]; 00261 result[3] = q1[3] + q2[3]; 00262 return result; 00263 } |
|
matrix addition (algebraic operation for matrix). @PRE: if lhs is m x n, and rhs is m x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n matrix TODO: enforce the sizes with templates... Definition at line 163 of file MatrixOps.h.
00166 { 00167 // p. 150 Numerical Analysis (second ed.) 00168 // if A is m x n, and B is m x n, then AB is m x n 00169 // (A - B)ij = (a)ij + (b)ij (where: 1 <= i <= m, 1 <= j <= n) 00170 for (unsigned int i = 0; i < ROWS; ++i) // 1 <= i <= m 00171 for (unsigned int j = 0; j < COLS; ++j) // 1 <= j <= n 00172 result( i, j ) = lhs( i, j ) + rhs( i, j ); 00173 00174 return result; 00175 } |
|
Computes the point at the center of the given triangle.
Definition at line 55 of file TriOps.h. Referenced by gmtl::Sphere::setCenter, and gmtl::Sphere::Sphere.
00056 { 00057 const float one_third = (1.0f/3.0f); 00058 return (tri[0] + tri[1] + tri[2]) * one_third; 00059 } |
|
quaternion complex conjugate.
Definition at line 405 of file QuatOps.h.
|
|
Computes the cross product between v1 and v2 and stores the result in result. The result is also returned by reference. Use this when you want to reuse an existing Vec to store the result. Note that this only applies to 3-dimensional vectors.
Definition at line 390 of file VecOps.h. Referenced by gmtl::Plane::Plane.
|
|
Computes the cross product between v1 and v2 and returns the result. Note that this only applies to 3-dimensional vectors.
Definition at line 367 of file VecOps.h.
|
|
Computes the distance from the plane to the point.
Definition at line 59 of file PlaneOps.h.
00060 { 00061 return ( dot(plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt)) - plane.mOffset ); 00062 } |
|
quaternion vector scale.
Definition at line 222 of file QuatOps.h.
00223 { 00224 result[0] = q[0] / s; 00225 result[1] = q[1] / s; 00226 result[2] = q[2] / s; 00227 result[3] = q[3] / s; 00228 return result; 00229 } |
|
quotient of two quaternions.
Definition at line 191 of file QuatOps.h.
|
|
vector dot product between two quaternions. get the lengthSquared between two quat vectors...
Definition at line 327 of file QuatOps.h.
00328 { 00329 return DATA_TYPE( (q1[0] * q2[0]) + 00330 (q1[1] * q2[1]) + 00331 (q1[2] * q2[2]) + 00332 (q1[3] * q2[3]) ); 00333 } |
|
Computes dot product of v1 and v2 and returns the result.
Definition at line 263 of file VecOps.h. Referenced by gmtl::Plane::Plane.
00264 { 00265 DATA_TYPE ret_val(0); 00266 for(unsigned i=0;i<SIZE;++i) 00267 { 00268 ret_val += (v1[i] * v2[i]); 00269 } 00270 return ret_val; 00271 } |
|
complex exponentiation.
Definition at line 444 of file QuatOps.h.
00445 { 00446 DATA_TYPE len1, len2; 00447 00448 len1 = Math::sqrt( result[Xelt] * result[Xelt] + 00449 result[Yelt] * result[Yelt] + 00450 result[Zelt] * result[Zelt] ); 00451 if (len1 > (DATA_TYPE)0.0) 00452 len2 = Math::sin( len1 ) / len1; 00453 else 00454 len2 = (DATA_TYPE)1.0; 00455 00456 result[Xelt] = result[Xelt] * len2; 00457 result[Yelt] = result[Yelt] * len2; 00458 result[Zelt] = result[Zelt] * len2; 00459 result[Welt] = Math::cos( len1 ); 00460 00461 return result; 00462 } |
|
Finds the point on the plane that is nearest to the given point. As a convenience, the distance between pt and result is returned.
Definition at line 125 of file PlaneOps.h.
00128 { 00129 // GGI: p297 00130 // GGII: p223 00131 gmtlASSERT( isNormalized(plane.mNorm) ); // Assert: Normalized 00132 DATA_TYPE dist_to_plane(0); 00133 dist_to_plane = plane.mOffset + dot( plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt) ); 00134 result = pt - (plane.mNorm * dist_to_plane); 00135 return dist_to_plane; 00136 } |
|
Make identity matrix out the matrix.
Definition at line 55 of file MatrixOps.h.
00056 { 00057 if(result.mState != Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY) // if not already ident 00058 { 00059 // TODO: mp 00060 for (unsigned int r = 0; r < ROWS; ++r) 00061 for (unsigned int c = 0; c < COLS; ++c) 00062 result( r, c ) = (DATA_TYPE)0.0; 00063 00064 // TODO: mp 00065 for (unsigned int x = 0; x < Math::Min( COLS, ROWS ); ++x) 00066 result( x, x ) = (DATA_TYPE)1.0; 00067 00068 // result.mState = Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY; 00069 result.mState = Matrix<DATA_TYPE, ROWS, COLS>::FULL; 00070 } 00071 00072 return result; 00073 } |
|
quaternion multiplicative inverse.
Definition at line 419 of file QuatOps.h.
00420 { 00421 // from game programming gems p198 00422 // do result = conj( q ) / norm( q ) 00423 conj( result ); 00424 00425 // return if norm() is near 0 (divide by 0 would result in NaN) 00426 DATA_TYPE l = lengthSquared( result ); 00427 if (l < (DATA_TYPE)0.0001) 00428 return result; 00429 00430 DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l; 00431 result[Xelt] *= l_inv; 00432 result[Yelt] *= l_inv; 00433 result[Zelt] *= l_inv; 00434 result[Welt] *= l_inv; 00435 return result; 00436 } |
|
smart matrix inversion (in place) Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through. 5 types of inversion: FULL, AFFINE, ORTHONORMAL, ORTHOGONAL, IDENTITY. Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix. Definition at line 427 of file MatrixOps.h.
00428 { 00429 return invert( result, result ); 00430 } |
|
smart matrix inversion. Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through. 5 types of inversion: FULL, AFFINE, ORTHONORMAL, ORTHOGONAL, IDENTITY. Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix. Definition at line 408 of file MatrixOps.h.
00409 { 00410 if (src.mState == Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY ) 00411 return result = src; 00412 else 00413 return invertFull( result, src ); 00414 } |
|
full matrix inversion. Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix. Definition at line 289 of file MatrixOps.h.
00290 { 00291 /*---------------------------------------------------------------------------* 00292 | mat_inv: Compute the inverse of a n x n matrix, using the maximum pivot | 00293 | strategy. n <= MAX1. | 00294 *---------------------------------------------------------------------------* 00295 00296 Parameters: 00297 a a n x n square matrix 00298 b inverse of input a. 00299 n dimenstion of matrix a. 00300 */ 00301 00302 const DATA_TYPE* a = src.getData(); 00303 DATA_TYPE* b = result.mData; 00304 00305 int n = 4; 00306 int i, j, k; 00307 int r[ 4], c[ 4], row[ 4], col[ 4]; 00308 DATA_TYPE m[ 4][ 4*2], pivot, max_m, tmp_m, fac; 00309 00310 /* Initialization */ 00311 for ( i = 0; i < n; i ++ ) 00312 { 00313 r[ i] = c[ i] = 0; 00314 row[ i] = col[ i] = 0; 00315 } 00316 00317 /* Set working matrix */ 00318 for ( i = 0; i < n; i++ ) 00319 { 00320 for ( j = 0; j < n; j++ ) 00321 { 00322 m[ i][ j] = a[ i * n + j]; 00323 m[ i][ j + n] = ( i == j ) ? (DATA_TYPE)1.0 : (DATA_TYPE)0.0 ; 00324 } 00325 } 00326 00327 /* Begin of loop */ 00328 for ( k = 0; k < n; k++ ) 00329 { 00330 /* Choosing the pivot */ 00331 for ( i = 0, max_m = 0; i < n; i++ ) 00332 { 00333 if ( row[ i] ) 00334 continue; 00335 for ( j = 0; j < n; j++ ) 00336 { 00337 if ( col[ j] ) 00338 continue; 00339 tmp_m = gmtl::Math::abs( m[ i][ j]); 00340 if ( tmp_m > max_m) 00341 { 00342 max_m = tmp_m; 00343 r[ k] = i; 00344 c[ k] = j; 00345 } 00346 } 00347 } 00348 row[ r[k] ] = col[ c[k] ] = 1; 00349 pivot = m[ r[ k] ][ c[ k] ]; 00350 00351 00352 if ( gmtl::Math::abs( pivot) <= 1e-20) 00353 { 00354 std::cerr << "*** pivot = " << pivot << " in mat_inv. ***\n"; 00355 result.setError(); 00356 return result; 00357 } 00358 00359 /* Normalization */ 00360 for ( j = 0; j < 2*n; j++ ) 00361 { 00362 if ( j == c[ k] ) 00363 m[ r[ k]][ j] = (DATA_TYPE)1.0; 00364 else 00365 m[ r[ k]][ j] /= pivot; 00366 } 00367 00368 /* Reduction */ 00369 for ( i = 0; i < n; i++ ) 00370 { 00371 if ( i == r[ k] ) 00372 continue; 00373 00374 for ( j=0, fac = m[ i][ c[k]]; j < 2*n; j++ ) 00375 { 00376 if ( j == c[ k] ) 00377 m[ i][ j] = (DATA_TYPE)0.0; 00378 else 00379 m[ i][ j] -= fac * m[ r[k]][ j]; 00380 } 00381 } 00382 } 00383 00384 /* Assign inverse to a matrix */ 00385 for ( i = 0; i < n; i++ ) 00386 for ( j = 0; j < n; j++ ) 00387 row[ i] = ( c[ j] == i ) ? r[ j] : row[ i]; 00388 00389 for ( i = 0; i < n; i++ ) 00390 for ( j = 0; j < n; j++ ) 00391 b[ i * n + j] = m[ row[ i]][ j + n]; 00392 00393 // It worked 00394 return result; 00395 } |
|
Determines if the given vector is normalized within the given tolerance. The vector is normalized if its lengthSquared is 1.
Definition at line 348 of file VecOps.h.
00350 { 00351 return Math::isEqual( lengthSquared( v1 ), (DATA_TYPE)1.0, eps ); 00352 } |
|
Determines if the given quaternion is normalized within the given tolerance. The quaternion is normalized if its lengthSquared is 1.
Definition at line 393 of file QuatOps.h.
00394 { 00395 return Math::isEqual( lengthSquared( q1 ), DATA_TYPE(1), eps ); 00396 } |
|
Computes the length of the given vector.
Definition at line 281 of file VecOps.h. Referenced by gmtl::LineSeg::getLength.
00282 { 00283 DATA_TYPE ret_val = lengthSquared(v1); 00284 if (ret_val == 0.0f) 00285 return 0.0f; 00286 else 00287 return Math::sqrt(ret_val); 00288 } |
|
quaternion "absolute" (also known as vector length or magnitude) using this can be faster than using length for some operations...
Definition at line 355 of file QuatOps.h.
00356 { 00357 return Math::sqrt( lengthSquared( q ) ); 00358 } |
|
Computes the square of the length of the given vector. This can be used in many calculations instead of length to increase speed by saving you an expensive sqrt call.
Definition at line 300 of file VecOps.h.
00301 { 00302 DATA_TYPE ret_val(0); 00303 for(unsigned i=0;i<SIZE;++i) 00304 { 00305 ret_val += (v1[i] * v1[i]); 00306 } 00307 00308 return ret_val; 00309 } |
|
quaternion "norm" (also known as vector length squared) using this can be faster than using length for some operations...
Definition at line 343 of file QuatOps.h.
00344 { 00345 return dot( q, q ); 00346 } |
|
complex logarithm.
Definition at line 469 of file QuatOps.h.
00470 { 00471 DATA_TYPE length; 00472 00473 length = Math::sqrt( result[Xelt] * result[Xelt] + 00474 result[Yelt] * result[Yelt] + 00475 result[Zelt] * result[Zelt] ); 00476 00477 // avoid divide by 0 00478 if (Math::isEqual( result[Welt], (DATA_TYPE)0.0, (DATA_TYPE)0.00001 ) == false) 00479 length = Math::aTan( length / result[Welt] ); 00480 else 00481 length = Math::PI_OVER_2; 00482 00483 result[Welt] = (DATA_TYPE)0.0; 00484 result[Xelt] = result[Xelt] * length; 00485 result[Yelt] = result[Yelt] * length; 00486 result[Zelt] = result[Zelt] * length; 00487 return result; 00488 } |
|
WARNING: not implemented (do not use).
Definition at line 499 of file QuatOps.h.
00500 { 00501 gmtlASSERT( false ); 00502 } |
|
vector scalar multiplication.
Definition at line 156 of file QuatOps.h.
00157 { 00158 result[0] = q[0] * s; 00159 result[1] = q[1] * s; 00160 result[2] = q[2] * s; 00161 result[3] = q[3] * s; 00162 return result; 00163 } |
|
matrix scalar mult. mult each elt in a matrix by a scalar value. @POST: result *= scalar Definition at line 228 of file MatrixOps.h.
00229 { 00230 for (unsigned i = 0; i < ROWS * COLS; ++i) 00231 result.mData[i] *= scalar; 00232 return result; 00233 } |
|
matrix scalar mult. mult each elt in a matrix by a scalar value. @POST: result = mat * scalar Definition at line 216 of file MatrixOps.h.
00217 { 00218 for (unsigned i = 0; i < ROWS * COLS; ++i) 00219 result.mData[i] = mat.mData[i] * scalar; 00220 return result; 00221 } |
|
matrix multiply. @PRE: With regard to size (ROWS/COLS): if lhs is m x p, and rhs is p x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n sized matrix @post: result = lhs * rhs (where rhs is applied first) Definition at line 106 of file MatrixOps.h.
00109 { 00110 Matrix<DATA_TYPE, ROWS, COLS> ret_mat; // prevent aliasing 00111 zero( ret_mat ); 00112 00113 // p. 150 Numerical Analysis (second ed.) 00114 // if A is m x p, and B is p x n, then AB is m x n 00115 // (AB)ij = [k = 1 to p] (a)ik (b)kj (where: 1 <= i <= m, 1 <= j <= n) 00116 for (unsigned int i = 0; i < ROWS; ++i) // 1 <= i <= m 00117 for (unsigned int j = 0; j < COLS; ++j) // 1 <= j <= n 00118 for (unsigned int k = 0; k < INTERNAL; ++k) // [k = 1 to p] 00119 ret_mat( i, j ) += lhs( i, k ) * rhs( k, j ); 00120 00121 return result = ret_mat; 00122 } |
|
product of two quaternions (quaternion product) multiplication of quats is much like multiplication of typical complex numbers.
Definition at line 55 of file QuatOps.h.
00056 { 00057 // Here is the easy to understand equation: (grassman product) 00058 // scalar_component = q1.s * q2.s - dot(q1.v, q2.v) 00059 // vector_component = q2.v * q1.s + q1.v * q2.s + cross(q1.v, q2.v) 00060 00061 // Here is another version (euclidean product, just FYI)... 00062 // scalar_component = q1.s * q2.s + dot(q1.v, q2.v) 00063 // vector_component = q2.v * q1.s - q1.v * q2.s - cross(q1.v, q2.v) 00064 00065 // Here it is, using vector algebra (grassman product) 00066 /* 00067 const float& w1( q1[Welt] ), w2( q2[Welt] ); 00068 Vec3 v1( q1[Xelt], q1[Yelt], q1[Zelt] ), v2( q2[Xelt], q2[Yelt], q2[Zelt] ); 00069 00070 float w = w1 * w2 - v1.dot( v2 ); 00071 Vec3 v = (w1 * v2) + (w2 * v1) + v1.cross( v2 ); 00072 00073 vec[Welt] = w; 00074 vec[Xelt] = v[0]; 00075 vec[Yelt] = v[1]; 00076 vec[Zelt] = v[2]; 00077 */ 00078 00079 // Here is the same, only expanded... (grassman product) 00080 Quat<DATA_TYPE> temporary; // avoid aliasing problems... 00081 temporary[Xelt] = q1[Welt]*q2[Xelt] + q1[Xelt]*q2[Welt] + q1[Yelt]*q2[Zelt] - q1[Zelt]*q2[Yelt]; 00082 temporary[Yelt] = q1[Welt]*q2[Yelt] + q1[Yelt]*q2[Welt] + q1[Zelt]*q2[Xelt] - q1[Xelt]*q2[Zelt]; 00083 temporary[Zelt] = q1[Welt]*q2[Zelt] + q1[Zelt]*q2[Welt] + q1[Xelt]*q2[Yelt] - q1[Yelt]*q2[Xelt]; 00084 temporary[Welt] = q1[Welt]*q2[Welt] - q1[Xelt]*q2[Xelt] - q1[Yelt]*q2[Yelt] - q1[Zelt]*q2[Zelt]; 00085 00086 // use a temporary, in case q1 or q2 is the same as self. 00087 result[Xelt] = temporary[Xelt]; 00088 result[Yelt] = temporary[Yelt]; 00089 result[Zelt] = temporary[Zelt]; 00090 result[Welt] = temporary[Welt]; 00091 00092 // don't normalize, because it might not be rotation arithmetic we're doing 00093 // (only rotation quats have unit length) 00094 return result; 00095 } |
|
Vector negation - negate each element in the quaternion vector. the negative of a rotation quaternion is geometrically equivelent to the original. there exist 2 quats for every possible rotation.
Definition at line 131 of file QuatOps.h.
00132 { 00133 result[0] = -result[0]; 00134 result[1] = -result[1]; 00135 result[2] = -result[2]; 00136 result[3] = -result[3]; 00137 return result; 00138 } |
|
Computes the normal for this triangle.
Definition at line 69 of file TriOps.h.
|
|
Normalizes the given vector in place causing it to be of unit length. If the vector is already of length 1.0, nothing is done. For convenience, the original length of the vector is returned.
Definition at line 323 of file VecOps.h. Referenced by gmtl::Plane::Plane.
00324 { 00325 DATA_TYPE len = length(v1); 00326 00327 if(len != 0.0f) 00328 { 00329 for(unsigned i=0;i<SIZE;++i) 00330 { 00331 v1[i] /= len; 00332 } 00333 } 00334 00335 return len; 00336 } |
|
set self to the normalized quaternion of self.
Definition at line 366 of file QuatOps.h.
00367 { 00368 DATA_TYPE l = length( result ); 00369 00370 // return if no magnitude (already as normalized as possible) 00371 if (l < (DATA_TYPE)0.0001) 00372 return result; 00373 00374 DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l; 00375 result[Xelt] *= l_inv; 00376 result[Yelt] *= l_inv; 00377 result[Zelt] *= l_inv; 00378 result[Welt] *= l_inv; 00379 00380 return result; 00381 } |
|
Multiplies v1 by a scalar value and returns the result. Thus result = scalar * v1. This is equivalent to result = v1 * scalar.
Definition at line 197 of file VecOps.h.
00199 { 00200 VecBase<DATA_TYPE, SIZE> ret_val(v1); 00201 ret_val *= scalar; 00202 return ret_val; 00203 00204 //return VecBase<DATA_TYPE, SIZE>(v1) *= scalar; 00205 } |
|
Multiplies v1 by a scalar value and returns the result. Thus result = v1 * scalar.
Definition at line 177 of file VecOps.h.
00179 { 00180 VecBase<DATA_TYPE, SIZE> ret_val(v1); 00181 ret_val *= scalar; 00182 return ret_val; 00183 00184 //return VecBase<DATA_TYPE, SIZE>(v1) *= scalar; 00185 } |
|
vector scalar multiplication.
Definition at line 170 of file QuatOps.h.
00171 { 00172 Quat<DATA_TYPE> temporary; 00173 return mult( temporary, q, s ); 00174 } |
|
product of two quaternions (quaternion product) Does quaternion multiplication.
Definition at line 104 of file QuatOps.h.
00105 { 00106 // (grassman product - see mult() for discussion) 00107 // don't normalize, because it might not be rotation arithmetic we're doing 00108 // (only rotation quats have unit length) 00109 return Quat<DATA_TYPE>( q1[Welt]*q2[Xelt] + q1[Xelt]*q2[Welt] + q1[Yelt]*q2[Zelt] - q1[Zelt]*q2[Yelt], 00110 q1[Welt]*q2[Yelt] + q1[Yelt]*q2[Welt] + q1[Zelt]*q2[Xelt] - q1[Xelt]*q2[Zelt], 00111 q1[Welt]*q2[Zelt] + q1[Zelt]*q2[Welt] + q1[Xelt]*q2[Yelt] - q1[Yelt]*q2[Xelt], 00112 q1[Welt]*q2[Welt] - q1[Xelt]*q2[Xelt] - q1[Yelt]*q2[Yelt] - q1[Zelt]*q2[Zelt] ); 00113 } |
|
matrix * matrix. @PRE: With regard to size (ROWS/COLS): if lhs is m x p, and rhs is p x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n sized matrix == lhs * rhs (where rhs is applied first) returns a temporary, is slower. Definition at line 130 of file MatrixOps.h.
00132 { 00133 Matrix<DATA_TYPE, ROWS, COLS> temporary; 00134 return mult( temporary, lhs, rhs ); 00135 } |
|
Multiplies v1 by a scalar value and stores the result in v1. This is equivalent to the expression v1 = v1 * scalar.
Definition at line 156 of file VecOps.h.
00158 { 00159 for(unsigned i=0;i<SIZE;++i) 00160 { 00161 v1[i] *= (DATA_TYPE)scalar; 00162 } 00163 00164 return v1; 00165 } |
|
vector scalar multiplication.
Definition at line 181 of file QuatOps.h.
00182 { 00183 return mult( q, q, s ); 00184 } |
|
quaternion postmult.
Definition at line 120 of file QuatOps.h.
00121 { 00122 return mult( result, result, q2 ); 00123 } |
|
matrix scalar mult (operator *=). multiply matrix elements by a scalar @POST: result *= scalar Definition at line 240 of file MatrixOps.h.
00241 { 00242 return mult( result, scalar ); 00243 } |
|
matrix postmult (operator *=). does a postmult on the matrix. @PRE: args must both be n x n sized (this function is undefined otherwise) @POST: result' = result * operand (where operand is applied first) Definition at line 205 of file MatrixOps.h.
00207 { 00208 return postMult( result, operand ); 00209 } |
|
Adds v2 to v1 and returns the result. Thus result = v1 + v2.
Definition at line 100 of file VecOps.h.
00102 { 00103 VecBase<DATA_TYPE, SIZE> ret_val(v1); 00104 ret_val += v2; 00105 return ret_val; 00106 } |
|
vector addition.
Definition at line 270 of file QuatOps.h.
00271 { 00272 Quat<DATA_TYPE> temporary; 00273 return add( temporary, q1, q2 ); 00274 } |
|
Adds v2 to v1 and stores the result in v1. This is equivalent to the expression v1 = v1 + v2.
Definition at line 80 of file VecOps.h.
00082 { 00083 for(unsigned i=0;i<SIZE;++i) 00084 { 00085 v1[i] += v2[i]; 00086 } 00087 00088 return v1; 00089 } |
|
vector addition.
Definition at line 281 of file QuatOps.h.
00282 { 00283 return add( q1, q1, q2 ); 00284 } |
|
Subtracts v2 from v1 and returns the result. Thus result = v1 - v2.
Definition at line 138 of file VecOps.h.
00140 { 00141 Vec<DATA_TYPE, SIZE> ret_val(v1); 00142 ret_val -= v2; 00143 return ret_val; 00144 } |
|
vector subtraction.
Definition at line 304 of file QuatOps.h.
00305 { 00306 Quat<DATA_TYPE> temporary; 00307 return sub( temporary, q1, q2 ); 00308 } |
|
Vector negation - (operator-) return a temporary that is the negative of the given quat. the negative of a rotation quaternion is geometrically equivelent to the original. there exist 2 quats for every possible rotation.
Definition at line 146 of file QuatOps.h.
00147 { 00148 return Quat<DATA_TYPE>( -quat[0], -quat[1], -quat[2], -quat[3] ); 00149 } |
|
Negates v1. The result = -v1.
Definition at line 60 of file VecOps.h.
00061 { 00062 Vec<DATA_TYPE, SIZE> ret_val; 00063 for ( unsigned i=0; i < SIZE; ++i ) 00064 { 00065 ret_val[i] = -v1[i]; 00066 } 00067 return ret_val; 00068 } |
|
Subtracts v2 from v1 and stores the result in v1. This is equivalent to the expression v1 = v1 - v2.
Definition at line 118 of file VecOps.h.
00120 { 00121 for(unsigned i=0;i<SIZE;++i) 00122 { 00123 v1[i] -= v2[i]; 00124 } 00125 00126 return v1; 00127 } |
|
vector subtraction.
Definition at line 315 of file QuatOps.h.
00316 { 00317 return sub( q1, q1, q2 ); 00318 } |
|
Divides v1 by a scalar value and returns the result. Thus result = v1 / scalar.
Definition at line 238 of file VecOps.h.
00240 { 00241 VecBase<DATA_TYPE, SIZE> ret_val(v1); 00242 ret_val /= scalar; 00243 return ret_val; 00244 // return VecBase<DATA_TYPE, SIZE>(v1)( /= scalar; 00245 } |
|
vector scalar division.
Definition at line 236 of file QuatOps.h.
00237 { 00238 Quat<DATA_TYPE> temporary; 00239 return div( temporary, q, s ); 00240 } |
|
quotient of two quaternions.
Definition at line 202 of file QuatOps.h.
00203 { 00204 return q1 * invert( q2 ); 00205 } |
|
Divides v1 by a scalar value and stores the result in v1. This is equivalent to the expression v1 = v1 / scalar.
Definition at line 217 of file VecOps.h.
00219 { 00220 for(unsigned i=0;i<SIZE;++i) 00221 { 00222 v1[i] /= scalar; 00223 } 00224 00225 return v1; 00226 } |
|
vector scalar division.
Definition at line 247 of file QuatOps.h.
00248 { 00249 return div( q, q, s ); 00250 } |
|
quotient of two quaternions.
Definition at line 212 of file QuatOps.h.
00213 { 00214 return div( result, result, q2 ); 00215 } |
|
matrix postmultiply. @PRE: args must both be n x n (this function is undefined otherwise) @POST: result' = result * operand Definition at line 182 of file MatrixOps.h.
00184 { 00185 return mult( result, result, operand ); 00186 } |
|
matrix preMultiply. @PRE: args must both be n x n (this function is undefined otherwise) @POST: result' = operand * result Definition at line 193 of file MatrixOps.h.
00195 { 00196 return mult( result, operand, result ); 00197 } |
|
Reflect a vector about a normal.
Definition at line 408 of file VecOps.h.
|
|
WARNING: not implemented (do not use).
Definition at line 492 of file QuatOps.h.
00493 { 00494 gmtlASSERT( false ); 00495 } |
|
vector subtraction.
Definition at line 290 of file QuatOps.h.
00291 { 00292 result[0] = q1[0] - q2[0]; 00293 result[1] = q1[1] - q2[1]; 00294 result[2] = q1[2] - q2[2]; 00295 result[3] = q1[3] - q2[3]; 00296 return result; 00297 } |
|
matrix subtraction (algebraic operation for matrix). @PRE: if lhs is m x n, and rhs is m x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n matrix @TODO: enforce the sizes with templates... Definition at line 143 of file MatrixOps.h.
00146 { 00147 // p. 150 Numerical Analysis (second ed.) 00148 // if A is m x n, and B is m x n, then AB is m x n 00149 // (A - B)ij = (a)ij - (b)ij (where: 1 <= i <= m, 1 <= j <= n) 00150 for (unsigned int i = 0; i < ROWS; ++i) // 1 <= i <= m 00151 for (unsigned int j = 0; j < COLS; ++j) // 1 <= j <= n 00152 result( i, j ) = lhs( i, j ) - rhs( i, j ); 00153 00154 return result; 00155 } |
|
matrix transpose from one type to another (i.e. 3x4 to 4x3) @PRE: source needs to be an M x N matrix, while dest needs to be N x M @POST: flip along diagonal Definition at line 265 of file MatrixOps.h.
00266 { 00267 // in case result is == source... :( 00268 Matrix<DATA_TYPE, COLS, ROWS> temp = source; 00269 00270 // p. 149 Numerical Analysis (second ed.) 00271 for (unsigned i = 0; i < ROWS; ++i) 00272 { 00273 for (unsigned j = 0; j < COLS; ++j) 00274 { 00275 result( i, j ) = temp( j, i ); 00276 } 00277 } 00278 00279 return result; 00280 } |
|
matrix transpose in place. @PRE: needs to be an N x N matrix @POST: flip along diagonal Definition at line 250 of file MatrixOps.h.
00251 { 00252 // p. 27 game programming gems #1 00253 for (unsigned c = 0; c < SIZE; ++c) 00254 for (unsigned r = c + 1; r < SIZE; ++r) 00255 std::swap( result( r, c ), result( c, r ) ); 00256 00257 return result; 00258 } |
|
Determines which side of the plane the given point lies with the given epsilon tolerance.
Definition at line 100 of file PlaneOps.h.
|
|
Determines which side of the plane the given point lies. This operation is done with ZERO tolerance.
Definition at line 75 of file PlaneOps.h.
|
|
zero out the matrix.
Definition at line 80 of file MatrixOps.h.
00081 { 00082 if (result.mState == Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY) 00083 { 00084 for (unsigned int x = 0; x < Math::Min( ROWS, COLS ); ++x) 00085 { 00086 result( x, x ) = (DATA_TYPE)0; 00087 } 00088 } 00089 else 00090 { 00091 for (unsigned int x = 0; x < ROWS*COLS; ++x) 00092 { 00093 result.mData[x] = (DATA_TYPE)0; 00094 } 00095 } 00096 return result; 00097 } |