[Opal-commits] opal/src testMatrix44r.cpp,NONE,1.1 Makefile.am,1.7,1.8 Makefile.in,1.7,1.8 Matrix44r
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-12-01 23:55:31
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13924/src Modified Files: Makefile.am Makefile.in Matrix44r.h Quaternion.cpp Quaternion.h testAccelerationSensor.cpp testQuaternion.cpp testVec3r.cpp testsolid.cpp Added Files: testMatrix44r.cpp Log Message: More Unit tests. Finished opal::Quaternion tests. Index: Makefile.in =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.in,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.in 1 Dec 2005 19:34:03 -0000 1.7 --- Makefile.in 1 Dec 2005 23:55:21 -0000 1.8 *************** *** 71,75 **** testAccelerationSensor.$(OBJEXT) testRaycastSensor.$(OBJEXT) \ testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ ! testPoint3r.$(OBJEXT) testQuaternion.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ --- 71,76 ---- testAccelerationSensor.$(OBJEXT) testRaycastSensor.$(OBJEXT) \ testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ ! testPoint3r.$(OBJEXT) testQuaternion.$(OBJEXT) \ ! testMatrix44r.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ *************** *** 213,217 **** test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ --- 214,219 ---- test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp \ ! testMatrix44r.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ *************** *** 321,324 **** --- 323,327 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/VolumeSensor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testAccelerationSensor.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testMatrix44r.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testPoint3r.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testQuaternion.Po@am__quote@ Index: testAccelerationSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testAccelerationSensor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testAccelerationSensor.cpp 13 Nov 2005 18:51:20 -0000 1.1 --- testAccelerationSensor.cpp 1 Dec 2005 23:55:21 -0000 1.2 *************** *** 98,102 **** f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.sensor->getGlobalLinearAccel() [ 1 ] , 0, 0.001 ); } } --- 98,102 ---- f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.sensor->getGlobalLinearAccel() [ 1 ] , 0 ); } } Index: testQuaternion.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testQuaternion.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testQuaternion.cpp 1 Dec 2005 19:34:03 -0000 1.2 --- testQuaternion.cpp 1 Dec 2005 23:55:21 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- // system headers #include <quicktest.h> + #include <sstream> // project headers *************** *** 99,118 **** } QT_TEST( lengthSquared ) { ! QT_CHECK_CLOSE( Quaternion( 0, 0, 0, 0 ).lengthSquared(), 0, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 0, 0, 0 ).lengthSquared(), 1, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 0, 0 ).lengthSquared(), 5, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 0 ).lengthSquared(), 14, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 4 ).lengthSquared(), 30, 0.001 ); } QT_TEST( length ) { ! QT_CHECK_CLOSE( Quaternion( 0, 0, 0, 0 ).length(), 0, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 0, 0, 0 ).length(), 1, 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 0, 0 ).length(), sqrt( 5 ), 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 0 ).length(), sqrt( 14 ), 0.001 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 4 ).length(), sqrt( 30 ), 0.001 ); } --- 100,154 ---- } + QT_TEST( operator_summation ) + { + QT_CHECK_EQUAL( Quaternion( 1, 0, 0, 0 ) + Quaternion( 0, 1, 0, 0 ), + Quaternion( 1, 1, 0, 0 ) ); + QT_CHECK_EQUAL( Quaternion( 1, 2, 3, 4 ) + Quaternion( 4, 3, 2, 1 ), + Quaternion( 5, 5, 5, 5 ) ); + } + + QT_TEST( operator_substraction ) + { + QT_CHECK_EQUAL( Quaternion( 1, 0, 0, 0 ) - Quaternion( 0, 1, 0, 0 ), + Quaternion( 1, -1, 0, 0 ) ); + QT_CHECK_EQUAL( Quaternion( 1, 2, 3, 4 ) - Quaternion( 4, 3, 2, 1 ), + Quaternion( -3, -1, 1, 3 ) ); + } + + QT_TEST( operator_multiply_before_scalar ) + { + QT_CHECK_EQUAL( Quaternion( 1, 0, 0, 0 ) * 5, Quaternion( 5, 0, 0, 0 ) ); + QT_CHECK_EQUAL( Quaternion( 1, 2, -3, 4 ) * -1, Quaternion( -1, -2, 3, -4 ) ); + } + + QT_TEST( operator_multiply_after_scalar ) + { + QT_CHECK_EQUAL( 5 * Quaternion( 1, 0, 0, 0 ), Quaternion( 5, 0, 0, 0 ) ); + QT_CHECK_EQUAL( -1 * Quaternion( 1, 2, -3, 4 ), Quaternion( -1, -2, 3, -4 ) ); + } + + QT_TEST( operator_string ) + { + std::ostringstream ss; + ss << Quaternion( 1, 2, 3, 4 ); + QT_CHECK_EQUAL( ss.str(), "[1 2 3 4]" ); + } + QT_TEST( lengthSquared ) { ! QT_CHECK_CLOSE( Quaternion( 0, 0, 0, 0 ).lengthSquared(), 0 ); ! QT_CHECK_CLOSE( Quaternion( 1, 0, 0, 0 ).lengthSquared(), 1 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 0, 0 ).lengthSquared(), 5 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 0 ).lengthSquared(), 14 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 4 ).lengthSquared(), 30 ); } QT_TEST( length ) { ! QT_CHECK_CLOSE( Quaternion( 0, 0, 0, 0 ).length(), 0 ); ! QT_CHECK_CLOSE( Quaternion( 1, 0, 0, 0 ).length(), 1 ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 0, 0 ).length(), sqrt( 5 ) ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 0 ).length(), sqrt( 14 ) ); ! QT_CHECK_CLOSE( Quaternion( 1, 2, 3, 4 ).length(), sqrt( 30 ) ); } *************** *** 121,125 **** Quaternion q( 0, 0, 0, 0 ); q.normalize(); ! QT_CHECK_NOT_EQUAL( q, Quaternion( 0, 0, 0, 0 ) ); } } --- 157,212 ---- Quaternion q( 0, 0, 0, 0 ); q.normalize(); ! QT_CHECK_EQUAL( q, Quaternion( 0, 0, 0, 0 ) ); ! ! q.set( 0, 0, 0, 1 ); ! q.normalize(); ! QT_CHECK_EQUAL( q, Quaternion( 0, 0, 0, 1 ) ); ! ! q.set( 1, 0, 0, 0 ); ! q.normalize(); ! QT_CHECK_EQUAL( q, Quaternion( 1, 0, 0, 0 ) ); ! ! q.set( 1, 0, 0, 1 ); ! q.normalize(); ! QT_CHECK_EQUAL( q, Quaternion( sqrt( 2 ) / 2.0, 0, 0, sqrt( 2 ) / 2.0 ) ); ! } ! ! QT_TEST( getAngleAxis ) ! { ! Quaternion q( 0, 1, 0, 0 ); ! real angle; ! Vec3r axis; ! q.getAngleAxis( angle, axis ); ! QT_CHECK_EQUAL( angle, 180 ); ! QT_CHECK_EQUAL( axis, Vec3r( 1, 0, 0 ) ); ! ! q.set( 0, 0, 1, 0 ); ! q.getAngleAxis( angle, axis ); ! QT_CHECK_EQUAL( angle, 180 ); ! QT_CHECK_EQUAL( axis, Vec3r( 0, 1, 0 ) ); ! ! q.set( 1, 0, 1, 0 ); ! q.normalize(); ! q.getAngleAxis( angle, axis ); ! QT_CHECK_CLOSE( angle, 90 ); ! QT_CHECK_EQUAL( axis, Vec3r( 0, 1, 0 ) ); ! } ! ! QT_TEST( getRoll_Pitch_Yaw ) ! { ! Quaternion q( 0, 0, 1, 0 ); ! QT_CHECK_CLOSE( q.getRoll(), 180 ); ! QT_CHECK_CLOSE( q.getPitch(), 0 ); ! QT_CHECK_CLOSE( q.getYaw(), 180 ); ! ! q.set( 0, 1, 0, 0 ); ! QT_CHECK_CLOSE( q.getRoll(), 180 ); ! QT_CHECK_CLOSE( q.getPitch(), 0 ); ! QT_CHECK_CLOSE( q.getYaw(), 0 ); ! ! q.set( 0, 0, 0, 1 ); ! QT_CHECK_CLOSE( q.getRoll(), 0 ); ! QT_CHECK_CLOSE( q.getPitch(), 0 ); ! QT_CHECK_CLOSE( q.getYaw(), 180 ); } } Index: testsolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testsolid.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** testsolid.cpp 1 Dec 2005 19:34:03 -0000 1.6 --- testsolid.cpp 1 Dec 2005 23:55:21 -0000 1.7 *************** *** 106,110 **** f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); } --- 106,110 ---- f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ] ); } *************** *** 118,122 **** f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); } --- 118,122 ---- f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ] ); } *************** *** 142,146 **** f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ], 0.001 ); } --- 142,146 ---- f.sim->simulate( 1 ); ! QT_CHECK_CLOSE( f.s->getPosition() [ 1 ], p[ 1 ] ); } *************** *** 216,225 **** Matrix44r m_set = f.s->getInertiaTensor(); QT_CHECK_EQUAL( m, m_set ); ! QT_CHECK_CLOSE( f.s->getMass(), mass.mass, 0.001 ); mass.mass = 2; f.s->setMass( mass, Matrix44r() ); ! QT_CHECK_CLOSE( f.s->getMass(), mass.mass, 0.001 ); } --- 216,225 ---- Matrix44r m_set = f.s->getInertiaTensor(); QT_CHECK_EQUAL( m, m_set ); ! QT_CHECK_CLOSE( f.s->getMass(), mass.mass ); mass.mass = 2; f.s->setMass( mass, Matrix44r() ); ! QT_CHECK_CLOSE( f.s->getMass(), mass.mass ); } Index: Makefile.am =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 1 Dec 2005 19:34:03 -0000 1.7 --- Makefile.am 1 Dec 2005 23:55:21 -0000 1.8 *************** *** 15,19 **** bin_PROGRAMS = test_opal test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode --- 15,20 ---- bin_PROGRAMS = test_opal test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp \ ! testMatrix44r.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode Index: Quaternion.h =================================================================== RCS file: /cvsroot/opal/opal/src/Quaternion.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Quaternion.h 1 Dec 2005 19:34:03 -0000 1.11 --- Quaternion.h 1 Dec 2005 23:55:21 -0000 1.12 *************** *** 61,65 **** void normalize(); ! void getAngleAxis( real& angle, Vec3r& axis ); real getRoll() const; --- 61,65 ---- void normalize(); ! void getAngleAxis( real& angle, Vec3r& axis ) const; real getRoll() const; Index: Quaternion.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Quaternion.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Quaternion.cpp 1 Dec 2005 19:34:03 -0000 1.1 --- Quaternion.cpp 1 Dec 2005 23:55:21 -0000 1.2 *************** *** 83,92 **** { real len = length(); ! assert( 0 != len ); ! real factor = 1 / len; ! ( *this ) = ( *this ) * factor; } ! void Quaternion::getAngleAxis( real& angle, Vec3r& axis ) { real sqrLen = x * x + y * y + z * z; --- 83,94 ---- { real len = length(); ! if ( len > 0 ) ! { ! real factor = 1 / len; ! ( *this ) = ( *this ) * factor; ! } } ! void Quaternion::getAngleAxis( real& angle, Vec3r& axis ) const { real sqrLen = x * x + y * y + z * z; *************** *** 146,158 **** const real & Quaternion::operator[] ( unsigned int i ) const { ! switch ( i ) ! { ! case 0: return w; ! case 1: return x; ! case 2: return y; ! case 3: return z; ! } ! assert( i < 4 ); ! return w; } --- 148,160 ---- const real & Quaternion::operator[] ( unsigned int i ) const { ! switch ( i ) ! { ! case 0: return w; ! case 1: return x; ! case 2: return y; ! case 3: return z; ! } ! assert( i < 4 ); ! return w; } --- NEW FILE: testMatrix44r.cpp --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * Oleksandr Lozitskiy mr....@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ // system headers #include <quicktest.h> // project headers #include "opal.h" using namespace opal; namespace testMatrix44r { QT_TEST( setQuaternion_values ) { Matrix44r m; m.setQuaternion( 0, 0, 0, 1 ); QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, 180 ) ); } QT_TEST( setQuaternion_object ) { Matrix44r m; m.setQuaternion( Quaternion( 0, 0, 0, 1 ) ); QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, 180 ) ); } } Index: testVec3r.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testVec3r.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testVec3r.cpp 30 Nov 2005 06:28:12 -0000 1.1 --- testVec3r.cpp 1 Dec 2005 23:55:21 -0000 1.2 *************** *** 289,301 **** { QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 1, 0, 0 ) ), ! 90, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0.5, 0.5, 0 ) ), ! 90, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, 0.5 ) ), ! 45, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, 0.5 ) ), ! 45, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, -0.5 ) ), ! 90 + 45, 0.0001 ); } --- 289,301 ---- { QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 1, 0, 0 ) ), ! 90 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0.5, 0.5, 0 ) ), ! 90 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, 0.5 ) ), ! 45 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, 0.5 ) ), ! 45 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, 0.5, -0.5 ) ), ! 90 + 45 ); } *************** *** 303,316 **** { QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 1, 0, 0 ) ), ! 90, 0.0001 ); real s = sqrt( 0.5 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( s, s, 0 ) ), ! 90, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, s ) ), ! 45, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, s ) ), ! 45, 0.0001 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, -s ) ), ! 90 + 45, 0.0001 ); } --- 303,316 ---- { QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 1, 0, 0 ) ), ! 90 ); real s = sqrt( 0.5 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( s, s, 0 ) ), ! 90 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, s ) ), ! 45 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, s ) ), ! 45 ); QT_CHECK_CLOSE( angleBetween( Vec3r( 0, 0, 1 ) , Vec3r( 0, s, -s ) ), ! 90 + 45 ); } Index: Matrix44r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Matrix44r.h,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Matrix44r.h 1 Dec 2005 19:34:03 -0000 1.39 --- Matrix44r.h 1 Dec 2005 23:55:21 -0000 1.40 *************** *** 69,72 **** --- 69,73 ---- inline friend Matrix44r operator*( real scalar, Matrix44r m ); + /// identity by default Matrix44r() { *************** *** 255,258 **** --- 256,268 ---- } + inline void setQuaternion( const Quaternion & q ) + { + real angle; + Vec3r axis; + q.getAngleAxis( angle, axis ); + + setRotation( angle, axis.x, axis.y, axis.z ); + } + inline void setRotation( real theta, real x, real y, real z ) { |