From: <pat...@us...> - 2011-03-27 18:22:46
|
Revision: 1273 http://ggt.svn.sourceforge.net/ggt/?rev=1273&view=rev Author: patrickh Date: 2011-03-27 18:22:39 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Updated a bunch of old-style casts to be static_cast instead. There is still a huge amount of work left to do on this task. Modified Paths: -------------- trunk/gmtl/AxisAngle.h trunk/gmtl/Generate.h trunk/gmtl/Intersection.h trunk/gmtl/Matrix.h trunk/gmtl/MatrixOps.h trunk/gmtl/Point.h trunk/gmtl/Quat.h trunk/gmtl/QuatOps.h trunk/gmtl/Vec.h trunk/gmtl/VecOps.h trunk/gmtl/Xforms.h Modified: trunk/gmtl/AxisAngle.h =================================================================== --- trunk/gmtl/AxisAngle.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/AxisAngle.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -39,8 +39,10 @@ /** default constructor. initializes to identity rotation (no rotation). */ AxisAngle() : - VecBase<DATA_TYPE, 4>( (DATA_TYPE)0.0, (DATA_TYPE)1.0, - (DATA_TYPE)0.0, (DATA_TYPE)0.0 ) + VecBase<DATA_TYPE, 4>(static_cast<DATA_TYPE>(0.0), + static_cast<DATA_TYPE>(1.0), + static_cast<DATA_TYPE>(0.0), + static_cast<DATA_TYPE>(0.0)) { } Modified: trunk/gmtl/Generate.h =================================================================== --- trunk/gmtl/Generate.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Generate.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -186,7 +186,7 @@ gmtlASSERT( (Math::isEqual( lengthSquared( axisAngle.getAxis() ), (DATA_TYPE)1.0, (DATA_TYPE)0.0001 )) && "you must pass in a normalized vector to setRot( quat, rad, vec )" ); - DATA_TYPE half_angle = axisAngle.getAngle() * (DATA_TYPE)0.5; + DATA_TYPE half_angle = axisAngle.getAngle() * static_cast<DATA_TYPE>(0.5); DATA_TYPE sin_half_angle = Math::sin( half_angle ); result[Welt] = Math::cos( half_angle ); @@ -224,25 +224,25 @@ Quat<DATA_TYPE> qx, qy, qz; // precompute half angles - DATA_TYPE xOver2 = xRot * (DATA_TYPE)0.5; - DATA_TYPE yOver2 = yRot * (DATA_TYPE)0.5; - DATA_TYPE zOver2 = zRot * (DATA_TYPE)0.5; + DATA_TYPE xOver2 = xRot * static_cast<DATA_TYPE>(0.5); + DATA_TYPE yOver2 = yRot * static_cast<DATA_TYPE>(0.5); + DATA_TYPE zOver2 = zRot * static_cast<DATA_TYPE>(0.5); // set the pitch quat qx[Xelt] = Math::sin( xOver2 ); - qx[Yelt] = (DATA_TYPE)0.0; - qx[Zelt] = (DATA_TYPE)0.0; + qx[Yelt] = static_cast<DATA_TYPE>(0.0); + qx[Zelt] = static_cast<DATA_TYPE>(0.0); qx[Welt] = Math::cos( xOver2 ); // set the yaw quat - qy[Xelt] = (DATA_TYPE)0.0; + qy[Xelt] = static_cast<DATA_TYPE>(0.0); qy[Yelt] = Math::sin( yOver2 ); - qy[Zelt] = (DATA_TYPE)0.0; + qy[Zelt] = static_cast<DATA_TYPE>(0.0); qy[Welt] = Math::cos( yOver2 ); // set the roll quat - qz[Xelt] = (DATA_TYPE)0.0; - qz[Yelt] = (DATA_TYPE)0.0; + qz[Xelt] = static_cast<DATA_TYPE>(0.0); + qz[Yelt] = static_cast<DATA_TYPE>(0.0); qz[Zelt] = Math::sin( zOver2 ); qz[Welt] = Math::cos( zOver2 ); @@ -287,10 +287,10 @@ DATA_TYPE tr( mat( 0, 0 ) + mat( 1, 1 ) + mat( 2, 2 ) ), s( 0.0f ); // If diagonal is positive - if (tr > (DATA_TYPE)0.0) + if (tr > static_cast<DATA_TYPE>(0.0)) { - s = Math::sqrt( tr + (DATA_TYPE)1.0 ); - quat[Welt] = s * (DATA_TYPE)0.5; + s = Math::sqrt(tr + static_cast<DATA_TYPE>(1.0)); + quat[Welt] = s * static_cast<DATA_TYPE>(0.5); s = DATA_TYPE(0.5) / s; quat[Xelt] = (mat( 2, 1 ) - mat( 1, 2 )) * s; @@ -305,21 +305,27 @@ unsigned int i( Xelt ), j, k; if (mat( 1, 1 ) > mat( 0, 0 )) + { i = 1; + } if (mat( 2, 2 ) > mat( i, i )) + { i = 2; + } j = nxt[i]; k = nxt[j]; - s = Math::sqrt( (mat( i, i )-(mat( j, j )+mat( k, k ))) + (DATA_TYPE)1.0 ); + s = Math::sqrt((mat(i, i) - (mat(j, j) + mat( k, k ))) + static_cast<DATA_TYPE>(1.0)); DATA_TYPE q[4]; - q[i] = s * (DATA_TYPE)0.5; + q[i] = s * static_cast<DATA_TYPE>(0.5); - if (s != (DATA_TYPE)0.0) + if (s != static_cast<DATA_TYPE>(0.0)) + { s = DATA_TYPE(0.5) / s; + } q[3] = (mat( k, j ) - mat( j, k )) * s; q[j] = (mat( j, i ) + mat( i, j )) * s; @@ -360,24 +366,27 @@ * @post axisAngle = quat; */ template <typename DATA_TYPE> - inline AxisAngle<DATA_TYPE>& set( AxisAngle<DATA_TYPE>& axisAngle, Quat<DATA_TYPE> quat ) + inline AxisAngle<DATA_TYPE>& set(AxisAngle<DATA_TYPE>& axisAngle, + Quat<DATA_TYPE> quat) { // set sure we don't get a NaN result from acos... - if (Math::abs( quat[Welt] ) > (DATA_TYPE)1.0) + if (Math::abs(quat[Welt]) > static_cast<DATA_TYPE>(1.0)) { - gmtl::normalize( quat ); + gmtl::normalize(quat); } - gmtlASSERT( Math::abs( quat[Welt] ) <= (DATA_TYPE)1.0 && "acos returns NaN when quat[Welt] > 1, try normalizing your quat." ); + gmtlASSERT(Math::abs(quat[Welt]) <= static_cast<DATA_TYPE>(1.0) && + "acos returns NaN when quat[Welt] > 1, try normalizing your quat." ); + // [acos( w ) * 2.0, v / (asin( w ) * 2.0)] // set the angle - aCos is mathematically defined to be between 0 and PI - DATA_TYPE rad = Math::aCos( quat[Welt] ) * (DATA_TYPE)2.0; - axisAngle.setAngle( rad ); + DATA_TYPE rad = Math::aCos(quat[Welt]) * static_cast<DATA_TYPE>(2.0); + axisAngle.setAngle(rad); // set the axis: (use sin(rad) instead of asin(w)) - DATA_TYPE sin_half_angle = Math::sin( rad * (DATA_TYPE)0.5 ); - if (sin_half_angle >= (DATA_TYPE)0.0001) // because (PI >= rad >= 0) + DATA_TYPE sin_half_angle = Math::sin( rad * static_cast<DATA_TYPE>(0.5)); + if (sin_half_angle >= static_cast<DATA_TYPE>(0.0001)) // because (PI >= rad >= 0) { DATA_TYPE sin_half_angle_inv = DATA_TYPE(1.0) / sin_half_angle; Vec<DATA_TYPE, 3> axis( quat[Xelt] * sin_half_angle_inv, @@ -393,10 +402,13 @@ // one of the terms should be a 1, // so we can maintain unit-ness // in case w is 0 (which here w is 0) - axisAngle.setAxis( gmtl::Vec<DATA_TYPE, 3>( - DATA_TYPE( 1.0 ) /*- gmtl::Math::abs( quat[Welt] )*/, - (DATA_TYPE)0.0, - (DATA_TYPE)0.0 ) ); + axisAngle.setAxis( + gmtl::Vec<DATA_TYPE, 3>( + static_cast<DATA_TYPE>(1.0) /*- gmtl::Math::abs( quat[Welt] )*/, + static_cast<DATA_TYPE>(0.0), + static_cast<DATA_TYPE>(0.0) + ) + ); } return axisAngle; } @@ -1364,29 +1376,33 @@ inline DEST_TYPE& setRot( DEST_TYPE& result, const Vec<DATA_TYPE, 3>& from, const Vec<DATA_TYPE, 3>& to ) { // @todo should assert that DEST_TYPE::DataType == DATA_TYPE - const DATA_TYPE epsilon = (DATA_TYPE)0.00001; + const DATA_TYPE epsilon = static_cast<DATA_TYPE>(0.00001); - gmtlASSERT( gmtl::Math::isEqual( gmtl::length( from ), (DATA_TYPE)1.0, epsilon ) && - gmtl::Math::isEqual( gmtl::length( to ), (DATA_TYPE)1.0, epsilon ) /* && - "input params not normalized" */); + gmtlASSERT( + gmtl::Math::isEqual(gmtl::length(from), static_cast<DATA_TYPE>(1.0), epsilon) && + gmtl::Math::isEqual(gmtl::length(to), static_cast<DATA_TYPE>(1.0), epsilon ) /* && + "input params not normalized" */); - DATA_TYPE cosangle = dot( from, to ); + DATA_TYPE cosangle = dot(from, to); // if cosangle is close to 1, so the vectors are close to being coincident // Need to generate an angle of zero with any vector we like // We'll choose identity (no rotation) - if ( Math::isEqual( cosangle, (DATA_TYPE)1.0, epsilon ) ) + if (Math::isEqual(cosangle, static_cast<DATA_TYPE>(1.0), epsilon)) { return result = DEST_TYPE(); } // vectors are close to being opposite, so rotate one a little... - else if ( Math::isEqual( cosangle, (DATA_TYPE)-1.0, epsilon ) ) + else if (Math::isEqual(cosangle, static_cast<DATA_TYPE>(-1.0), epsilon)) { - Vec<DATA_TYPE, 3> to_rot( to[0] + (DATA_TYPE)0.3, to[1] - (DATA_TYPE)0.15, to[2] - (DATA_TYPE)0.15 ), axis; - normalize( cross( axis, from, to_rot ) ); // setRot requires normalized vec - DATA_TYPE angle = Math::aCos( cosangle ); - return setRot( result, gmtl::AxisAngle<DATA_TYPE>( angle, axis ) ); + Vec<DATA_TYPE, 3> to_rot(to[0] + static_cast<DATA_TYPE>(0.3), + to[1] - static_cast<DATA_TYPE>(0.15), + to[2] - static_cast<DATA_TYPE>(0.15)); + Vec<DATA_TYPE, 3> axis; + normalize(cross(axis, from, to_rot)); // setRot requires normalized vec + DATA_TYPE angle = Math::aCos(cosangle); + return setRot(result, gmtl::AxisAngle<DATA_TYPE>(angle, axis)); } // This is the usual situation - take a cross-product of vec1 and vec2 @@ -1394,9 +1410,9 @@ else { Vec<DATA_TYPE, 3> axis; - normalize( cross( axis, from, to ) ); // setRot requires normalized vec - DATA_TYPE angle = Math::aCos( cosangle ); - return setRot( result, gmtl::AxisAngle<DATA_TYPE>( angle, axis ) ); + normalize(cross(axis, from, to)); // setRot requires normalized vec + DATA_TYPE angle = Math::aCos(cosangle); + return setRot(result, gmtl::AxisAngle<DATA_TYPE>(angle, axis)); } } Modified: trunk/gmtl/Intersection.h =================================================================== --- trunk/gmtl/Intersection.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Intersection.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -696,9 +696,10 @@ * @return numhits, t0, t1 are undefined if return value is false */ template<typename T> - inline bool intersectVolume( const Sphere<T>& sphere, const Ray<T>& ray, int& numhits, T& t0, T& t1 ) + inline bool intersectVolume(const Sphere<T>& sphere, const Ray<T>& ray, + int& numhits, T& t0, T& t1) { - bool result = intersect( sphere, ray, numhits, t0, t1 ); + bool result = intersect(sphere, ray, numhits, t0, t1); if (result && numhits == 2) { return true; @@ -707,7 +708,7 @@ { const T rsq = sphere.getRadius() * sphere.getRadius(); const Vec<T, 3> dist = ray.getOrigin() - sphere.getCenter(); - const T a = lengthSquared( dist ) - rsq; + const T a = lengthSquared(dist) - rsq; bool inside = a <= T( 0 ); @@ -735,24 +736,29 @@ * @note If ray is parallel to plane: t=0, ret:true -> on plane, ret:false -> No hit */ template<class DATA_TYPE> - bool intersect( const Plane<DATA_TYPE>& plane, const Ray<DATA_TYPE>& ray, DATA_TYPE& t ) + bool intersect(const Plane<DATA_TYPE>& plane, const Ray<DATA_TYPE>& ray, + DATA_TYPE& t) { - const DATA_TYPE eps(0.00001f); + const DATA_TYPE eps(static_cast<DATA_TYPE>(0.00001)); // t = -(n\xB7P + d) - Vec<DATA_TYPE, 3> N( plane.getNormal() ); - DATA_TYPE denom( dot(N,ray.getDir()) ); - if(gmtl::Math::abs(denom) < eps) // Ray parallel to plane + Vec<DATA_TYPE, 3> N(plane.getNormal()); + DATA_TYPE denom(dot(N,ray.getDir())); + if (gmtl::Math::abs(denom) < eps) // Ray parallel to plane { t = 0; - if(distance(plane, ray.mOrigin) < eps) // Test for ray on plane - { return true; } + if (distance(plane, ray.mOrigin) < eps) // Test for ray on plane + { + return true; + } else - { return false; } + { + return false; + } } t = dot( N, Vec<DATA_TYPE,3>(N * plane.getOffset() - ray.getOrigin()) ) / denom; - return (DATA_TYPE)0 <= t; + return static_cast<DATA_TYPE>(0) <= t; } /** @@ -766,10 +772,11 @@ * @return true if the lineseg intersects the plane. */ template<class DATA_TYPE> - bool intersect( const Plane<DATA_TYPE>& plane, const LineSeg<DATA_TYPE>& seg, DATA_TYPE& t ) + bool intersect(const Plane<DATA_TYPE>& plane, + const LineSeg<DATA_TYPE>& seg, DATA_TYPE& t ) { bool res(intersect(plane, static_cast<Ray<DATA_TYPE> >(seg), t)); - return res && t <= (DATA_TYPE)1.0; + return res && t <= static_cast<DATA_TYPE>(1.0); } /** @@ -785,10 +792,10 @@ * @see from http://www.acm.org/jgt/papers/MollerTrumbore97/code.html */ template<class DATA_TYPE> - bool intersect( const Tri<DATA_TYPE>& tri, const Ray<DATA_TYPE>& ray, - float& u, float& v, float& t ) + bool intersect(const Tri<DATA_TYPE>& tri, const Ray<DATA_TYPE>& ray, + float& u, float& v, float& t) { - const float EPSILON = (DATA_TYPE)0.00001f; + const float EPSILON = static_cast<DATA_TYPE>(0.00001); Vec<DATA_TYPE, 3> edge1, edge2, tvec, pvec, qvec; float det,inv_det; @@ -800,36 +807,42 @@ gmtl::cross( pvec, ray.getDir(), edge2 ); /* if determinant is near zero, ray lies in plane of triangle */ - det = gmtl::dot( edge1, pvec ); + det = gmtl::dot(edge1, pvec); if (det < EPSILON) + { return false; + } /* calculate distance from vert0 to ray origin */ tvec = ray.getOrigin() - tri[0]; /* calculate U parameter and test bounds */ - u = gmtl::dot( tvec, pvec ); + u = gmtl::dot(tvec, pvec); if (u < 0.0 || u > det) + { return false; + } /* prepare to test V parameter */ - gmtl::cross( qvec, tvec, edge1 ); + gmtl::cross(qvec, tvec, edge1); /* calculate V parameter and test bounds */ v = gmtl::dot( ray.getDir(), qvec ); if (v < 0.0 || u + v > det) + { return false; + } /* calculate t, scale parameters, ray intersects triangle */ t = gmtl::dot( edge2, qvec ); - inv_det = ((DATA_TYPE)1.0) / det; + inv_det = static_cast<DATA_TYPE>(1.0) / det; t *= inv_det; u *= inv_det; v *= inv_det; // test if t is within the ray boundary (when t >= 0) - return t >= (DATA_TYPE)0; + return t >= static_cast<DATA_TYPE>(0); } /** @@ -849,10 +862,11 @@ * @see from http://www.acm.org/jgt/papers/MollerTrumbore97/code.html */ template<class DATA_TYPE> - bool intersectDoubleSided(const Tri<DATA_TYPE>& tri, const Ray<DATA_TYPE>& ray, + bool intersectDoubleSided(const Tri<DATA_TYPE>& tri, + const Ray<DATA_TYPE>& ray, DATA_TYPE& u, DATA_TYPE& v, DATA_TYPE& t) { - const DATA_TYPE EPSILON = (DATA_TYPE)0.00001f; + const DATA_TYPE EPSILON = static_cast<DATA_TYPE>(0.00001); Vec<DATA_TYPE, 3> edge1, edge2, tvec, pvec, qvec; DATA_TYPE det, inv_det; @@ -875,7 +889,7 @@ tvec = ray.getOrigin() - tri[0]; // Calc inverse deteriminant. - inv_det = ((DATA_TYPE)1.0) / det; + inv_det = static_cast<DATA_TYPE>(1.0) / det; // Calculate U parameter and test bounds. u = inv_det * gmtl::dot(tvec, pvec); @@ -898,7 +912,7 @@ t = inv_det * gmtl::dot(edge2, qvec); // Test if t is within the ray boundary (when t >= 0). - return t >= (DATA_TYPE)0; + return t >= static_cast<DATA_TYPE>(0); } /** @@ -917,16 +931,19 @@ bool intersect( const Tri<DATA_TYPE>& tri, const LineSeg<DATA_TYPE>& lineseg, DATA_TYPE& u, DATA_TYPE& v, DATA_TYPE& t ) { - const DATA_TYPE eps = (DATA_TYPE)0.0001010101; - DATA_TYPE l = length( lineseg.getDir() ); + const DATA_TYPE eps = static_cast<DATA_TYPE>(0.0001010101); + const DATA_TYPE l = length(lineseg.getDir()); + if (eps < l) { - Ray<DATA_TYPE> temp( lineseg.getOrigin(), lineseg.getDir() ); - bool result = intersect( tri, temp, u, v, t ); - return result && t <= (DATA_TYPE)1.0; + Ray<DATA_TYPE> temp(lineseg.getOrigin(), lineseg.getDir()); + const bool result = intersect(tri, temp, u, v, t); + return result && t <= static_cast<DATA_TYPE>(1.0); } else - { return false; } + { + return false; + } } /** Modified: trunk/gmtl/Matrix.h =================================================================== --- trunk/gmtl/Matrix.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Matrix.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -216,12 +216,16 @@ for (unsigned int r = 0; r < ROWS; ++r) { for (unsigned int c = 0; c < COLS; ++c) - { this->operator()( r, c ) = (DATA_TYPE)0.0; } + { + this->operator()(r, c) = static_cast<DATA_TYPE>(0.0); + } } /** @todo mp */ - for (unsigned int x = 0; x < Math::Min( COLS, ROWS ); ++x) - { this->operator()( x, x ) = (DATA_TYPE)1.0; } + for (unsigned int x = 0; x < Math::Min(COLS, ROWS); ++x) + { + this->operator()(x, x) = static_cast<DATA_TYPE>(1.0); + } /** @todo Set initial state to IDENTITY and test other stuff */ mState = IDENTITY; @@ -458,7 +462,10 @@ /** Gets a DATA_TYPE pointer to the matrix data. * @return Returns a pointer to the head of the matrix data. */ - const DATA_TYPE* getData() const { return (DATA_TYPE*)mData; } + const DATA_TYPE* getData() const + { + return mData; + } bool isError() { @@ -469,8 +476,10 @@ mState |= XFORM_ERROR; } - void setState(int state) - { mState = state; } + void setState(const int state) + { + mState = state; + } public: /** Column major. In other words {Column1, Column2, Column3, Column4} in memory Modified: trunk/gmtl/MatrixOps.h =================================================================== --- trunk/gmtl/MatrixOps.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/MatrixOps.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -21,22 +21,32 @@ * @{ */ - /** Make identity matrix out the matrix. - * @post Every element is 0 except the matrix's diagonal, whose elements are 1. + /** + * Makes identity matrix out the matrix. + * + * @post Every element is 0 except the matrix's diagonal, whose elements + * are 1. */ template <typename DATA_TYPE, unsigned ROWS, unsigned COLS> - inline Matrix<DATA_TYPE, ROWS, COLS>& identity( Matrix<DATA_TYPE, ROWS, COLS>& result ) + inline Matrix<DATA_TYPE, ROWS, COLS>& + identity(Matrix<DATA_TYPE, ROWS, COLS>& result) { if(result.mState != Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY) // if not already ident { // TODO: mp for (unsigned int r = 0; r < ROWS; ++r) - for (unsigned int c = 0; c < COLS; ++c) - result( r, c ) = (DATA_TYPE)0.0; + { + for (unsigned int c = 0; c < COLS; ++c) + { + result(r, c) = static_cast<DATA_TYPE>(0.0); + } + } // TODO: mp - for (unsigned int x = 0; x < Math::Min( COLS, ROWS ); ++x) - result( x, x ) = (DATA_TYPE)1.0; + for (unsigned int x = 0; x < Math::Min(COLS, ROWS); ++x) + { + result(x, x) = static_cast<DATA_TYPE>(1.0); + } result.mState = Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY; // result.mState = Matrix<DATA_TYPE, ROWS, COLS>::FULL; @@ -45,25 +55,27 @@ return result; } - - /** zero out the matrix. + /** + * Zero out the matrix. + * * @post every element is 0. */ template <typename DATA_TYPE, unsigned ROWS, unsigned COLS> - inline Matrix<DATA_TYPE, ROWS, COLS>& zero( Matrix<DATA_TYPE, ROWS, COLS>& result ) + inline Matrix<DATA_TYPE, ROWS, COLS>& + zero(Matrix<DATA_TYPE, ROWS, COLS>& result) { if (result.mState == Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY) { - for (unsigned int x = 0; x < Math::Min( ROWS, COLS ); ++x) + for (unsigned int x = 0; x < Math::Min(ROWS, COLS); ++x) { - result( x, x ) = (DATA_TYPE)0; + result(x, x) = static_cast<DATA_TYPE>(0); } } else { - for (unsigned int x = 0; x < ROWS*COLS; ++x) + for (unsigned int x = 0; x < ROWS * COLS; ++x) { - result.mData[x] = (DATA_TYPE)0; + result.mData[x] = static_cast<DATA_TYPE>(0); } } result.mState = Matrix<DATA_TYPE, ROWS, COLS>::ORTHOGONAL; @@ -543,7 +555,8 @@ for ( j = 0; j < n; j++ ) { m[ i][ j] = a[ i * n + j]; - m[ i][ j + n] = ( i == j ) ? (DATA_TYPE)1.0 : (DATA_TYPE)0.0 ; + m[ i][ j + n] = ( i == j ) ? static_cast<DATA_TYPE>(1.0) + : static_cast<DATA_TYPE>(0.0); } } @@ -580,38 +593,56 @@ } /* Normalization */ - for ( j = 0; j < 2*n; j++ ) + for (j = 0; j < 2 * n; ++j) { - if ( j == c[ k] ) - m[ r[ k]][ j] = (DATA_TYPE)1.0; + if (j == c[k]) + { + m[r[k]][j] = static_cast<DATA_TYPE>(1.0); + } else - m[ r[ k]][ j] /= pivot; + { + m[r[k]][j] /= pivot; + } } /* Reduction */ - for ( i = 0; i < n; i++ ) + for (i = 0; i < n; ++i) { - if ( i == r[ k] ) + if (i == r[k]) + { continue; + } - for ( j=0, fac = m[ i][ c[k]]; j < 2*n; j++ ) + for (j = 0, fac = m[i][c[k]]; j < 2 * n; ++j) { - if ( j == c[ k] ) - m[ i][ j] = (DATA_TYPE)0.0; + if (j == c[k]) + { + m[i][j] = static_cast<DATA_TYPE>(0.0); + } else - m[ i][ j] -= fac * m[ r[k]][ j]; + { + m[i][j] -= fac * m[r[k]][j]; + } } } } /* Assign inverse to a matrix */ - for ( i = 0; i < n; i++ ) - for ( j = 0; j < n; j++ ) - row[ i] = ( c[ j] == i ) ? r[ j] : row[ i]; + for (i = 0; i < n; ++i) + { + for (j = 0; j < n; ++j) + { + row[i] = (c[j] == i) ? r[j] : row[i]; + } + } - for ( i = 0; i < n; i++ ) - for ( j = 0; j < n; j++ ) - b[ i * n + j] = m[ row[ i]][ j + n]; + for (i = 0; i < n; ++i) + { + for (j = 0; j < n; ++j) + { + b[i * n + j] = m[row[i]][j + n]; + } + } // It worked result.mState = src.mState; @@ -677,16 +708,22 @@ * @{ */ - /** Tests 2 matrices for equality - * @param lhs The first matrix - * @param rhs The second matrix - * @pre Both matrices must be of the same size. - * @return true if the matrices have the same element values; false otherwise + /** + * Tests 2 matrices for equality. + * + * @pre Both matrices must be of the same size. + * + * @param lhs The first matrix. + * @param rhs The second matrix. + * + * @return true if the matrices have the same element values; false + * otherwise. */ template <typename DATA_TYPE, unsigned ROWS, unsigned COLS> - inline bool operator==( const Matrix<DATA_TYPE, ROWS, COLS>& lhs, const Matrix<DATA_TYPE, ROWS, COLS>& rhs ) + inline bool operator==(const Matrix<DATA_TYPE, ROWS, COLS>& lhs, + const Matrix<DATA_TYPE, ROWS, COLS>& rhs) { - for (unsigned int i = 0; i < ROWS*COLS; ++i) + for (unsigned int i = 0; i < ROWS * COLS; ++i) { if (lhs.mData[i] != rhs.mData[i]) { @@ -703,16 +740,21 @@ */ } - /** Tests 2 matrices for inequality - * @param lhs The first matrix - * @param rhs The second matrix - * @pre Both matrices must be of the same size. - * @return false if the matrices differ on any element value; true otherwise + /** + * Tests 2 matrices for inequality. + * + * @pre Both matrices must be of the same size. + * + * @param lhs The first matrix. + * @param rhs The second matrix. + * + * @return false if the matrices differ on any element value; true otherwise. */ template <typename DATA_TYPE, unsigned ROWS, unsigned COLS> - inline bool operator!=( const Matrix<DATA_TYPE, ROWS, COLS>& lhs, const Matrix<DATA_TYPE, ROWS, COLS>& rhs ) + inline bool operator!=(const Matrix<DATA_TYPE, ROWS, COLS>& lhs, + const Matrix<DATA_TYPE, ROWS, COLS>& rhs) { - return bool( !(lhs == rhs) ); + return ! (lhs == rhs); } /** Tests 2 matrices for equality within a tolerance Modified: trunk/gmtl/Point.h =================================================================== --- trunk/gmtl/Point.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Point.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -42,8 +42,10 @@ */ Point() { - for (unsigned i = 0; i < SIZE; ++i) - this->mData[i] = (DATA_TYPE)0; + for (unsigned int i = 0; i < SIZE; ++i) + { + this->mData[i] = static_cast<DATA_TYPE>(0); + } } /** @name Value constructors Modified: trunk/gmtl/Quat.h =================================================================== --- trunk/gmtl/Quat.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Quat.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -58,7 +58,8 @@ * NOTE: the addition identity is [0,0,0,0] */ Quat() - : mData( (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)1.0 ) + : mData(static_cast<DATA_TYPE>(0.0), static_cast<DATA_TYPE>(0.0), + static_cast<DATA_TYPE>(0.0), static_cast<DATA_TYPE>(1.0)) { } @@ -138,7 +139,10 @@ /** Get a DATA_TYPE pointer to the quat internal data. * @post Returns a ptr to the head of the quat data */ - const DATA_TYPE* getData() const { return (DATA_TYPE*)mData.getData();} + const DATA_TYPE* getData() const + { + return mData.getData(); + } public: // Order x, y, z, w Modified: trunk/gmtl/QuatOps.h =================================================================== --- trunk/gmtl/QuatOps.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/QuatOps.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -334,15 +334,17 @@ * @see Quat */ template <typename DATA_TYPE> - Quat<DATA_TYPE>& normalize( Quat<DATA_TYPE>& result ) + Quat<DATA_TYPE>& normalize(Quat<DATA_TYPE>& result) { - DATA_TYPE l = length( result ); + DATA_TYPE l = length(result); // return if no magnitude (already as normalized as possible) - if (l < (DATA_TYPE)0.0001) + if (l < static_cast<DATA_TYPE>(0.0001)) + { return result; + } - DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l; + DATA_TYPE l_inv = static_cast<DATA_TYPE>(1.0) / l; result[Xelt] *= l_inv; result[Yelt] *= l_inv; result[Zelt] *= l_inv; @@ -361,9 +363,9 @@ * @return true if the quaternion is normalized, false otherwise */ template< typename DATA_TYPE > - bool isNormalized( const Quat<DATA_TYPE>& q1, const DATA_TYPE eps = 0.0001f ) + bool isNormalized(const Quat<DATA_TYPE>& q1, const DATA_TYPE eps = 0.0001f) { - return Math::isEqual( lengthSquared( q1 ), DATA_TYPE(1), eps ); + return Math::isEqual(lengthSquared(q1), DATA_TYPE(1), eps); } /** quaternion complex conjugate. @@ -387,18 +389,20 @@ * @see Quat */ template <typename DATA_TYPE> - Quat<DATA_TYPE>& invert( Quat<DATA_TYPE>& result ) + Quat<DATA_TYPE>& invert(Quat<DATA_TYPE>& result) { // from game programming gems p198 // do result = conj( q ) / norm( q ) - conj( result ); + conj(result); // return if norm() is near 0 (divide by 0 would result in NaN) - DATA_TYPE l = lengthSquared( result ); - if (l < (DATA_TYPE)0.0001) + DATA_TYPE l = lengthSquared(result); + if (l < static_cast<DATA_TYPE>(0.0001)) + { return result; + } - DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l; + DATA_TYPE l_inv = static_cast<DATA_TYPE>(1.0) / l; result[Xelt] *= l_inv; result[Yelt] *= l_inv; result[Zelt] *= l_inv; @@ -412,17 +416,21 @@ * @see Quat */ template <typename DATA_TYPE> - Quat<DATA_TYPE>& exp( Quat<DATA_TYPE>& result ) + Quat<DATA_TYPE>& exp(Quat<DATA_TYPE>& result) { DATA_TYPE len1, len2; - len1 = Math::sqrt( result[Xelt] * result[Xelt] + - result[Yelt] * result[Yelt] + - result[Zelt] * result[Zelt] ); - if (len1 > (DATA_TYPE)0.0) - len2 = Math::sin( len1 ) / len1; + len1 = Math::sqrt(result[Xelt] * result[Xelt] + + result[Yelt] * result[Yelt] + + result[Zelt] * result[Zelt]); + if (len1 > static_cast<DATA_TYPE>(0.0)) + { + len2 = Math::sin(len1) / len1; + } else - len2 = (DATA_TYPE)1.0; + { + len2 = static_cast<DATA_TYPE>(1.0); + } result[Xelt] = result[Xelt] * len2; result[Yelt] = result[Yelt] * len2; @@ -446,12 +454,16 @@ result[Zelt] * result[Zelt] ); // avoid divide by 0 - if (Math::isEqual( result[Welt], (DATA_TYPE)0.0, (DATA_TYPE)0.00001 ) == false) - length = Math::aTan( length / result[Welt] ); + if (Math::isEqual(result[Welt], static_cast<DATA_TYPE>(0.0), static_cast<DATA_TYPE>(0.00001)) == false) + { + length = Math::aTan(length / result[Welt]); + } else + { length = Math::PI_OVER_2; + } - result[Welt] = (DATA_TYPE)0.0; + result[Welt] = static_cast<DATA_TYPE>(0.0); result[Xelt] = result[Xelt] * length; result[Yelt] = result[Yelt] * length; result[Zelt] = result[Zelt] * length; @@ -494,7 +506,10 @@ * @see Quat */ template <typename DATA_TYPE> - Quat<DATA_TYPE>& slerp( Quat<DATA_TYPE>& result, const DATA_TYPE t, const Quat<DATA_TYPE>& from, const Quat<DATA_TYPE>& to, bool adjustSign=true) + Quat<DATA_TYPE>& slerp(Quat<DATA_TYPE>& result, const DATA_TYPE t, + const Quat<DATA_TYPE>& from, + const Quat<DATA_TYPE>& to, + const bool adjustSign = true) { const Quat<DATA_TYPE>& p = from; // just an alias to match q @@ -503,7 +518,7 @@ // adjust signs (if necessary) Quat<DATA_TYPE> q; - if (adjustSign && (cosom < (DATA_TYPE)0.0)) + if (adjustSign && (cosom < static_cast<DATA_TYPE>(0.0))) { cosom = -cosom; q[0] = -to[0]; // Reverse all signs @@ -518,19 +533,19 @@ // Calculate coefficients DATA_TYPE sclp, sclq; - if (((DATA_TYPE)1.0 - cosom) > (DATA_TYPE)0.0001) // 0.0001 -> some epsillon + if ((static_cast<DATA_TYPE>(1.0) - cosom) > static_cast<DATA_TYPE>(0.0001)) // 0.0001 -> some epsillo)n { // Standard case (slerp) DATA_TYPE omega, sinom; - omega = gmtl::Math::aCos( cosom ); // extract theta from dot product's cos theta - sinom = gmtl::Math::sin( omega ); - sclp = gmtl::Math::sin( ((DATA_TYPE)1.0 - t) * omega ) / sinom; - sclq = gmtl::Math::sin( t * omega ) / sinom; + omega = Math::aCos(cosom); // extract theta from dot product's cos theta + sinom = Math::sin(omega ); + sclp = Math::sin((static_cast<DATA_TYPE>(1.0) - t) * omega ) / sinom; + sclq = Math::sin(t * omega ) / sinom; } else { // Very close, do linear interp (because it's faster) - sclp = (DATA_TYPE)1.0 - t; + sclp = static_cast<DATA_TYPE>(1.0) - t; sclq = t; } @@ -551,7 +566,9 @@ * @see Quat */ template <typename DATA_TYPE> - Quat<DATA_TYPE>& lerp( Quat<DATA_TYPE>& result, const DATA_TYPE t, const Quat<DATA_TYPE>& from, const Quat<DATA_TYPE>& to) + Quat<DATA_TYPE>& lerp(Quat<DATA_TYPE>& result, const DATA_TYPE t, + const Quat<DATA_TYPE>& from, + const Quat<DATA_TYPE>& to) { // just an alias to match q const Quat<DATA_TYPE>& p = from; @@ -561,7 +578,7 @@ // adjust signs (if necessary) Quat<DATA_TYPE> q; - if (cosom < (DATA_TYPE)0.0) + if (cosom < static_cast<DATA_TYPE>(0.0)) { q[0] = -to[0]; // Reverse all signs q[1] = -to[1]; @@ -575,7 +592,7 @@ // do linear interp DATA_TYPE sclp, sclq; - sclp = (DATA_TYPE)1.0 - t; + sclp = static_cast<DATA_TYPE>(1.0) - t; sclq = t; result[Xelt] = sclp * p[Xelt] + sclq * q[Xelt]; Modified: trunk/gmtl/Vec.h =================================================================== --- trunk/gmtl/Vec.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Vec.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -50,8 +50,10 @@ */ Vec() { - for (unsigned i = 0; i < SIZE; ++i) - this->mData[i] = (DATA_TYPE)0; + for (unsigned int i = 0; i < SIZE; ++i) + { + this->mData[i] = static_cast<DATA_TYPE>(0); + } } /// @name Value constructors Modified: trunk/gmtl/VecOps.h =================================================================== --- trunk/gmtl/VecOps.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/VecOps.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -182,9 +182,9 @@ VecBase<DATA_TYPE, SIZE>& operator *=(VecBase<DATA_TYPE, SIZE>& v1, const SCALAR_TYPE& scalar) { - for(unsigned i=0;i<SIZE;++i) + for (unsigned int i = 0; i < SIZE; ++i) { - v1[i] *= (DATA_TYPE)scalar; + v1[i] *= static_cast<DATA_TYPE>(scalar); } return v1; @@ -435,10 +435,10 @@ * @return true if the vector is normalized, false otherwise */ template< class DATA_TYPE, unsigned SIZE > -bool isNormalized( const Vec<DATA_TYPE, SIZE>& v1, - const DATA_TYPE eps = (DATA_TYPE) 0.0001f ) +bool isNormalized(const Vec<DATA_TYPE, SIZE>& v1, + const DATA_TYPE eps = static_cast<DATA_TYPE>(0.0001)) { - return Math::isEqual( lengthSquared( v1 ), DATA_TYPE(1.0), eps ); + return Math::isEqual(lengthSquared(v1), DATA_TYPE(1.0), eps); } /** @@ -492,7 +492,7 @@ VecBase<DATA_TYPE, SIZE>& vec, const Vec<DATA_TYPE, SIZE>& normal ) { - result = vec - (DATA_TYPE( 2.0 ) * (dot( (Vec<DATA_TYPE, SIZE>)vec, normal ) * normal)); + result = vec - (DATA_TYPE(2.0) * (dot(static_cast<Vec<DATA_TYPE, SIZE> >(vec), normal) * normal)); return result; } Modified: trunk/gmtl/Xforms.h =================================================================== --- trunk/gmtl/Xforms.h 2011-03-27 18:11:00 UTC (rev 1272) +++ trunk/gmtl/Xforms.h 2011-03-27 18:22:39 UTC (rev 1273) @@ -37,10 +37,12 @@ * then this might not give the correct result, since conj and invert is only equiv when normalized... */ template <typename DATA_TYPE> - inline VecBase<DATA_TYPE, 3>& xform( VecBase<DATA_TYPE, 3>& result, const Quat<DATA_TYPE>& rot, const VecBase<DATA_TYPE, 3>& vector ) + inline VecBase<DATA_TYPE, 3>& xform(VecBase<DATA_TYPE, 3>& result, + const Quat<DATA_TYPE>& rot, + const VecBase<DATA_TYPE, 3>& vector) { // check preconditions... - gmtlASSERT( Math::isEqual( length( rot ), (DATA_TYPE)1.0, (DATA_TYPE)0.0001 ) && "must pass a rotation quaternion to xform(result,quat,vec) - by definition, a rotation quaternion is normalized). if you need non-rotation quaternion support, let us know." ); + gmtlASSERT(Math::isEqual(length(rot), static_cast<DATA_TYPE>(1.0), static_cast<DATA_TYPE>(0.0001)) && "must pass a rotation quaternion to xform(result,quat,vec) - by definition, a rotation quaternion is normalized). if you need non-rotation quaternion support, let us know."); // easiest to write and understand (slowest too) //return result_vec = makeVec( rot * makePure( vector ) * makeConj( rot ) ); @@ -48,18 +50,21 @@ // completely hand expanded // (faster by 28% in gcc 2.96 debug mode.) // (faster by 35% in gcc 2.96 opt3 mode (78% for doubles)) - Quat<DATA_TYPE> rot_conj( -rot[Xelt], -rot[Yelt], -rot[Zelt], rot[Welt] ); - Quat<DATA_TYPE> pure( vector[0], vector[1], vector[2], (DATA_TYPE)0.0 ); + Quat<DATA_TYPE> rot_conj(-rot[Xelt], -rot[Yelt], -rot[Zelt], rot[Welt]); + Quat<DATA_TYPE> pure(vector[0], vector[1], vector[2], + static_cast<DATA_TYPE>(0.0)); Quat<DATA_TYPE> temp( pure[Welt]*rot_conj[Xelt] + pure[Xelt]*rot_conj[Welt] + pure[Yelt]*rot_conj[Zelt] - pure[Zelt]*rot_conj[Yelt], pure[Welt]*rot_conj[Yelt] + pure[Yelt]*rot_conj[Welt] + pure[Zelt]*rot_conj[Xelt] - pure[Xelt]*rot_conj[Zelt], pure[Welt]*rot_conj[Zelt] + pure[Zelt]*rot_conj[Welt] + pure[Xelt]*rot_conj[Yelt] - pure[Yelt]*rot_conj[Xelt], - pure[Welt]*rot_conj[Welt] - pure[Xelt]*rot_conj[Xelt] - pure[Yelt]*rot_conj[Yelt] - pure[Zelt]*rot_conj[Zelt] ); + pure[Welt]*rot_conj[Welt] - pure[Xelt]*rot_conj[Xelt] - pure[Yelt]*rot_conj[Yelt] - pure[Zelt]*rot_conj[Zelt] + ); result.set( rot[Welt]*temp[Xelt] + rot[Xelt]*temp[Welt] + rot[Yelt]*temp[Zelt] - rot[Zelt]*temp[Yelt], rot[Welt]*temp[Yelt] + rot[Yelt]*temp[Welt] + rot[Zelt]*temp[Xelt] - rot[Xelt]*temp[Zelt], - rot[Welt]*temp[Zelt] + rot[Zelt]*temp[Welt] + rot[Xelt]*temp[Yelt] - rot[Yelt]*temp[Xelt] ); + rot[Welt]*temp[Zelt] + rot[Zelt]*temp[Welt] + rot[Xelt]*temp[Yelt] - rot[Yelt]*temp[Xelt] + ); return result; } @@ -162,26 +167,35 @@ // copy the point to the correct size. Vec<DATA_TYPE, COLS> temp_vector, temp_result; - for (unsigned x = 0; x < VEC_SIZE; ++x) + for (unsigned int x = 0; x < VEC_SIZE; ++x) + { temp_vector[x] = vector[x]; - temp_vector[COLS-1] = (DATA_TYPE)0.0; // by definition of a vector, set the last unspecified elt to 0.0 + } + // by definition of a vector, set the last unspecified elt to 0.0 + temp_vector[COLS-1] = static_cast<DATA_TYPE>(0.0); + // transform it. xform<DATA_TYPE, ROWS, COLS>( temp_result, matrix, temp_vector ); // convert result back to vec<DATA_TYPE, VEC_SIZE> - // some matrices will make the W param large even if this is a true vector, - // we'll need to redistribute it to the other elts if W param is non-zero - if (Math::isEqual( temp_result[VEC_SIZE], (DATA_TYPE)0, (DATA_TYPE)0.0001 ) == false) + // some matrices will make the W param large even if this is a true + // vector, we'll need to redistribute it to the other elts if W param is + // non-zero + if (Math::isEqual(temp_result[VEC_SIZE], static_cast<DATA_TYPE>(0), static_cast<DATA_TYPE>(0.0001)) == false) { - DATA_TYPE w_coord_div = DATA_TYPE( 1.0 ) / temp_result[VEC_SIZE]; - for (unsigned x = 0; x < VEC_SIZE; ++x) + DATA_TYPE w_coord_div = DATA_TYPE(1.0) / temp_result[VEC_SIZE]; + for (unsigned int x = 0; x < VEC_SIZE; ++x) + { result[x] = temp_result[x] * w_coord_div; + } } else { - for (unsigned x = 0; x < VEC_SIZE; ++x) + for (unsigned int x = 0; x < VEC_SIZE; ++x) + { result[x] = temp_result[x]; + } } return result; @@ -267,27 +281,35 @@ GMTL_STATIC_ASSERT( PNT_SIZE == COLS-1, Point_not_of_size_mat_col_minus_1_as_required_for_xform); // copy the point to the correct size. - Point<DATA_TYPE, PNT_SIZE+1> temp_point, temp_result; - for (unsigned x = 0; x < PNT_SIZE; ++x) + Point<DATA_TYPE, PNT_SIZE + 1> temp_point, temp_result; + for (unsigned int x = 0; x < PNT_SIZE; ++x) + { temp_point[x] = point[x]; - temp_point[PNT_SIZE] = (DATA_TYPE)1.0; // by definition of a point, set the last unspecified elt to 1.0 + } + // by definition of a point, set the last unspecified elt to 1.0 + temp_point[PNT_SIZE] = static_cast<DATA_TYPE>(1.0); // transform it. xform<DATA_TYPE, ROWS, COLS>( temp_result, matrix, temp_point ); // convert result back to pnt<DATA_TYPE, PNT_SIZE> - // some matrices will make the W param large even if this is a true vector, - // we'll need to redistribute it to the other elts if W param is non-zero - if (Math::isEqual( temp_result[PNT_SIZE], (DATA_TYPE)0, (DATA_TYPE)0.0001 ) == false) + // some matrices will make the W param large even if this is a true + // vector, we'll need to redistribute it to the other elts if W param is + // non-zero + if (Math::isEqual(temp_result[PNT_SIZE], static_cast<DATA_TYPE>(0), static_cast<DATA_TYPE>(0.0001)) == false) { - DATA_TYPE w_coord_div = DATA_TYPE( 1.0 ) / temp_result[PNT_SIZE]; - for (unsigned x = 0; x < PNT_SIZE; ++x) + DATA_TYPE w_coord_div = DATA_TYPE(1.0) / temp_result[PNT_SIZE]; + for (unsigned int x = 0; x < PNT_SIZE; ++x) + { result[x] = temp_result[x] * w_coord_div; + } } else { - for (unsigned x = 0; x < PNT_SIZE; ++x) + for (unsigned int x = 0; x < PNT_SIZE; ++x) + { result[x] = temp_result[x]; + } } return result; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |