Hi Anders,
The equality test is an exact equality test, same with isIdentity().
One could relax it by adding an epilson to it, but this would not be
an exact equality, so would be better placed in a separate method.
Robert.
On 2/26/07, Anders Backman <[EMAIL PROTECTED]> wrote:
Hi Robert.
I just got stuck on something I been worried about for quite some time
regarding the Math library in osg:
bool Matrix::isIdentity() const
{
return _mat[0][0]==1.0f && _mat[0][1]==0.0f && _mat[0][2]==0.0f
&& _mat[0][3]==0.0f &&
_mat[1][0]==0.0f && _mat[1][1]==1.0f && _mat[1][2]==0.0f
&& _mat[1][3]==0.0f &&
_mat[2][0]==0.0f && _mat[2][1]==0.0f && _mat[2][2]==1.0f
&& _mat[2][3]==0.0f &&
_mat[3][0]==0.0f && _mat[3][1]==0.0f && _mat[3][2]== 0.0f
&& _mat[3][3]==1.0f;
}
Is there a specific reason for not using epsilon tests for a float? I can
think of quite a few situations when this would fail.
I guess, there is only one situation when this would succeed for sure, and
that is after a call to makeIdentity().
This also goes for quite some of the Vec3, Vec4, Quat code too.
All comparisons such as:
inline bool operator == (const Vec3f& v) const { return _v[0]==v._v[0] &&
_v[1]==v._v[1] && _v[2]==v._v[2]; }
Would effectively fail in most situations, as comparing floats directly is
something that is not recomended.
Instead something like the following should be used:
#define EPSILON 1E-16
#define EQUAL(A,B) (abs((A)-(B)) < EPSILON)
inline bool operator == (const Vec3f& v) const { return EQUAL(_v[0]-v._v[0])
&& EQUAL(_v[1]-v._v[1]) && EQUAL(_v[2]-v._v[2]); }'
Comments?
--
________________________________________________________________
Anders Backman Email: [EMAIL PROTECTED]
HPC2N/VRlab Phone: +46 (0)90-786 9936
Umea university Cellular: +46 (0)70-392 64 67
S-901 87 UMEA SWEDEN Fax: +46 90-786 6126
http://www.cs.umu.se/~andersb
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/