[Opal-commits] opal/src VelocityMotor.cpp,NONE,1.1 VelocityMotor.h,NONE,1.1 VelocityMotorData.h,NONE
Status: Inactive
Brought to you by:
tylerstreeter
|
From: Olex <ole...@us...> - 2005-12-10 05:18:45
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11266/src Modified Files: Makefile.am Makefile.in Matrix44r.h MotorData.h OpalMath.h Simulator.cpp Simulator.h opal.h testMatrix44r.cpp Added Files: VelocityMotor.cpp VelocityMotor.h VelocityMotorData.h testBlueprint.cpp testMath.cpp testVelocityMotor.cpp Log Message: Implemented VelocityMotor and its unit test. Adjusted QuickTest. Added opal::normalizeDegrees(). --- NEW FILE: VelocityMotorData.h --- /************************************************************************* * * * 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_VELOCITY_MOTOR_DATA_H #define OPAL_VELOCITY_MOTOR_DATA_H // class headers #include "MotorData.h" // project headers #include "Defines.h" namespace opal { /// A data structure describing a VelocityMotor. class VelocityMotorData : public MotorData { public: OPAL_DECL VelocityMotorData() : MotorData() { mType = VELOCITY_MOTOR; solid = NULL; internal_solidIndex = 0; solidBlueprintRefName = ""; velocity = Vec3r( 0, 0, 0 ); maxForce = 1; letGravityAffectSolid = false; } /// Copy constructor. OPAL_DECL VelocityMotorData( const VelocityMotorData& data ) { ( *this ) = data; } OPAL_DECL virtual ~VelocityMotorData() {} /// Makes a deep copy. OPAL_DECL virtual void OPAL_CALL operator=( const VelocityMotorData& data ) { mType = data.mType; enabled = data.enabled; name = data.name; solid = data.solid; internal_solidIndex = data.internal_solidIndex; solidBlueprintRefName = data.solidBlueprintRefName; velocity = data.velocity; maxForce = data.maxForce; letGravityAffectSolid = data.letGravityAffectSolid; } /// Pointer to the Solid. Solid* solid; /// Maximum force that can be used to achieve target velocity. real maxForce; /// if true, the solid will be affected by gravity bool letGravityAffectSolid; /// Internal data used for Blueprint instantiation. int internal_solidIndex; /// String used for for intra-Blueprint references. std::string solidBlueprintRefName; /// The velocity that is to be achieved every frame Vec3r velocity; protected: private: }; } #endif Index: opal.h =================================================================== RCS file: /cvsroot/opal/opal/src/opal.h,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** opal.h 1 Dec 2005 02:04:54 -0000 1.30 --- opal.h 10 Dec 2005 05:18:35 -0000 1.31 *************** *** 49,52 **** --- 49,54 ---- #include "ThrusterMotor.h" #include "ThrusterMotorData.h" + #include "VelocityMotor.h" + #include "VelocityMotorData.h" #include "SpringMotor.h" #include "SpringMotorData.h" Index: Makefile.in =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.in,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.in 9 Dec 2005 18:11:23 -0000 1.9 --- Makefile.in 10 Dec 2005 05:18:35 -0000 1.10 *************** *** 63,67 **** SolidData.$(OBJEXT) Space.$(OBJEXT) SpringMotor.$(OBJEXT) \ ThrusterMotor.$(OBJEXT) VolumeSensor.$(OBJEXT) Vec3r.$(OBJEXT) \ ! Quaternion.$(OBJEXT) libopalode_a_OBJECTS = $(am_libopalode_a_OBJECTS) am__installdirs = "$(DESTDIR)$(bindir)" --- 63,67 ---- SolidData.$(OBJEXT) Space.$(OBJEXT) SpringMotor.$(OBJEXT) \ ThrusterMotor.$(OBJEXT) VolumeSensor.$(OBJEXT) Vec3r.$(OBJEXT) \ ! Quaternion.$(OBJEXT) VelocityMotor.$(OBJEXT) libopalode_a_OBJECTS = $(am_libopalode_a_OBJECTS) am__installdirs = "$(DESTDIR)$(bindir)" *************** *** 72,76 **** testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ testPoint3r.$(OBJEXT) testQuaternion.$(OBJEXT) \ ! testMatrix44r.$(OBJEXT) testBlueprint.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ --- 72,77 ---- testSimulator.$(OBJEXT) testVec3r.$(OBJEXT) \ testPoint3r.$(OBJEXT) testQuaternion.$(OBJEXT) \ ! testMatrix44r.$(OBJEXT) testBlueprint.$(OBJEXT) \ ! testMath.$(OBJEXT) testVelocityMotor.$(OBJEXT) test_opal_OBJECTS = $(am_test_opal_OBJECTS) test_opal_DEPENDENCIES = \ *************** *** 208,224 **** noinst_LIBRARIES = libopalode.a libopalode_a_SOURCES = AccelerationSensor.cpp AttractorMotor.cpp Blueprint.cpp \ ! BlueprintInstance.cpp BlueprintManager.cpp CollisionEventHandler.cpp GearedMotor.cpp \ ! InclineSensor.cpp Joint.cpp Logger.cpp Motor.cpp RaycastSensor.cpp Sensor.cpp \ ! ServoMotor.cpp Simulator.cpp Solid.cpp SolidData.cpp Space.cpp SpringMotor.cpp \ ! ThrusterMotor.cpp VolumeSensor.cpp Vec3r.cpp Quaternion.cpp test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp \ ! testMatrix44r.cpp testBlueprint.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode ! noinst_HEADERS = Mass.h all: all-recursive --- 209,225 ---- noinst_LIBRARIES = libopalode.a libopalode_a_SOURCES = AccelerationSensor.cpp AttractorMotor.cpp Blueprint.cpp \ ! BlueprintInstance.cpp BlueprintManager.cpp CollisionEventHandler.cpp GearedMotor.cpp \ ! InclineSensor.cpp Joint.cpp Logger.cpp Motor.cpp RaycastSensor.cpp Sensor.cpp \ ! ServoMotor.cpp Simulator.cpp Solid.cpp SolidData.cpp Space.cpp SpringMotor.cpp \ ! ThrusterMotor.cpp VolumeSensor.cpp Vec3r.cpp Quaternion.cpp VelocityMotor.cpp test_opal_SOURCES = testopal.cpp testsolid.cpp testAccelerationSensor.cpp \ ! testRaycastSensor.cpp testSimulator.cpp testVec3r.cpp testPoint3r.cpp testQuaternion.cpp \ ! testMatrix44r.cpp testBlueprint.cpp testMath.cpp testVelocityMotor.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode ! noinst_HEADERS = Mass.h VelocityMotor.h VelocityMotorData.h all: all-recursive *************** *** 321,327 **** --- 322,330 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ThrusterMotor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Vec3r.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/VelocityMotor.Po@am__quote@ @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)/testBlueprint.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testMath.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@ *************** *** 330,333 **** --- 333,337 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testSimulator.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testVec3r.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testVelocityMotor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testopal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testsolid.Po@am__quote@ --- NEW FILE: testVelocityMotor.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 testVelocityMotor { QT_TEST( constructor ) { Simulator * sim = createSimulator(); VelocityMotor * motor = sim->createVelocityMotor(); sim->destroyMotor( motor ); sim->destroy(); } class Fixture { public: Fixture() { sim = createSimulator(); sim->setGravity( Vec3r( 0, -9.81, 0 ) ); solid = sim->createSolid(); SphereShapeData data; data.radius = 1; data.material.density = 1; solid->addShape( data ); motor = sim->createVelocityMotor(); VelocityMotorData vdata; vdata.solid = solid; vdata.maxForce = 1000; motor->init( vdata ); } ~Fixture() { sim->destroyMotor( motor ); sim->destroySolid( solid ); sim->destroy(); } Simulator * sim; Solid * solid; VelocityMotor * motor; }; QT_TEST( check_default ) { Fixture f; f.sim->simulate( 0.2 ); QT_CHECK_CLOSE( f.solid->getGlobalLinearVel().x + f.solid->getGlobalLinearVel().z, 0 ); } QT_TEST( check_movement ) { Fixture f; f.motor->setVelocity( Vec3r( 1, 0, 0 ) ); f.sim->simulate( 0.2 ); QT_CHECK( f.solid->getGlobalLinearVel().length() > 0 ); } QT_TEST( check_achieving_velocity ) { Fixture f; f.motor->setVelocity( Vec3r( 1, 0, 0 ) ); for ( int i = 0; i < 5; ++i ) f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().x, 1, 0.01 ); // don't care about .y here QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().z, 0, 0.01 ); } QT_TEST( check_achieving_velocity_after_changing_it ) { Fixture f; f.motor->setVelocity( Vec3r( 1, 0, 0 ) ); for ( int i = 0; i < 5; ++i ) f.sim->simulate( 0.2 ); f.motor->setVelocity( Vec3r( 0, 0, 1 ) ); for ( int i = 0; i < 5; ++i ) f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().x, 0, 0.01 ); // don't care about .y here QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().z, 1, 0.01 ); } QT_TEST( check_achieving_velocity_upward ) { Fixture f; f.motor->setVelocity( Vec3r( 0, 1, 0 ) ); f.motor->letGravityAffectSolid( false ); for ( int i = 0; i < 50; ++i ) f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().x, 0, 0.01 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().y, 1, 0.01 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().z, 0, 0.01 ); } QT_TEST( check_achieving_velocity_downward ) { Fixture f; f.motor->setVelocity( Vec3r( 0, -1, 0 ) ); f.motor->letGravityAffectSolid( false ); for ( int i = 0; i < 5; ++i ) f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().x, 0, 0.01 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().y, -1, 0.01 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().z, 0, 0.01 ); } QT_TEST( check_achieving_velocity_while_allowing_gravity ) { Fixture f; f.motor->setVelocity( Vec3r( 1, 0, 0 ) ); f.motor->letGravityAffectSolid( true ); for ( int i = 0; i < 5; ++i ) f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().x, 1, 0.01 ); QT_CHECK_LESS( f.solid->getGlobalLinearVel().y, -0.1 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().z, 0, 0.01 ); } QT_TEST( enable_disable ) { Fixture f; f.motor->setVelocity( Vec3r( 0, 1, 0 ) ); f.motor->setEnabled( true ); f.sim->simulate( 0.2 ); QT_CHECK_GREATER( f.solid->getGlobalLinearVel().y, 0 ); real y = f.solid->getGlobalLinearVel().y; f.motor->setEnabled( false ); f.sim->simulate( 0.2 ); QT_CHECK_LESS( f.solid->getGlobalLinearVel().y, y ); y = f.solid->getGlobalLinearVel().y; f.motor->setEnabled( true ); f.sim->simulate( 0.2 ); QT_CHECK_GREATER( f.solid->getGlobalLinearVel().y, y ); } QT_TEST( not_enough_force ) { Fixture f; f.motor->setVelocity( Vec3r( 0, 1, 0 ) ); f.motor->setMaximumForce( 1 ); f.sim->simulate( 0.2 ); QT_CHECK_LESS( f.solid->getGlobalLinearVel().y, 0.5 ); f.motor->setMaximumForce( 1000 ); f.sim->simulate( 0.2 ); QT_CHECK_CLOSE_CUSTOM( f.solid->getGlobalLinearVel().y, 1, 0.01 ); } } Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** Simulator.cpp 1 Dec 2005 02:04:54 -0000 1.68 --- Simulator.cpp 10 Dec 2005 05:18:35 -0000 1.69 *************** *** 26,30 **** --- 26,33 ---- *************************************************************************/ + // class headers #include "Simulator.h" + + // project headers #include "BlueprintInstance.h" #include "BoxShapeData.h" *************** *** 42,45 **** --- 45,49 ---- #include "VolumeSensor.h" #include "PostStepEventHandler.h" + #include "VelocityMotor.h" namespace opal *************** *** 793,796 **** --- 797,807 ---- } + VelocityMotor* Simulator::createVelocityMotor() + { + VelocityMotor * newMotor = new VelocityMotor( this ); + addMotor( newMotor ); + return newMotor; + } + GearedMotor* Simulator::createGearedMotor() { Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** Simulator.h 26 Nov 2005 22:40:18 -0000 1.102 --- Simulator.h 10 Dec 2005 05:18:35 -0000 1.103 *************** *** 45,48 **** --- 45,49 ---- class SpringMotor; class ThrusterMotor; + class VelocityMotor; class AccelerationSensor; class InclineSensor; *************** *** 308,311 **** --- 309,315 ---- virtual ThrusterMotor* OPAL_CALL createThrusterMotor(); + /// Creates and returns a pointer to a VelocityMotor. + virtual VelocityMotor* OPAL_CALL createVelocityMotor(); + /// Creates and returns a pointer to a GearedMotor. virtual GearedMotor* OPAL_CALL createGearedMotor(); --- NEW FILE: VelocityMotor.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. * * * *************************************************************************/ // class headers #include "VelocityMotor.h" // project headers #include "Simulator.h" namespace opal { VelocityMotor::VelocityMotor( Simulator * sim ) { mSimulator = sim; } VelocityMotor::~VelocityMotor() {} void VelocityMotor::setVelocity( const Vec3r & velocity ) { mData.velocity = velocity; } const Vec3r & VelocityMotor::getVelocity() const { return mData.velocity; } void VelocityMotor::init( const VelocityMotorData & data ) { Motor::init(); mData = data; if ( mData.solid ) { mData.solid->setLinearDamping( 0 ); } } void VelocityMotor::setEnabled( bool e ) { mData.enabled = e; } bool VelocityMotor::isEnabled() const { return mData.enabled; } MotorType VelocityMotor::getType() const { return VELOCITY_MOTOR; } void VelocityMotor::setName( const std::string& name ) { mData.name = name; } const std::string & VelocityMotor::getName() const { return mData.name; } bool VelocityMotor::internal_dependsOnSolid( Solid * s ) const { if ( mData.solid == s ) return true; else return false; } void VelocityMotor::letGravityAffectSolid( bool affect ) { mData.letGravityAffectSolid = affect; } bool VelocityMotor::doesGravityAffectSolid() const { return mData.letGravityAffectSolid; } void VelocityMotor::internal_update() { // check if we have a solid if ( mData.solid == NULL || isEnabled() == false ) return ; Vec3r targetVelocity = mData.velocity; Solid * solid = mData.solid; Vec3r currentAchievedVelocity = solid->getGlobalLinearVel(); if ( doesGravityAffectSolid() ) { Vec3r gravity = mSimulator->getGravity(); if ( gravity.length() > 0 ) { Vec3r gravity_velocity = project( gravity, currentAchievedVelocity ); currentAchievedVelocity -= gravity_velocity; } } Vec3r deltaVelocity = targetVelocity - currentAchievedVelocity; Vec3r forceVector = deltaVelocity / mSimulator->getStepSize() * solid->getMass(); if ( !doesGravityAffectSolid() ) forceVector -= mSimulator->getGravity() * solid->getMass(); if ( forceVector.length() > getMaximumForce() ) { forceVector.normalize(); forceVector *= getMaximumForce(); } Force controllingForce; controllingForce.duration = 0; controllingForce.singleStep = true; controllingForce.type = GLOBAL_FORCE; controllingForce.vec = forceVector; solid->addForce( controllingForce ); } void VelocityMotor::setMaximumForce( real maxForce ) { mData.maxForce = maxForce; } real VelocityMotor::getMaximumForce() const { return mData.maxForce; } } --- NEW FILE: testBlueprint.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> #include <sstream> // project headers #include "opal.h" using namespace opal; namespace testBlueprint { QT_TEST( create_and_delete ) { Simulator * sim = createSimulator(); // Create a SolidData object. SolidData solid1Data; solid1Data.name = "object"; BoxShapeData boxData; solid1Data.addShape( boxData ); // Setup a Blueprint. Blueprint bp; bp.addSolid( &solid1Data ); bp.finalize(); sim->simulate( 0.2 ); QT_CHECK_EQUAL( sim->getNumSolids(), 0 ); { // Instantiate the Blueprint. BlueprintInstance instance; sim->instantiateBlueprint( instance, bp ); QT_CHECK_EQUAL( sim->getNumSolids(), 1 ); unsigned int nsolids = instance.getNumSolids(); for ( unsigned int i = 0; i < nsolids; ++i ) { sim->destroySolid( instance.getSolid( i ) ); } } sim->simulate( 0.2 ); QT_CHECK_EQUAL( sim->getNumSolids(), 0 ); } class MockCollisionHandler : public CollisionEventHandler { public: MockCollisionHandler() {} void handleCollisionEvent( const CollisionEvent & e ) { // nothing } }; QT_TEST( create_and_delete_with_callback ) { Simulator * sim = createSimulator(); // Create a SolidData object. SolidData solid1Data; solid1Data.name = "object"; BoxShapeData boxData; solid1Data.addShape( boxData ); // Setup a Blueprint. Blueprint bp; bp.addSolid( &solid1Data ); bp.finalize(); sim->simulate( 0.2 ); QT_CHECK_EQUAL( sim->getNumSolids(), 0 ); { // Instantiate the Blueprint. BlueprintInstance instance; sim->instantiateBlueprint( instance, bp ); QT_CHECK_EQUAL( sim->getNumSolids(), 1 ); MockCollisionHandler * callback = new MockCollisionHandler(); instance.getSolid( "object" ) ->setCollisionEventHandler( callback ); sim->simulate( 0.2 ); unsigned int nsolids = instance.getNumSolids(); for ( unsigned int i = 0; i < nsolids; ++i ) { sim->destroySolid( instance.getSolid( i ) ); } delete callback; } sim->simulate( 0.2 ); QT_CHECK_EQUAL( sim->getNumSolids(), 0 ); } } --- NEW FILE: testMath.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 testOpalMath { QT_TEST( normalizeDegrees ) { QT_CHECK_EQUAL( normalizeDegrees( 179.0 ), 179.0 ); QT_CHECK_EQUAL( normalizeDegrees( 180.0 ) , 180.0 ); QT_CHECK_EQUAL( normalizeDegrees( -179.0 ) , -179.0 ); QT_CHECK_EQUAL( normalizeDegrees( -180.0 ) , 180.0 ); QT_CHECK_EQUAL( normalizeDegrees( 360.0 + 20.0 ) , 20.0 ); QT_CHECK_EQUAL( normalizeDegrees( 360.0 + -20.0 ) , -20.0 ); QT_CHECK_EQUAL( normalizeDegrees( 180.0 + 20.0 ) , -160.0 ); } } --- NEW FILE: VelocityMotor.h --- /************************************************************************* * * * 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. * * * *************************************************************************/ #ifndef OPALVELOCITYMOTOR_H #define OPALVELOCITYMOTOR_H // class headers #include "Motor.h" // project headers #include "Portability.h" #include "VelocityMotorData.h" namespace opal { class Simulator; class VelocityMotorData; /** * Tries to achieve given velocity in one time step of the simulation. * * @author Oleksandr Lozitskiy <mr.olexander@gmail> */ class VelocityMotor : public Motor { public: //! constructor /*! * @param sim physical simulator */ VelocityMotor( Simulator * sim ); //! destructor ~VelocityMotor(); /// Initializes the Motor with the given data structure. void OPAL_CALL init( const VelocityMotorData & data ); /// Sets whether the Motor has any effect. void OPAL_CALL setEnabled( bool e ); /// Returns true if the Motor is enabled. bool OPAL_CALL isEnabled() const; /// Returns the Motor type. MotorType OPAL_CALL getType() const; /// Sets the Motor's name. void OPAL_CALL setName( const std::string & name ); /// Returns the Motor's name. const std::string & OPAL_CALL getName() const; /// Set target velocity. void OPAL_CALL setVelocity( const Vec3r & velocity ); /// Return target velocity. const Vec3r & OPAL_CALL getVelocity() const; /// Called regularly to update the Motor. This does nothing if the /// Motor is disabled. void OPAL_CALL internal_update(); //! Returns true if motors controls this solid. bool OPAL_CALL internal_dependsOnSolid( Solid * s ) const; //! against gravity or not? /*! * @param affect if true, motor will NOT work against gravity, * so solid will be affected by gravity */ void OPAL_CALL letGravityAffectSolid( bool affect ); //! Returns true if gravity is being ignored by the motor bool OPAL_CALL doesGravityAffectSolid() const; //! Maximum allowed force for the motor to use. void OPAL_CALL setMaximumForce( real maxForce ); //! What is the maximum allowed force for this motor? real OPAL_CALL getMaximumForce() const; protected: /// Stores data describing the Motor. VelocityMotorData mData; private: Simulator * mSimulator; }; } #endif Index: MotorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/MotorData.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MotorData.h 11 Mar 2005 05:31:56 -0000 1.3 --- MotorData.h 10 Dec 2005 05:18:35 -0000 1.4 *************** *** 40,44 **** SERVO_MOTOR, SPRING_MOTOR, ! THRUSTER_MOTOR }; --- 40,45 ---- SERVO_MOTOR, SPRING_MOTOR, ! THRUSTER_MOTOR, ! VELOCITY_MOTOR }; Index: OpalMath.h =================================================================== RCS file: /cvsroot/opal/opal/src/OpalMath.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** OpalMath.h 30 Nov 2005 06:28:12 -0000 1.15 --- OpalMath.h 10 Dec 2005 05:18:35 -0000 1.16 *************** *** 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_OPAL_MATH_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_OPAL_MATH_H *************** *** 34,100 **** namespace opal { ! #ifdef OPAL_USE_DOUBLE ! typedef double real; ! #else ! typedef float real; ! #endif ! namespace globals ! { ! const real OPAL_PI = (real)3.14159265358979323846; ! const real OPAL_HALF_PI = (real)1.57079632679489661923; ! const real OPAL_ONE_THIRD = (real)0.33333333333333333333; ! const real OPAL_EPSILON = (real)0.000001; ! } ! /// Converts a value from degrees to radians. ! inline real degToRad(real deg) ! { ! const real d2r = globals::OPAL_PI/(real)180.0; ! return (d2r * deg); ! } ! /// Converts a value from radians to degrees. ! inline real radToDeg(real rad) ! { ! const real r2d = (real)180.0/globals::OPAL_PI; ! return (r2d * rad); ! } ! /// Returns the absolute value of a real number. ! inline real abs(real value) ! { ! 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. ! /// See Christer Ericson's GDC 2005 presentation: ! /// http://realtimecollisiondetection.net/pubs/GDC05_Ericson_Numerical_Robustness_for_Geometric_Calculations.ppt ! 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; ! } ! } } --- 34,114 ---- namespace opal { ! #ifdef OPAL_USE_DOUBLE ! typedef double real; ! #else ! typedef float real; ! #endif ! namespace globals ! { ! const real OPAL_PI = ( real ) 3.14159265358979323846; ! const real OPAL_HALF_PI = ( real ) 1.57079632679489661923; ! const real OPAL_ONE_THIRD = ( real ) 0.33333333333333333333; ! const real OPAL_EPSILON = ( real ) 0.000001; ! } ! /// Converts a value from degrees to radians. ! inline real degToRad( real deg ) ! { ! const real d2r = globals::OPAL_PI / ( real ) 180.0; ! return ( d2r * deg ); ! } ! /// Converts a value from radians to degrees. ! inline real radToDeg( real rad ) ! { ! const real r2d = ( real ) 180.0 / globals::OPAL_PI; ! return ( r2d * rad ); ! } ! /// Returns the absolute value of a real number. ! inline real abs( real value ) ! { ! 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. ! /// See Christer Ericson's GDC 2005 presentation: ! /// http://realtimecollisiondetection.net/pubs/GDC05_Ericson_Numerical_Robustness_for_Geometric_Calculations.ppt ! 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; ! } ! } ! ! //! translates degree angle to (-180, 180] ! inline real normalizeDegrees( real degrees ) ! { ! while ( degrees > 180.0 ) ! { ! degrees -= 360.0; ! } ! while ( degrees <= -180.0 ) ! { ! degrees += 360.0; ! } ! return degrees; ! } } Index: testMatrix44r.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/testMatrix44r.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testMatrix44r.cpp 9 Dec 2005 18:11:23 -0000 1.3 --- testMatrix44r.cpp 10 Dec 2005 05:18:35 -0000 1.4 *************** *** 41,45 **** Matrix44r m; m.setQuaternion( 0, 0, 0, 1 ); ! QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, -180 ) ); QT_CHECK_EQUAL( m.getQuaternion(), Quaternion( 0, 0, 0, 1 ) ); --- 41,45 ---- Matrix44r m; m.setQuaternion( 0, 0, 0, 1 ); ! QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, 180 ) ); QT_CHECK_EQUAL( m.getQuaternion(), Quaternion( 0, 0, 0, 1 ) ); *************** *** 51,55 **** Matrix44r m; m.setQuaternion( Quaternion( 0, 0, 0, 1 ) ); ! QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, -180 ) ); QT_CHECK_EQUAL( m.getQuaternion(), Quaternion( 0, 0, 0, 1 ) ); --- 51,55 ---- Matrix44r m; m.setQuaternion( Quaternion( 0, 0, 0, 1 ) ); ! QT_CHECK_EQUAL( m.getEulerXYZ(), Vec3r( 0, 0, 180 ) ); QT_CHECK_EQUAL( m.getQuaternion(), Quaternion( 0, 0, 0, 1 ) ); Index: Makefile.am =================================================================== RCS file: /cvsroot/opal/opal/src/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.am 9 Dec 2005 18:11:23 -0000 1.9 --- Makefile.am 10 Dec 2005 05:18:35 -0000 1.10 *************** *** 9,21 **** noinst_LIBRARIES = libopalode.a libopalode_a_SOURCES = AccelerationSensor.cpp AttractorMotor.cpp Blueprint.cpp \ ! BlueprintInstance.cpp BlueprintManager.cpp CollisionEventHandler.cpp GearedMotor.cpp \ ! InclineSensor.cpp Joint.cpp Logger.cpp Motor.cpp RaycastSensor.cpp Sensor.cpp \ ! ServoMotor.cpp Simulator.cpp Solid.cpp SolidData.cpp Space.cpp SpringMotor.cpp \ ! ThrusterMotor.cpp VolumeSensor.cpp Vec3r.cpp Quaternion.cpp 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 testBlueprint.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode ! noinst_HEADERS = Mass.h --- 9,21 ---- noinst_LIBRARIES = libopalode.a libopalode_a_SOURCES = AccelerationSensor.cpp AttractorMotor.cpp Blueprint.cpp \ ! BlueprintInstance.cpp BlueprintManager.cpp CollisionEventHandler.cpp GearedMotor.cpp \ ! InclineSensor.cpp Joint.cpp Logger.cpp Motor.cpp RaycastSensor.cpp Sensor.cpp \ ! ServoMotor.cpp Simulator.cpp Solid.cpp SolidData.cpp Space.cpp SpringMotor.cpp \ ! ThrusterMotor.cpp VolumeSensor.cpp Vec3r.cpp Quaternion.cpp VelocityMotor.cpp 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 testBlueprint.cpp testMath.cpp testVelocityMotor.cpp test_opal_LDADD = $(top_builddir)/src/external/tinyxml/libtinyxml.a \ $(top_builddir)/src/ODE/libodeimpl.a $(top_builddir)/src/libopalode.a -lode ! noinst_HEADERS = Mass.h VelocityMotor.h VelocityMotorData.h Index: Matrix44r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Matrix44r.h,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Matrix44r.h 1 Dec 2005 23:55:21 -0000 1.40 --- Matrix44r.h 10 Dec 2005 05:18:35 -0000 1.41 *************** *** 370,373 **** --- 370,378 ---- } + // normalize to (-180,180] + angles[ 0 ] = normalizeDegrees( angles[ 0 ] ); + angles[ 1 ] = normalizeDegrees( angles[ 1 ] ); + angles[ 2 ] = normalizeDegrees( angles[ 2 ] ); + // convert to degrees angles[ 0 ] = radToDeg( angles[ 0 ] ); |