[Opal-commits] opal/src Matrix44r.h,1.33,1.34 OpalMath.h,1.11,1.12 Solid.cpp,1.34,1.35 Vec3r.h,1.16,
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-04-27 02:28:27
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2054/src Modified Files: Matrix44r.h OpalMath.h Solid.cpp Vec3r.h Log Message: fixed bug in one of the Matrix44r invert function (the one that wasn't being used anywhere); added a smart tolerance-checking function Index: Vec3r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Vec3r.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Vec3r.h 18 Apr 2005 22:21:04 -0000 1.16 --- Vec3r.h 27 Apr 2005 02:28:18 -0000 1.17 *************** *** 58,63 **** inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v); ! /// Returns true if the two vectors are roughly collinear (within some ! /// epsilon). inline bool areCollinear(const Vec3r& u, const Vec3r& v); --- 58,62 ---- inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v); ! /// Returns true if the two vectors are roughly collinear. inline bool areCollinear(const Vec3r& u, const Vec3r& v); *************** *** 301,305 **** { real value = 1 - dot(u, v); ! if (opal::abs(value) < globals::OPAL_EPSILON) { return true; --- 300,304 ---- { real value = 1 - dot(u, v); ! if (areEqual(value, 0)) { return true; Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Solid.cpp 18 Apr 2005 22:21:04 -0000 1.34 --- Solid.cpp 27 Apr 2005 02:28:18 -0000 1.35 *************** *** 180,184 **** { if (mData.enabled && !mData.isStatic && ! f.vec.lengthSquared() > globals::OPAL_EPSILON ) { mForceList.push_back(f); --- 180,184 ---- { if (mData.enabled && !mData.isStatic && ! !areEqual(f.vec.lengthSquared(), 0)) { mForceList.push_back(f); Index: Matrix44r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Matrix44r.h,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Matrix44r.h 18 Apr 2005 22:21:03 -0000 1.33 --- Matrix44r.h 27 Apr 2005 02:28:18 -0000 1.34 *************** *** 275,279 **** real trace = (*this)(0,0) + (*this)(1,1) + (*this)(2,2) + 1.0f; ! if(trace > globals::OPAL_EPSILON) { real s = 0.5f / sqrt(trace); --- 275,279 ---- real trace = (*this)(0,0) + (*this)(1,1) + (*this)(2,2) + 1.0f; ! if(!areEqual(trace, 0)) { real s = 0.5f / sqrt(trace); *************** *** 517,524 **** inline bool inverse(Matrix44r & dest, const Matrix44r & src) { - std::cerr << "opal::Matrix44r inverse is hella busted! use \ - fastInverse for affine transforms" << std::endl; real det = src.determinant(); ! if(opal::abs(det < globals::OPAL_EPSILON)) return false; dest = ((real)1.0 / det) * src; return true; --- 517,525 ---- inline bool inverse(Matrix44r & dest, const Matrix44r & src) { real det = src.determinant(); ! if(areEqual(det, 0)) ! { ! return false; ! } dest = ((real)1.0 / det) * src; return true; *************** *** 534,540 **** // original matrix. for (int x = 0; x < 3; ++x) - for (int y = 0; y < 3; ++y) { ! result(x,y) = src(y,x); } --- 535,543 ---- // original matrix. for (int x = 0; x < 3; ++x) { ! for (int y = 0; y < 3; ++y) ! { ! result(x,y) = src(y,x); ! } } *************** *** 546,552 **** result(2, 2)).lengthSquared(); ! if(opal::abs(l0) > globals::OPAL_EPSILON) l0 = 1.0f / l0; ! if(opal::abs(l1) > globals::OPAL_EPSILON) l1 = 1.0f / l1; ! if(opal::abs(l2) > globals::OPAL_EPSILON) l2 = 1.0f / l2; // apply the inverse scale to the 3x3 --- 549,566 ---- result(2, 2)).lengthSquared(); ! if(!areEqual(l0, 0)) ! { ! l0 = 1.0f / l0; ! } ! ! if(!areEqual(l1, 0)) ! { ! l1 = 1.0f / l1; ! } ! ! if(!areEqual(l2, 0)) ! { ! l2 = 1.0f / l2; ! } // apply the inverse scale to the 3x3 *************** *** 573,577 **** // invert scale. ! const real tw = (opal::abs(src(3, 3)) > globals::OPAL_EPSILON) ? 1.0f / src(3, 3) : 0.0f; --- 587,592 ---- // invert scale. ! ! const real tw = !areEqual(src(3, 3), 0) ? 1.0f / src(3, 3) : 0.0f; Index: OpalMath.h =================================================================== RCS file: /cvsroot/opal/opal/src/OpalMath.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** OpalMath.h 18 Apr 2005 22:21:03 -0000 1.11 --- OpalMath.h 27 Apr 2005 02:28:18 -0000 1.12 *************** *** 62,65 **** --- 62,93 ---- return fabs(value); } + + /// Returns true if the two values are equal within some tolerance, + /// using a combination of absolute and relative (epsilon is scaled + /// by the magnitudes of the values) tolerance, depending on whether + /// both values are both less than 1. + inline bool areEqual(real x, real y) + { + real maxVal = 1; + + if (opal::abs(x) > maxVal) + { + maxVal = opal::abs(x); + } + + if (opal::abs(y) > maxVal) + { + maxVal = opal::abs(y); + } + + if (opal::abs(x - y) <= globals::OPAL_EPSILON * maxVal) + { + return true; + } + else + { + return false; + } + } } |