Updated osgunittests with a matrix invert unit test, and added a conditional

calling of invert_4x4 or invert_4x3 depending on the the right hand column of the matrix.

Updated wrappers
This commit is contained in:
Robert Osfield 2006-07-28 13:48:08 +00:00
parent f5b5f7f527
commit f977d7c606
8 changed files with 72 additions and 62 deletions

View File

@ -98,6 +98,24 @@ void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up
}
void testMatrixInvert(const osg::Matrix& matrix)
{
//Invert it twice using the two inversion functions and view the results
osg::notify(osg::NOTICE)<<"testMatrixInvert("<<std::endl;
osg::notify(osg::NOTICE)<<matrix<<std::endl;
osg::notify(osg::NOTICE)<<")"<<std::endl;
osg::Matrix invM1_0;
invM1_0.invert(matrix);
osg::notify(osg::NOTICE)<<"Matrix::invert"<<std::endl;
osg::notify(osg::NOTICE)<<invM1_0<<std::endl;
osg::Matrix default_result = matrix*invM1_0;
osg::notify(osg::NOTICE)<<"matrix * invert="<<std::endl;
osg::notify(osg::NOTICE)<<default_result<<std::endl;;
}
void sizeOfTest()
{
std::cout<<"sizeof(bool)=="<<sizeof(bool)<<std::endl;
@ -372,6 +390,16 @@ int main( int argc, char** argv )
testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(1.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
testMatrixInvert(osg::Matrix(0.999848, -0.002700, 0.017242, -0.1715,
0, 0.987960, 0.154710, 0.207295,
-0.017452, -0.154687, 0.987809, -0.98239,
0, 0, 0, 1));
testMatrixInvert(osg::Matrix(0.999848, -0.002700, 0.017242, 0.0,
0.0, 0.987960, 0.154710, 0.0,
-0.017452, -0.154687, 0.987809, 0.0,
-0.1715, 0.207295, -0.98239, 1.0));
}
if (printSizeOfTest)

View File

@ -197,14 +197,20 @@ class OSG_EXPORT Matrixd
void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,
value_type lookDistance=1.0f) const;
/** invert the matrix rhs. */
bool invert( const Matrixd& rhs);
/** invert the matrix rhs, automatically select invert_4x3 or invert_4x4. */
inline bool invert( const Matrixd& rhs)
{
if (rhs._mat[0][3]==0.0 && rhs._mat[1][3]==0.0 && rhs._mat[2][3]==0.0 && rhs._mat[3][3]==1.0)
return invert_4x3(rhs);
else
return invert_4x4(rhs);
}
/** 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. */
bool invert_4x3( const Matrixd& rhs);
/** full 4x4 matrix invert. */
bool invert_4x4_orig( const Matrixd& );
/** full 4x4 matrix invert. */
bool invert_4x4_new( const Matrixd& );
bool invert_4x4( const Matrixd& rhs);
/** ortho-normalize the 3x3 rotation & scale matrix */
void orthoNormalize(const Matrixd& rhs);

View File

@ -197,14 +197,20 @@ class OSG_EXPORT Matrixf
void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,
value_type lookDistance=1.0f) const;
/** invert the matrix rhs. */
bool invert( const Matrixf& rhs);
/** invert the matrix rhs, automatically select invert_4x3 or invert_4x4. */
inline bool invert( const Matrixf& rhs)
{
if (rhs._mat[0][3]==0.0 && rhs._mat[1][3]==0.0 && rhs._mat[2][3]==0.0 && rhs._mat[3][3]==1.0)
return invert_4x3(rhs);
else
return invert_4x4(rhs);
}
/** 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. */
bool invert_4x3( const Matrixf& rhs);
/** full 4x4 matrix invert. */
bool invert_4x4_orig( const Matrixf& );
/** full 4x4 matrix invert. */
bool invert_4x4_new( const Matrixf& );
bool invert_4x4( const Matrixf& rhs);
/** ortho-normalize the 3x3 rotation & scale matrix */
void orthoNormalize(const Matrixf& rhs);

View File

@ -524,45 +524,6 @@ void Matrix_implementation::orthoNormalize(const Matrix_implementation& rhs)
}
bool Matrix_implementation::invert( const Matrix_implementation& rhs)
{
#if 1
return invert_4x4_new(rhs);
#else
static const osg::Timer& timer = *Timer::instance();
Matrix_implementation a;
Matrix_implementation b;
Timer_t t1 = timer.tick();
a.invert_4x4_new(rhs);
Timer_t t2 = timer.tick();
b.invert_4x4_orig(rhs);
Timer_t t3 = timer.tick();
static double new_time = 0.0;
static double orig_time = 0.0;
static double count = 0.0;
new_time += timer.delta_u(t1,t2);
orig_time += timer.delta_u(t2,t3);
++count;
std::cout<<"Average new="<<new_time/count<<" orig = "<<orig_time/count<<std::endl;
std::cout<<"new matrix invert time="<<timer.delta_u(t1,t2)<<" "<<a<<std::endl;
std::cout<<"orig matrix invert time="<<timer.delta_u(t2,t3)<<" "<<b<<std::endl;
set(b);
return true;
#endif
}
/******************************************
Matrix inversion technique:
Given a matrix mat, we want to invert it.
@ -589,12 +550,12 @@ So the inverse is mat' = (trans * corr)' * rot', where rot' must be computed the
This problem is simplified if [px py pz s] = [0 0 0 1], which will happen if mat was composed only of rotations, scales, and translations (which is common). In this case, we can ignore corr entirely which saves on a lot of computations.
******************************************/
bool Matrix_implementation::invert_4x4_new( const Matrix_implementation& mat )
bool Matrix_implementation::invert_4x3( const Matrix_implementation& mat )
{
if (&mat==this)
{
Matrix_implementation tm(mat);
return invert_4x4_new(tm);
return invert_4x3(tm);
}
register value_type r00, r01, r02,
@ -719,11 +680,11 @@ inline T SGL_ABS(T a)
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
#endif
bool Matrix_implementation::invert_4x4_orig( const Matrix_implementation& mat )
bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
{
if (&mat==this) {
Matrix_implementation tm(mat);
return invert_4x4_orig(tm);
return invert_4x4(tm);
}
unsigned int indxc[4], indxr[4], ipiv[4];

View File

@ -75,8 +75,8 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixd)
I_MethodWithDefaults4(void, getLookAt, IN, osg::Vec3f &, eye, , IN, osg::Vec3f &, center, , IN, osg::Vec3f &, up, , IN, osg::Matrixd::value_type, lookDistance, 1.0f);
I_MethodWithDefaults4(void, getLookAt, IN, osg::Vec3d &, eye, , IN, osg::Vec3d &, center, , IN, osg::Vec3d &, up, , IN, osg::Matrixd::value_type, lookDistance, 1.0f);
I_Method1(bool, invert, IN, const osg::Matrixd &, rhs);
I_Method1(bool, invert_4x4_orig, IN, const osg::Matrixd &, x);
I_Method1(bool, invert_4x4_new, IN, const osg::Matrixd &, x);
I_Method1(bool, invert_4x3, IN, const osg::Matrixd &, rhs);
I_Method1(bool, invert_4x4, IN, const osg::Matrixd &, rhs);
I_Method1(void, orthoNormalize, IN, const osg::Matrixd &, rhs);
I_Method1(osg::Vec3f, preMult, IN, const osg::Vec3f &, v);
I_Method1(osg::Vec3d, preMult, IN, const osg::Vec3d &, v);

View File

@ -75,8 +75,8 @@ BEGIN_VALUE_REFLECTOR(osg::Matrixf)
I_MethodWithDefaults4(void, getLookAt, IN, osg::Vec3f &, eye, , IN, osg::Vec3f &, center, , IN, osg::Vec3f &, up, , IN, osg::Matrixf::value_type, lookDistance, 1.0f);
I_MethodWithDefaults4(void, getLookAt, IN, osg::Vec3d &, eye, , IN, osg::Vec3d &, center, , IN, osg::Vec3d &, up, , IN, osg::Matrixf::value_type, lookDistance, 1.0f);
I_Method1(bool, invert, IN, const osg::Matrixf &, rhs);
I_Method1(bool, invert_4x4_orig, IN, const osg::Matrixf &, x);
I_Method1(bool, invert_4x4_new, IN, const osg::Matrixf &, x);
I_Method1(bool, invert_4x3, IN, const osg::Matrixf &, rhs);
I_Method1(bool, invert_4x4, IN, const osg::Matrixf &, rhs);
I_Method1(void, orthoNormalize, IN, const osg::Matrixf &, rhs);
I_Method1(osg::Vec3f, preMult, IN, const osg::Vec3f &, v);
I_Method1(osg::Vec3d, preMult, IN, const osg::Vec3d &, v);

View File

@ -28,7 +28,7 @@
TYPE_NAME_ALIAS(std::list< osg::ref_ptr< osg::Texture::TextureObject > >, osg::Texture::TextureObjectList);
TYPE_NAME_ALIAS(std::map< unsigned int COMMA osg::Texture::TextureObjectList >, osg::Texture::TextureObjectListMap);
TYPE_NAME_ALIAS(osg::buffered_object< osg::Texture::TextureObjectList >, osg::Texture::TextureObjectListMap);
BEGIN_ENUM_REFLECTOR(osg::Texture::WrapParameter)
I_EnumLabel(osg::Texture::WRAP_S);
@ -235,6 +235,16 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObject)
I_WriteOnlyProperty(bool, Allocated);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::buffered_object< osg::Texture::TextureObjectList >)
I_Constructor0();
I_Constructor1(IN, unsigned int, size);
I_Method1(void, setAllElementsTo, IN, const osg::Texture::TextureObjectList &, t);
I_Method0(void, clear);
I_Method0(bool, empty);
I_Method0(unsigned int, size);
I_WriteOnlyProperty(const osg::Texture::TextureObjectList &, AllElementsTo);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::Texture::TextureObject >)
I_Constructor0();
I_Constructor1(IN, osg::Texture::TextureObject *, ptr);
@ -248,5 +258,3 @@ END_REFLECTOR
STD_LIST_REFLECTOR(std::list< osg::ref_ptr< osg::Texture::TextureObject > >);
STD_MAP_REFLECTOR(std::map< unsigned int COMMA osg::Texture::TextureObjectList >);

View File

@ -39,6 +39,7 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
I_Method2(void, mouseWarp, IN, float, x, IN, float, y);
I_Method2(void, mouseMotion, IN, float, x, IN, float, y);
I_Method3(void, mouseButtonPress, IN, float, x, IN, float, y, IN, unsigned int, button);
I_Method3(void, mouseDoubleButtonPress, IN, float, x, IN, float, y, IN, unsigned int, button);
I_Method3(void, mouseButtonRelease, IN, float, x, IN, float, y, IN, unsigned int, button);
I_Method1(void, keyPress, IN, osgGA::GUIEventAdapter::KeySymbol, key);
I_Method1(void, keyRelease, IN, osgGA::GUIEventAdapter::KeySymbol, key);