[Opal-commits] opal/src testQuaternion.cpp,NONE,1.1 Makefile.am,1.5,1.6 Makefile.in,1.5,1.6 Matrix44
Status: Inactive
Brought to you by:
tylerstreeter
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6648/src Modified Files: Makefile.am Makefile.in Matrix44r.h Quaternion.h Solid.cpp Solid.h testsolid.cpp Added Files: testQuaternion.cpp Log Message: Solid::setQuaternion and Matrix44r:setQuaternion initial draft. Added unit tests for Quaternion. Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Solid.cpp 6 Nov 2005 05:12:21 -0000 1.39 --- Solid.cpp 1 Dec 2005 04:54:44 -0000 1.40 *************** *** 1,28 **** /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #include "Solid.h" --- 1,28 ---- /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #include "Solid.h" *************** *** 30,318 **** namespace opal { ! Solid::Solid() ! { ! // "mData" is initialized in its own constructor. ! setCollisionEventHandler(NULL); ! setUserData(NULL); ! resetAABB(); ! } ! Solid::~Solid() ! { ! mForceList.clear(); ! } ! void Solid::internal_destroy() ! { ! delete this; ! } ! const SolidData& Solid::getData() ! { ! // Update parameters that don't get updated automatically. ! mData.sleeping = isSleeping(); ! return mData; ! } ! void Solid::setName(const std::string& name) ! { ! mData.name = name; ! } ! const std::string& Solid::getName()const ! { ! return mData.name; ! } ! bool Solid::isEnabled()const ! { ! return mData.enabled; ! } ! void Solid::setEnabled(bool e) ! { ! mData.enabled = e; ! } ! bool Solid::isStatic()const ! { ! return mData.isStatic; ! } ! void Solid::setSleepiness(real s) ! { ! assert(s >= 0.0 && s <= 1.0); ! mData.sleepiness = s; ! } ! real Solid::getSleepiness()const ! { ! return mData.sleepiness; ! } ! void Solid::setLinearDamping(real ld) ! { ! assert(ld >= 0.0); ! mData.linearDamping = ld; ! } ! real Solid::getLinearDamping()const ! { ! return mData.linearDamping; ! } ! void Solid::setAngularDamping(real ad) ! { ! assert(ad >= 0.0); ! mData.angularDamping = ad; ! } ! real Solid::getAngularDamping()const ! { ! return mData.angularDamping; ! } ! void Solid::setUserData(void* data) ! { ! mUserData = data; ! } ! void* Solid::getUserData()const ! { ! return mUserData; ! } ! void Solid::setTransform(const Matrix44r& t) ! { ! mData.transform = t; ! internal_updateEngineTransform(); ! } ! const Matrix44r& Solid::getTransform()const ! { ! return mData.transform; ! } ! void Solid::setPosition(real x, real y, real z) ! { ! mData.transform.setPosition(x, y, z); ! internal_updateEngineTransform(); ! } ! void Solid::setPosition(const Point3r & p) ! { ! setPosition(p[0], p[1], p[2]); ! } ! Point3r Solid::getPosition()const ! { ! return mData.transform.getPosition(); ! } ! Vec3r Solid::getEulerXYZ()const ! { ! return mData.transform.getEulerXYZ(); ! } ! Quaternion Solid::getQuaternion()const ! { ! return mData.transform.getQuaternion(); ! } ! void Solid::getLocalAABB(real aabb[6])const { ! for (unsigned int i = 0; i < 6; ++i) ! { ! aabb[i] = mLocalAABB[i]; ! } } ! void Solid::getGlobalAABB(real aabb[6])const ! { ! Point3r minExtents(mLocalAABB[0], mLocalAABB[2], mLocalAABB[4]); ! Point3r maxExtents(mLocalAABB[1], mLocalAABB[3], mLocalAABB[5]); ! // Transform the AABB extents to global coordinates. ! minExtents = mData.transform * minExtents; ! maxExtents = mData.transform * maxExtents; ! aabb[0] = minExtents[0]; ! aabb[1] = maxExtents[0]; ! aabb[2] = minExtents[1]; ! aabb[3] = maxExtents[1]; ! aabb[4] = minExtents[2]; ! aabb[5] = maxExtents[2]; ! } ! //void Solid::addPlane(const Point3r& point, const Vec3r& normal, const Material& m) ! //{ ! // Point3r origin(0, 0, 0); ! // Vec3r n = normal; ! // n.normalize(); ! // Vec3r v = point - origin; ! // ! // real angle = 0; ! // if (0 != v.length()) ! // { ! // v.normalize(); ! // angle = acos(dot(n,v)); // note: this only works when the two vectors are normalized ! // } ! // ! // real length = distance(point, origin); ! // real D = length * cos(angle); ! // real abcd[4] = {n[0], n[1], n[2], D}; ! // addPlane(abcd, m); ! //} ! void Solid::addForce(const Force& f) ! { ! if (mData.enabled && !mData.isStatic && ! !areEqual(f.vec.lengthSquared(), 0)) ! { ! mForceList.push_back(f); ! } ! } ! void Solid::internal_applyForces(real stepSize) ! { ! if (mData.isStatic) ! { ! return; ! } ! // If there are Forces to apply and the Solid is asleep, wake it up. ! if(!mForceList.empty() && isSleeping()) ! { ! setSleeping(false); ! } ! real invStepSize = 1 / stepSize; ! for (unsigned int i = 0; i < mForceList.size();) ! { ! if (true == mForceList[i].singleStep) ! { ! mForceList[i].duration = stepSize; ! } ! else if (mForceList[i].duration < stepSize) ! { ! // Scale the size of the force/torque. ! mForceList[i].vec *= (mForceList[i].duration * invStepSize); ! } ! // Apply the actual force/torque. ! applyForce(mForceList[i]); ! // The following is ok for all cases (even when duration is ! // < mStepSize). ! mForceList[i].duration -= stepSize; ! if (mForceList[i].duration <= 0) ! { ! // Delete this force. ! mForceList[i] = mForceList.back(); ! mForceList.pop_back(); ! } ! else ! { ! ++i; ! } ! } ! } ! void Solid::setCollisionEventHandler(CollisionEventHandler* eventHandler) ! { ! mCollisionEventHandler = eventHandler; ! } ! CollisionEventHandler* Solid::getCollisionEventHandler()const ! { ! return mCollisionEventHandler; ! } ! void Solid::addToLocalAABB(const real aabb[6]) ! { ! // Loop over the 3 dimensions of the AABB's extents. ! for (unsigned int i = 0; i < 3; ++i) ! { ! if (aabb[i * 2] < mLocalAABB[i * 2]) ! { ! mLocalAABB[i * 2] = aabb[i * 2]; ! } ! if (aabb[i * 2 + 1] > mLocalAABB[i * 2 + 1]) ! { ! mLocalAABB[i * 2 + 1] = aabb[i * 2 + 1]; ! } ! } ! } ! void Solid::resetAABB() ! { ! for (unsigned int i = 0; i < 6; ++i) ! { ! mLocalAABB[i] = 0; ! } ! } ! //void Solid::internal_updateSleeping() ! //{ ! // mData.sleeping = isSleeping(); ! //} ! //// TODO: Quickly spinning solids should be set as fast rotating solids to ! //// improve simulation accuracy. ! //void Solid::setFastRotation(bool fast) ! //{ ! //} ! //bool Solid::getFastRotation()const ! //{ ! // return false; ! //} ! //void Solid::setFastRotationAxis(Vec3r axis) ! //{ ! //} } --- 30,330 ---- namespace opal { ! Solid::Solid() ! { ! // "mData" is initialized in its own constructor. ! setCollisionEventHandler( NULL ); ! setUserData( NULL ); ! resetAABB(); ! } ! Solid::~Solid() ! { ! mForceList.clear(); ! } ! void Solid::internal_destroy() ! { ! delete this; ! } ! const SolidData& Solid::getData() ! { ! // Update parameters that don't get updated automatically. ! mData.sleeping = isSleeping(); ! return mData; ! } ! void Solid::setName( const std::string& name ) ! { ! mData.name = name; ! } ! const std::string& Solid::getName() const ! { ! return mData.name; ! } ! bool Solid::isEnabled() const ! { ! return mData.enabled; ! } ! void Solid::setEnabled( bool e ) ! { ! mData.enabled = e; ! } ! bool Solid::isStatic() const ! { ! return mData.isStatic; ! } ! void Solid::setSleepiness( real s ) ! { ! assert( s >= 0.0 && s <= 1.0 ); ! mData.sleepiness = s; ! } ! real Solid::getSleepiness() const ! { ! return mData.sleepiness; ! } ! void Solid::setLinearDamping( real ld ) ! { ! assert( ld >= 0.0 ); ! mData.linearDamping = ld; ! } ! real Solid::getLinearDamping() const ! { ! return mData.linearDamping; ! } ! void Solid::setAngularDamping( real ad ) ! { ! assert( ad >= 0.0 ); ! mData.angularDamping = ad; ! } ! real Solid::getAngularDamping() const ! { ! return mData.angularDamping; ! } ! void Solid::setUserData( void* data ) ! { ! mUserData = data; ! } ! void* Solid::getUserData() const ! { ! return mUserData; ! } ! void Solid::setTransform( const Matrix44r& t ) ! { ! mData.transform = t; ! internal_updateEngineTransform(); ! } ! const Matrix44r& Solid::getTransform() const ! { ! return mData.transform; ! } ! void Solid::setPosition( real x, real y, real z ) ! { ! mData.transform.setPosition( x, y, z ); ! internal_updateEngineTransform(); ! } ! void Solid::setPosition( const Point3r & p ) ! { ! setPosition( p[ 0 ], p[ 1 ], p[ 2 ] ); ! } ! Point3r Solid::getPosition() const ! { ! return mData.transform.getPosition(); ! } ! Vec3r Solid::getEulerXYZ() const ! { ! return mData.transform.getEulerXYZ(); ! } ! Quaternion Solid::getQuaternion() const ! { ! return mData.transform.getQuaternion(); ! } ! void Solid::setQuaternion( const Quaternion & q ) ! { ! mData.transform.setQuaternion( q[ 0 ], q[ 1 ], q[ 2 ], q[ 3 ] ); ! internal_updateEngineTransform(); ! } ! ! void Solid::setQuaternion( real w, real x, real y, real z ) { ! mData.transform.setQuaternion( w, x, y, z ); ! internal_updateEngineTransform(); } ! void Solid::getLocalAABB( real aabb[ 6 ] ) const ! { ! for ( unsigned int i = 0; i < 6; ++i ) ! { ! aabb[ i ] = mLocalAABB[ i ]; ! } ! } ! void Solid::getGlobalAABB( real aabb[ 6 ] ) const ! { ! Point3r minExtents( mLocalAABB[ 0 ], mLocalAABB[ 2 ], mLocalAABB[ 4 ] ); ! Point3r maxExtents( mLocalAABB[ 1 ], mLocalAABB[ 3 ], mLocalAABB[ 5 ] ); ! // Transform the AABB extents to global coordinates. ! minExtents = mData.transform * minExtents; ! maxExtents = mData.transform * maxExtents; ! aabb[ 0 ] = minExtents[ 0 ]; ! aabb[ 1 ] = maxExtents[ 0 ]; ! aabb[ 2 ] = minExtents[ 1 ]; ! aabb[ 3 ] = maxExtents[ 1 ]; ! aabb[ 4 ] = minExtents[ 2 ]; ! aabb[ 5 ] = maxExtents[ 2 ]; ! } ! //void Solid::addPlane(const Point3r& point, const Vec3r& normal, const Material& m) ! //{ ! // Point3r origin(0, 0, 0); ! // Vec3r n = normal; ! // n.normalize(); ! // Vec3r v = point - origin; ! // ! // real angle = 0; ! // if (0 != v.length()) ! // { ! // v.normalize(); ! // angle = acos(dot(n,v)); // note: this only works when the two vectors are normalized ! // } ! // ! // real length = distance(point, origin); ! // real D = length * cos(angle); ! // real abcd[4] = {n[0], n[1], n[2], D}; ! // addPlane(abcd, m); ! //} ! void Solid::addForce( const Force& f ) ! { ! if ( mData.enabled && !mData.isStatic && ! !areEqual( f.vec.lengthSquared(), 0 ) ) ! { ! mForceList.push_back( f ); ! } ! } ! void Solid::internal_applyForces( real stepSize ) ! { ! if ( mData.isStatic ) ! { ! return ; ! } ! // If there are Forces to apply and the Solid is asleep, wake it up. ! if ( !mForceList.empty() && isSleeping() ) ! { ! setSleeping( false ); ! } ! real invStepSize = 1 / stepSize; ! for ( unsigned int i = 0; i < mForceList.size(); ) ! { ! if ( true == mForceList[ i ].singleStep ) ! { ! mForceList[ i ].duration = stepSize; ! } ! else if ( mForceList[ i ].duration < stepSize ) ! { ! // Scale the size of the force/torque. ! mForceList[ i ].vec *= ( mForceList[ i ].duration * invStepSize ); ! } ! // Apply the actual force/torque. ! applyForce( mForceList[ i ] ); ! // The following is ok for all cases (even when duration is ! // < mStepSize). ! mForceList[ i ].duration -= stepSize; ! if ( mForceList[ i ].duration <= 0 ) ! { ! // Delete this force. ! mForceList[ i ] = mForceList.back(); ! mForceList.pop_back(); ! } ! else ! { ! ++i; ! } ! } ! } ! void Solid::setCollisionEventHandler( CollisionEventHandler* eventHandler ) ! { ! mCollisionEventHandler = eventHandler; ! } ! CollisionEventHandler* Solid::getCollisionEventHandler() const ! { ! return mCollisionEventHandler; ! } ! void Solid::addToLocalAABB( const real aabb[ 6 ] ) ! { ! // Loop over the 3 dimensions of the AABB's extents. ! for ( unsigned int i = 0; i < 3; ++i ) ! { ! if ( aabb[ i * 2 ] < mLocalAABB[ i * 2 ] ) ! { ! mLocalAABB[ i * 2 ] = aabb[ i * 2 ]; ! } ! if ( aabb[ i * 2 + 1 ] > mLocalAABB[ i * 2 + 1 ] ) ! { ! mLocalAABB[ i * 2 + 1 ] = aabb[ i * 2 + 1 ]; ! } ! } ! } ! void Solid::resetAABB() ! { ! for ( unsigned int i = 0; i < 6; ++i ) ! { ! mLocalAABB[ i ] = 0; ! } ! } ! //void Solid::internal_updateSleeping() ! //{ ! // mData.sleeping = isSleeping(); ! //} ! //// TODO: Quickly spinning solids should be set as fast rotating solids to ! //// improve simulation accuracy. ! //void Solid::setFastRotation(bool fast) ! //{ ! //} ! //bool Solid::getFastRotation()const ! //{ ! // return false; ! //} ! ! //void Solid::setFastRotationAxis(Vec3r axis) ! //{ ! //} } Index: Makefile.in =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.in,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.in 1 Dec 2005 02:04:54 -0000 1.5 --- Makefile.in 1 Dec 2005 04:54:44 -0000 1.6 *************** *** 70,74 **** testAccelerationSensor.$(OBJEXT) testRaycastSensor.$(OBJEXT) \ testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ ! testPoint3r.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ --- 70,74 ---- testAccelerationSensor.$(OBJEXT) testRaycastSensor.$(OBJEXT) \ testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ ! testPoint3r.$(OBJEXT) testQuaternion.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ *************** *** 212,216 **** test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ --- 212,216 ---- 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 \ *************** *** 320,323 **** --- 320,324 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testAccelerationSensor.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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testRaycastSensor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testSimulator.Po@am__quote@ --- NEW FILE: testQuaternion.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 testQuaternion { QT_TEST( default_constructor ) { Quaternion q; QT_CHECK_EQUAL( q[ 0 ], 0 ); QT_CHECK_EQUAL( q[ 1 ], 0 ); QT_CHECK_EQUAL( q[ 2 ], 0 ); QT_CHECK_EQUAL( q[ 3 ], 0 ); } QT_TEST( constructor ) { Quaternion q( 1, 2, 3, 4 ); QT_CHECK_EQUAL( q[ 0 ], 1 ); QT_CHECK_EQUAL( q[ 1 ], 2 ); QT_CHECK_EQUAL( q[ 2 ], 3 ); QT_CHECK_EQUAL( q[ 3 ], 4 ); } QT_TEST( operator_equal ) { QT_CHECK_EQUAL( Quaternion( 0, 0, 0, 0 ), Quaternion( 0, 0, 0, 0 ) ); QT_CHECK_EQUAL( Quaternion( 0, 0, 0, 1 ), Quaternion( 0, 0, 0, 1 ) ); QT_CHECK_EQUAL( Quaternion( 0, 0, 1, 2 ), Quaternion( 0, 0, 1, 2 ) ); QT_CHECK_EQUAL( Quaternion( 1, 2, 0, 3 ), Quaternion( 1, 2, 0, 3 ) ); } QT_TEST( operator_not_equal ) { QT_CHECK_NOT_EQUAL( Quaternion( 0, 0, 0, 0 ), Quaternion( 1, 0, 0, 0 ) ); QT_CHECK_NOT_EQUAL( Quaternion( 0, 0, 0, 1 ), Quaternion( 0, 1, 0, 0 ) ); QT_CHECK_NOT_EQUAL( Quaternion( 0, 0, 1, 2 ), Quaternion( 4, 5, 0, 2 ) ); QT_CHECK_NOT_EQUAL( Quaternion( 1, 2, 0, 3 ), Quaternion( 1, 0, 2, 3 ) ); } } Index: testsolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testsolid.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** testsolid.cpp 1 Dec 2005 02:04:54 -0000 1.4 --- testsolid.cpp 1 Dec 2005 04:54:44 -0000 1.5 *************** *** 216,220 **** 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; --- 216,220 ---- 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; *************** *** 223,225 **** --- 223,237 ---- QT_CHECK_CLOSE( f.s->getMass(), mass.mass, 0.001 ); } + + QT_TEST( setQuaternion_Q ) + { + SolidBoxFixture f; + Quaternion q = f.s->getQuaternion(); + f.s->setQuaternion( q ); + QT_CHECK_EQUAL( q, f.s->getQuaternion() ); + + q.set( 1, 0, 0, 0 ); + f.s->setQuaternion( q ); + QT_CHECK_EQUAL( q, f.s->getQuaternion() ); + } } Index: Makefile.am =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 1 Dec 2005 02:04:54 -0000 1.5 --- Makefile.am 1 Dec 2005 04:54:44 -0000 1.6 *************** *** 15,19 **** bin_PROGRAMS = test_opal test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode --- 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 Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** Solid.h 1 Dec 2005 02:04:54 -0000 1.93 --- Solid.h 1 Dec 2005 04:54:44 -0000 1.94 *************** *** 1,28 **** /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #ifndef OPAL_SOLID_H --- 1,28 ---- /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #ifndef OPAL_SOLID_H *************** *** 35,281 **** namespace opal { ! class Mass; ! class Simulator; ! class Space; ! class ShapeData; ! /// Solids are the physical objects in a simulation. Solids can be ! /// static or dynamic: basically, dynamic Solids move, and static Solids ! /// don't move. (Static Solids can still be positioned manually.) All ! /// Solids start out enabled, but they don't do much until Shapes are ! /// added. ! class Solid ! { ! public: ! Solid(); ! /// Initializes the Solid with the given data structure. Calling ! /// this more than once will automatically destroy all the old ! /// Shapes before adding new ones. ! virtual void OPAL_CALL init(const SolidData& data) = 0; ! /// Returns all data describing the Solid. ! virtual const SolidData& OPAL_CALL getData(); ! /// Sets the Solid's name. ! virtual void OPAL_CALL setName(const std::string& name); ! /// Returns the Solid's name. ! virtual const std::string& OPAL_CALL getName()const; ! /// Returns true if the Solid is enabled. ! virtual bool OPAL_CALL isEnabled()const; ! /// Sets whether the Solid can collide with other Solids and be ! /// physically simulated. Forces applied to this Solid while ! /// disabled will be ignored. ! virtual void OPAL_CALL setEnabled(bool e); ! /// Returns true if this is a static Solid. ! virtual bool OPAL_CALL isStatic()const; ! /// Sets whether the Solid should be static or dynamic. ! virtual void OPAL_CALL setStatic(bool s) = 0; ! /// Removes the Solid from its current Space and adds it to the new ! /// Space. ! virtual void OPAL_CALL setSpace(Space* newSpace) = 0; ! /// Sets whether the Solid is sleeping (i.e. set this to false to ! /// wake up a sleeping Solid). ! virtual void OPAL_CALL setSleeping(bool sleeping) = 0; ! /// Returns true if the Solid is sleeping. If the Solid is static, ! /// this will always return true. ! virtual bool OPAL_CALL isSleeping()const = 0; ! /// Sets the Solid's sleepiness level. ! virtual void OPAL_CALL setSleepiness(real s); ! /// Returns the Solid's sleepiness level. ! virtual real OPAL_CALL getSleepiness()const; ! /// Sets the amount of linear damping on this Solid. ! virtual void OPAL_CALL setLinearDamping(real ld); ! /// Returns the amount of linear damping on this Solid. ! virtual real OPAL_CALL getLinearDamping()const; ! /// Sets the amount of angular damping on this Solid. ! virtual void OPAL_CALL setAngularDamping(real ad); ! /// Returns the amount of angular damping on this Solid. ! virtual real OPAL_CALL getAngularDamping()const; ! /// Set this Solid's user data pointer to some external data. This ! /// can be used to let the Solid point to some user object (e.g. an ! /// object with a visual mesh). The user data is totally user-managed ! /// (i.e. it is not destroyed when the Solid is destroyed). ! virtual void OPAL_CALL setUserData(void* data); ! /// Returns the user data pointer (NULL if it has not been set). ! virtual void* OPAL_CALL getUserData()const; ! /// Sets this Solid's transform matrix. ! virtual void OPAL_CALL setTransform(const Matrix44r& t); ! /// Returns a constant reference to this Solid's transform. ! virtual const Matrix44r& OPAL_CALL getTransform()const; ! /// Sets the position of this Solid in global coordinates. ! virtual void OPAL_CALL setPosition(real x, real y, real z); ! /// Sets the position of this Solid in global coordinates. ! virtual void OPAL_CALL setPosition(const Point3r & p); ! /// Returns the position of this Solid in global coordinates. ! virtual Point3r OPAL_CALL getPosition()const; ! /// Returns the euler angles of the Solid's orientation. ! virtual Vec3r OPAL_CALL getEulerXYZ()const; ! /// Returns a quaternion representing the Solid's orientation. ! virtual Quaternion OPAL_CALL getQuaternion()const; ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes relative to the Solid. ! virtual void OPAL_CALL getLocalAABB(real aabb[6])const; ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes in global coordinates. ! virtual void OPAL_CALL getGlobalAABB(real aabb[6])const; ! /// Removes all shapes from this Solid. Resets the Solid's ! /// axis-aligned bounding box. ! virtual void OPAL_CALL clearShapes() = 0; ! /// Adds a Shape to this Solid. Updates the Solid's axis-aligned ! /// bounding box. ! virtual void OPAL_CALL addShape(ShapeData& data) = 0; ! /// Applies a force/torque to this Solid. If the Solid is disabled, ! /// the Solid is static, or the magnitude of the force/torque is ! /// zero, this will do nothing. ! virtual void OPAL_CALL addForce(const Force& f); ! /// Removes all forces and torques currently affecting this Solid. ! virtual void OPAL_CALL zeroForces() = 0; ! /// Sets the Solid's linear velocity in local coordinates. ! virtual void OPAL_CALL setLocalLinearVel(const Vec3r& vel) = 0; ! /// Returns the Solid's linear velocity in local coordinates. ! virtual Vec3r OPAL_CALL getLocalLinearVel()const = 0; ! /// Given an offset point relative to the Solid's local origin, ! /// returns the linear velocity of the point in local coordinates. ! virtual Vec3r OPAL_CALL getLocalLinearVelAtLocalPos( ! const Point3r& p)const = 0; ! /// Sets the Solid's angular velocity in local coordinates. ! virtual void OPAL_CALL setLocalAngularVel(const Vec3r& vel) = 0; ! /// Returns the Solid's angular velocity in local coordinates. ! virtual Vec3r OPAL_CALL getLocalAngularVel()const = 0; ! /// Sets the Solid's linear velocity in global coordinates. ! virtual void OPAL_CALL setGlobalLinearVel(const Vec3r& vel) = 0; ! /// Returns the Solid's linear velocity in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalLinearVel()const = 0; ! /// Given an offset point relative to the Solid's local origin, ! /// returns the linear velocity of the point in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalLinearVelAtLocalPos( ! const Point3r& p)const = 0; ! /// Sets the Solid's angular velocity in global coordinates. ! virtual void OPAL_CALL setGlobalAngularVel(const Vec3r& vel) = 0; ! /// Returns the Solid's angular velocity in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalAngularVel()const = 0; ! /// Set a new mass, center, and intertia for the solid. ! virtual void OPAL_CALL setMass( const Mass & newmass, const Matrix44r & offset ) = 0; ! /// Translate the Solid's mass using the given offset vector ! /// specified in global coordinates. ! virtual void OPAL_CALL translateMass(const Vec3r& offset) = 0; ! /// Sets the Solid's collision event handler. ! virtual void OPAL_CALL setCollisionEventHandler( ! CollisionEventHandler* eventHandler); ! /// Returns the Solid's collision event handler. If this returns ! /// NULL, the Solid is not using one. ! virtual CollisionEventHandler* OPAL_CALL ! getCollisionEventHandler()const; ! //// Quickly spinning solids should be set as fast rotating solids to ! //// improve simulation accuracy. ! //virtual void OPAL_CALL setFastRotation(bool fast); ! //virtual bool OPAL_CALL getFastRotation()const; ! //virtual void OPAL_CALL setFastRotationAxis(Vec3r axis); ! /// Returns the Solid's mass. This will return 0 if the Solid ! /// is static. ! virtual real OPAL_CALL getMass()const = 0; ! /// Returns the Solid's inertia tensor as a 4x4 matrix. This will ! /// be the identity matrix if the Solid is static. ! virtual Matrix44r OPAL_CALL getInertiaTensor()const = 0; ! /// Update the OPAL transform using the physics engine transform. ! virtual void OPAL_CALL internal_updateOPALTransform() = 0; ! /// Update the physics engine transform using the OPAL transform. ! virtual void OPAL_CALL internal_updateEngineTransform() = 0; ! /// Loops over the Solid's list of Forces and applies them. ! virtual void OPAL_CALL internal_applyForces(real stepSize); ! /// Updates the SolidData sleeping value from the physics engine. ! void internal_updateSleeping(); ! /// Internal function used to destroy this object. ! virtual void OPAL_CALL internal_destroy(); ! protected: ! virtual ~Solid(); ! /// Physics engine-specific function for applying Forces to ! /// Solids. ! virtual void applyForce(const Force& f) = 0; ! /// Adds the given axis-aligned bounding box to the Solid's AABB. ! void addToLocalAABB(const real aabb[6]); ! /// Resets the Solid's axis-aligned bounding box. ! void resetAABB(); ! /// An internal list of this Solid's pending Forces. ! std::vector<Force> mForceList; ! /// Stores data describing the Solid. ! SolidData mData; ! /// The axis-aligned bounding box of all shapes in local ! /// coordinates. This array stores data in the following order: ! /// min x, max x, min y, max y, min z, max z. This gets updated ! /// whenever a shape is added or removed. ! real mLocalAABB[6]; ! /// Pointer to this Solid's collision event handler. ! CollisionEventHandler* mCollisionEventHandler; ! /// Pointer to user data. This is totally user-managed (i.e. OPAL ! /// will never delete it). ! void* mUserData; ! /// Data used for ! private: ! }; } --- 35,287 ---- namespace opal { ! class Mass; ! class Simulator; ! class Space; ! class ShapeData; ! /// Solids are the physical objects in a simulation. Solids can be ! /// static or dynamic: basically, dynamic Solids move, and static Solids ! /// don't move. (Static Solids can still be positioned manually.) All ! /// Solids start out enabled, but they don't do much until Shapes are ! /// added. ! class Solid ! { ! public: ! Solid(); ! /// Initializes the Solid with the given data structure. Calling ! /// this more than once will automatically destroy all the old ! /// Shapes before adding new ones. ! virtual void OPAL_CALL init( const SolidData& data ) = 0; ! /// Returns all data describing the Solid. ! virtual const SolidData& OPAL_CALL getData(); ! /// Sets the Solid's name. ! virtual void OPAL_CALL setName( const std::string& name ); ! /// Returns the Solid's name. ! virtual const std::string& OPAL_CALL getName() const; ! /// Returns true if the Solid is enabled. ! virtual bool OPAL_CALL isEnabled() const; ! /// Sets whether the Solid can collide with other Solids and be ! /// physically simulated. Forces applied to this Solid while ! /// disabled will be ignored. ! virtual void OPAL_CALL setEnabled( bool e ); ! /// Returns true if this is a static Solid. ! virtual bool OPAL_CALL isStatic() const; ! /// Sets whether the Solid should be static or dynamic. ! virtual void OPAL_CALL setStatic( bool s ) = 0; ! /// Removes the Solid from its current Space and adds it to the new ! /// Space. ! virtual void OPAL_CALL setSpace( Space* newSpace ) = 0; ! /// Sets whether the Solid is sleeping (i.e. set this to false to ! /// wake up a sleeping Solid). ! virtual void OPAL_CALL setSleeping( bool sleeping ) = 0; ! /// Returns true if the Solid is sleeping. If the Solid is static, ! /// this will always return true. ! virtual bool OPAL_CALL isSleeping() const = 0; ! /// Sets the Solid's sleepiness level. ! virtual void OPAL_CALL setSleepiness( real s ); ! /// Returns the Solid's sleepiness level. ! virtual real OPAL_CALL getSleepiness() const; ! /// Sets the amount of linear damping on this Solid. ! virtual void OPAL_CALL setLinearDamping( real ld ); ! /// Returns the amount of linear damping on this Solid. ! virtual real OPAL_CALL getLinearDamping() const; ! /// Sets the amount of angular damping on this Solid. ! virtual void OPAL_CALL setAngularDamping( real ad ); ! /// Returns the amount of angular damping on this Solid. ! virtual real OPAL_CALL getAngularDamping() const; ! /// Set this Solid's user data pointer to some external data. This ! /// can be used to let the Solid point to some user object (e.g. an ! /// object with a visual mesh). The user data is totally user-managed ! /// (i.e. it is not destroyed when the Solid is destroyed). ! virtual void OPAL_CALL setUserData( void* data ); ! /// Returns the user data pointer (NULL if it has not been set). ! virtual void* OPAL_CALL getUserData() const; ! /// Sets this Solid's transform matrix. ! virtual void OPAL_CALL setTransform( const Matrix44r& t ); ! /// Returns a constant reference to this Solid's transform. ! virtual const Matrix44r& OPAL_CALL getTransform() const; ! /// Sets the position of this Solid in global coordinates. ! virtual void OPAL_CALL setPosition( real x, real y, real z ); ! /// Sets the position of this Solid in global coordinates. ! virtual void OPAL_CALL setPosition( const Point3r & p ); ! /// Returns the position of this Solid in global coordinates. ! virtual Point3r OPAL_CALL getPosition() const; ! /// Returns the euler angles of the Solid's orientation. ! virtual Vec3r OPAL_CALL getEulerXYZ() const; ! /// Returns a quaternion representing the Solid's orientation. ! virtual Quaternion OPAL_CALL getQuaternion() const; ! /// Sets a quaternion representing the Solid's orientation. ! virtual void OPAL_CALL setQuaternion( const Quaternion & q ); ! /// Sets a quaternion representing the Solid's orientation. ! virtual void OPAL_CALL setQuaternion( real w, real x, real y, real z ); ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes relative to the Solid. ! virtual void OPAL_CALL getLocalAABB( real aabb[ 6 ] ) const; ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes in global coordinates. ! virtual void OPAL_CALL getGlobalAABB( real aabb[ 6 ] ) const; ! /// Removes all shapes from this Solid. Resets the Solid's ! /// axis-aligned bounding box. ! virtual void OPAL_CALL clearShapes() = 0; ! /// Adds a Shape to this Solid. Updates the Solid's axis-aligned ! /// bounding box. ! virtual void OPAL_CALL addShape( ShapeData& data ) = 0; ! /// Applies a force/torque to this Solid. If the Solid is disabled, ! /// the Solid is static, or the magnitude of the force/torque is ! /// zero, this will do nothing. ! virtual void OPAL_CALL addForce( const Force& f ); ! /// Removes all forces and torques currently affecting this Solid. ! virtual void OPAL_CALL zeroForces() = 0; ! /// Sets the Solid's linear velocity in local coordinates. ! virtual void OPAL_CALL setLocalLinearVel( const Vec3r& vel ) = 0; ! /// Returns the Solid's linear velocity in local coordinates. ! virtual Vec3r OPAL_CALL getLocalLinearVel() const = 0; ! /// Given an offset point relative to the Solid's local origin, ! /// returns the linear velocity of the point in local coordinates. ! virtual Vec3r OPAL_CALL getLocalLinearVelAtLocalPos( ! const Point3r& p ) const = 0; ! /// Sets the Solid's angular velocity in local coordinates. ! virtual void OPAL_CALL setLocalAngularVel( const Vec3r& vel ) = 0; ! /// Returns the Solid's angular velocity in local coordinates. ! virtual Vec3r OPAL_CALL getLocalAngularVel() const = 0; ! /// Sets the Solid's linear velocity in global coordinates. ! virtual void OPAL_CALL setGlobalLinearVel( const Vec3r& vel ) = 0; ! /// Returns the Solid's linear velocity in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalLinearVel() const = 0; ! /// Given an offset point relative to the Solid's local origin, ! /// returns the linear velocity of the point in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalLinearVelAtLocalPos( ! const Point3r& p ) const = 0; ! /// Sets the Solid's angular velocity in global coordinates. ! virtual void OPAL_CALL setGlobalAngularVel( const Vec3r& vel ) = 0; ! /// Returns the Solid's angular velocity in global coordinates. ! virtual Vec3r OPAL_CALL getGlobalAngularVel() const = 0; ! /// Set a new mass, center, and intertia for the solid. ! virtual void OPAL_CALL setMass( const Mass & newmass, const Matrix44r & offset ) = 0; ! /// Translate the Solid's mass using the given offset vector ! /// specified in global coordinates. ! virtual void OPAL_CALL translateMass( const Vec3r& offset ) = 0; ! /// Sets the Solid's collision event handler. ! virtual void OPAL_CALL setCollisionEventHandler( ! CollisionEventHandler* eventHandler ); ! /// Returns the Solid's collision event handler. If this returns ! /// NULL, the Solid is not using one. ! virtual CollisionEventHandler* OPAL_CALL ! getCollisionEventHandler() const; ! //// Quickly spinning solids should be set as fast rotating solids to ! //// improve simulation accuracy. ! //virtual void OPAL_CALL setFastRotation(bool fast); ! //virtual bool OPAL_CALL getFastRotation()const; ! //virtual void OPAL_CALL setFastRotationAxis(Vec3r axis); ! /// Returns the Solid's mass. This will return 0 if the Solid ! /// is static. ! virtual real OPAL_CALL getMass() const = 0; ! /// Returns the Solid's inertia tensor as a 4x4 matrix. This will ! /// be the identity matrix if the Solid is static. ! virtual Matrix44r OPAL_CALL getInertiaTensor() const = 0; ! /// Update the OPAL transform using the physics engine transform. ! virtual void OPAL_CALL internal_updateOPALTransform() = 0; ! /// Update the physics engine transform using the OPAL transform. ! virtual void OPAL_CALL internal_updateEngineTransform() = 0; ! /// Loops over the Solid's list of Forces and applies them. ! virtual void OPAL_CALL internal_applyForces( real stepSize ); ! /// Updates the SolidData sleeping value from the physics engine. ! void internal_updateSleeping(); ! /// Internal function used to destroy this object. ! virtual void OPAL_CALL internal_destroy(); ! protected: ! virtual ~Solid(); ! /// Physics engine-specific function for applying Forces to ! /// Solids. ! virtual void applyForce( const Force& f ) = 0; ! /// Adds the given axis-aligned bounding box to the Solid's AABB. ! void addToLocalAABB( const real aabb[ 6 ] ); ! /// Resets the Solid's axis-aligned bounding box. ! void resetAABB(); ! /// An internal list of this Solid's pending Forces. ! std::vector<Force> mForceList; ! /// Stores data describing the Solid. ! SolidData mData; ! /// The axis-aligned bounding box of all shapes in local ! /// coordinates. This array stores data in the following order: ! /// min x, max x, min y, max y, min z, max z. This gets updated ! /// whenever a shape is added or removed. ! real mLocalAABB[ 6 ]; ! /// Pointer to this Solid's collision event handler. ! CollisionEventHandler* mCollisionEventHandler; ! ! /// Pointer to user data. This is totally user-managed (i.e. OPAL ! /// will never delete it). ! void* mUserData; ! ! /// Data used for ! private: ! }; } Index: Quaternion.h =================================================================== RCS file: /cvsroot/opal/opal/src/Quaternion.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Quaternion.h 18 Apr 2005 22:21:03 -0000 1.9 --- Quaternion.h 1 Dec 2005 04:54:44 -0000 1.10 *************** *** 1,185 **** /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #ifndef OPAL_QUATERNION_H #define OPAL_QUATERNION_H #include "OpalMath.h" namespace opal { ! class Quaternion; ! inline Quaternion operator+(const Quaternion &q1, const Quaternion &q2); ! inline Quaternion operator-(const Quaternion &q1, const Quaternion &q2); ! inline Quaternion operator*(const Quaternion& q, real scalar); ! inline Quaternion operator*(real scalar, const Quaternion& q); ! /// Prints the Quaternion to the given output stream. ! inline std::ostream& operator<<(std::ostream& o, const Quaternion& q); ! class Quaternion ! { ! private: ! real mData[4]; ! public: ! Quaternion() ! { ! mData[0] = 0; ! mData[1] = 0; ! mData[2] = 0; ! mData[3] = 0; ! } ! Quaternion(real w, real x, real y, real z) ! { ! mData[0] = w; ! mData[1] = x; ! mData[2] = y; ! mData[3] = z; ! } ! Quaternion(const Quaternion& src) ! { ! memcpy(mData, src.mData, 4 * sizeof(real)); ! } ! inline void set(real w, real x, real y, real z ) ! { ! mData[0] = w; ! mData[1] = x; ! mData[2] = y; ! mData[3] = z; ! } ! inline real lengthSquared()const ! { ! return mData[0]*mData[0] + mData[1]*mData[1] + mData[2]*mData[2] + ! mData[3]*mData[3]; ! } ! inline real length()const ! { ! return sqrt(lengthSquared()); ! } ! inline void normalize() ! { ! real len = length(); ! assert(0 != len); ! real factor = 1 / len; ! (*this) = (*this) * factor; ! } ! void getAngleAxis(real& angle, Vec3r& axis) ! { ! real sqrLen = mData[1]*mData[1] + mData[2]*mData[2] + ! mData[3]*mData[3]; ! if(sqrLen > 0) ! { ! angle = 2 * acos(mData[0]); ! real invLen = 1 / sqrt(sqrLen); ! axis[0] = mData[1] * invLen; ! axis[1] = mData[2] * invLen; ! axis[2] = mData[3] * invLen; ! } ! else ! { ! angle = 0; ! axis[0] = 1; ! axis[1] = 0; ! axis[2] = 0; ! } ! // convert to degrees ! angle = radToDeg(angle); ! } ! real getRoll()const ! { ! return radToDeg(atan2(2*(mData[2]*mData[3] + mData[0]*mData[1]), ! mData[0]*mData[0] - mData[1]*mData[1] - mData[2]*mData[2] + ! mData[3]*mData[3])); ! } ! real getPitch()const ! { ! return radToDeg(asin(-2*(mData[1]*mData[3] - mData[0]*mData[2]))); ! } ! real getYaw()const ! { ! return radToDeg(atan2(2*(mData[1]*mData[2] + mData[0]*mData[3]), ! mData[0]*mData[0] + mData[1]*mData[1] - mData[2]*mData[2] - ! mData[3]*mData[3])); ! } ! inline real & operator[](unsigned int i) ! { ! assert(i < 4); ! return mData[i]; ! } ! inline const real & operator[](unsigned int i)const ! { ! assert(i < 4); ! return mData[i]; ! } ! }; ! inline Quaternion operator+(const Quaternion &q1, const Quaternion &q2) ! { ! return Quaternion(q1[0] + q2[0], q1[1] + q2[1], q1[2] + q2[2], q1[3] + ! q2[3]); ! } ! inline Quaternion operator-(const Quaternion &q1, const Quaternion &q2) ! { ! return Quaternion(q1[0] - q2[0], q1[1] - q2[1], q1[2] - q2[2], q1[3] - ! q2[3]); ! } ! inline Quaternion operator*(const Quaternion& q, real scalar) ! { ! return Quaternion(scalar * q[0], scalar * q[1], scalar * q[2], ! scalar * q[3]); ! } ! inline Quaternion operator*(real scalar, const Quaternion& q) ! { ! return Quaternion(scalar * q[0], scalar * q[1], scalar * q[2], ! scalar * q[3]); ! } ! inline std::ostream& operator<<(std::ostream& o, const Quaternion& q) ! { ! return o << "[" << q[0] << " " << q[1] << " " << q[2] << " " ! << q[3] << "]"; ! } } --- 1,206 ---- /************************************************************************* ! * * ! * Open Physics Abstraction Layer * ! * Copyright (C) 2004-2005 * ! * Alan Fischer ala...@gm... * ! * Andres Reinot an...@re... * ! * Tyler Streeter tyl...@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. * ! * * ! *************************************************************************/ #ifndef OPAL_QUATERNION_H #define OPAL_QUATERNION_H + // project headers #include "OpalMath.h" namespace opal { ! class Quaternion; ! inline Quaternion operator+( const Quaternion &q1, const Quaternion &q2 ); ! inline Quaternion operator-( const Quaternion &q1, const Quaternion &q2 ); ! inline Quaternion operator*( const Quaternion& q, real scalar ); ! inline Quaternion operator*( real scalar, const Quaternion& q ); ! inline bool operator==( const Quaternion &q1, const Quaternion &q2 ); ! inline bool operator!=( const Quaternion &q1, const Quaternion &q2 ); ! /// Prints the Quaternion to the given output stream. ! inline std::ostream& operator<<( std::ostream& o, const Quaternion& q ); ! class Quaternion ! { ! private: ! real mData[ 4 ]; ! public: ! Quaternion() ! { ! mData[ 0 ] = 0; ! mData[ 1 ] = 0; ! mData[ 2 ] = 0; ! mData[ 3 ] = 0; ! } ! Quaternion( real w, real x, real y, real z ) ! { ! mData[ 0 ] = w; ! mData[ 1 ] = x; ! mData[ 2 ] = y; ! mData[ 3 ] = z; ! } ! Quaternion( const Quaternion& src ) ! { ! memcpy( mData, src.mData, 4 * sizeof( real ) ); ! } ! inline void set( real w, real x, real y, real z ) ! { ! mData[ 0 ] = w; ! mData[ 1 ] = x; ! mData[ 2 ] = y; ! mData[ 3 ] = z; ! } ! inline real lengthSquared()... [truncated message content] |