Introduced btActionInterface. This makes it easier to extend user-defined actions, such as vehicles and characters.

btRaycastVehicle and btKinematicCharacterController are derived from btActionInterface now.
Some cosmetic cleanup: changed sourceforce/sf.net url to bulletphysics.com.
This commit is contained in:
erwin.coumans
2009-03-03 16:18:23 +00:00
parent 459c22e7cb
commit 90f96aec27
38 changed files with 409 additions and 203 deletions

View File

@@ -0,0 +1,39 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _BT_ACTION_INTERFACE_H
#define _BT_ACTION_INTERFACE_H
class btIDebugDraw;
class btCollisionWorld;
#include "LinearMath/btScalar.h"
///Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWorld
class btActionInterface
{
public:
virtual ~btActionInterface()
{
}
virtual void updateAction( btCollisionWorld* collisionWorld, btScalar deltaTimeStep)=0;
virtual void debugDraw(btIDebugDraw* debugDrawer) = 0;
};
#endif //_BT_ACTION_INTERFACE_H

View File

@@ -90,8 +90,7 @@ void btContinuousDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
integrateTransforms(timeStep * toi);
///update vehicle simulation
updateVehicles(timeStep);
updateActions(timeStep);
updateActivationState( timeStep );

View File

@@ -51,15 +51,7 @@ subject to the following restrictions:
#include "LinearMath/btIDebugDraw.h"
//vehicle
#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
#include "BulletDynamics/Vehicle/btWheelInfo.h"
//character
#include "BulletDynamics/Character/btCharacterControllerInterface.h"
#include "LinearMath/btIDebugDraw.h"
#include "BulletDynamics/Dynamics/btActionInterface.h"
#include "LinearMath/btQuickprof.h"
#include "LinearMath/btMotionState.h"
@@ -212,32 +204,11 @@ void btDiscreteDynamicsWorld::debugDrawWorld()
}
for ( i=0;i<this->m_vehicles.size();i++)
if (getDebugDrawer() && getDebugDrawer()->getDebugMode())
{
for (int v=0;v<m_vehicles[i]->getNumWheels();v++)
for (i=0;i<m_actions.size();i++)
{
btVector3 wheelColor(0,255,255);
if (m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_isInContact)
{
wheelColor.setValue(0,0,255);
} else
{
wheelColor.setValue(255,0,255);
}
btVector3 wheelPosWS = m_vehicles[i]->getWheelInfo(v).m_worldTransform.getOrigin();
btVector3 axle = btVector3(
m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[0][m_vehicles[i]->getRightAxis()],
m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[1][m_vehicles[i]->getRightAxis()],
m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[2][m_vehicles[i]->getRightAxis()]);
//m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_wheelAxleWS
//debug wheels (cylinders)
m_debugDrawer->drawLine(wheelPosWS,wheelPosWS+axle,wheelColor);
m_debugDrawer->drawLine(wheelPosWS,m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_contactPointWS,wheelColor);
m_actions[i]->debugDraw(m_debugDrawer);
}
}
}
@@ -309,7 +280,7 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
synchronizeSingleMotionState(body);
}
}
/*
if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
{
for ( int i=0;i<this->m_vehicles.size();i++)
@@ -321,6 +292,8 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
}
}
}
*/
}
@@ -426,10 +399,8 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
integrateTransforms(timeStep);
///update vehicle simulation
updateVehicles(timeStep);
updateActions(timeStep);
updateCharacters(timeStep);
updateActivationState( timeStep );
if(0 != m_internalTickCallback) {
@@ -493,29 +464,15 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short
}
void btDiscreteDynamicsWorld::updateVehicles(btScalar timeStep)
void btDiscreteDynamicsWorld::updateActions(btScalar timeStep)
{
BT_PROFILE("updateVehicles");
BT_PROFILE("updateActions");
for ( int i=0;i<m_vehicles.size();i++)
for ( int i=0;i<m_actions.size();i++)
{
btRaycastVehicle* vehicle = m_vehicles[i];
vehicle->updateVehicle( timeStep);
m_actions[i]->updateAction( this, timeStep);
}
}
void btDiscreteDynamicsWorld::updateCharacters(btScalar timeStep)
{
BT_PROFILE("updateCharacters");
for ( int i=0;i<m_characters.size();i++)
{
btCharacterControllerInterface* character = m_characters[i];
character->preStep (this);
character->playerStep (this,timeStep);
}
}
void btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep)
@@ -572,24 +529,35 @@ void btDiscreteDynamicsWorld::removeConstraint(btTypedConstraint* constraint)
constraint->getRigidBodyB().removeConstraintRef(constraint);
}
void btDiscreteDynamicsWorld::addVehicle(btRaycastVehicle* vehicle)
void btDiscreteDynamicsWorld::addAction(btActionInterface* action)
{
m_vehicles.push_back(vehicle);
m_actions.push_back(action);
}
void btDiscreteDynamicsWorld::removeVehicle(btRaycastVehicle* vehicle)
void btDiscreteDynamicsWorld::removeAction(btActionInterface* action)
{
m_vehicles.remove(vehicle);
m_actions.remove(action);
}
void btDiscreteDynamicsWorld::addCharacter(btCharacterControllerInterface* character)
void btDiscreteDynamicsWorld::addVehicle(btActionInterface* vehicle)
{
m_characters.push_back(character);
addAction(vehicle);
}
void btDiscreteDynamicsWorld::removeCharacter(btCharacterControllerInterface* character)
void btDiscreteDynamicsWorld::removeVehicle(btActionInterface* vehicle)
{
m_characters.remove(character);
removeAction(vehicle);
}
void btDiscreteDynamicsWorld::addCharacter(btActionInterface* character)
{
addAction(character);
}
void btDiscreteDynamicsWorld::removeCharacter(btActionInterface* character)
{
removeAction(character);
}

View File

@@ -23,10 +23,8 @@ class btOverlappingPairCache;
class btConstraintSolver;
class btSimulationIslandManager;
class btTypedConstraint;
class btActionInterface;
class btRaycastVehicle;
class btCharacterControllerInterface;
class btIDebugDraw;
#include "LinearMath/btAlignedObjectArray.h"
@@ -52,12 +50,8 @@ protected:
bool m_ownsIslandManager;
bool m_ownsConstraintSolver;
btAlignedObjectArray<btActionInterface*> m_actions;
btAlignedObjectArray<btRaycastVehicle*> m_vehicles;
btAlignedObjectArray<btCharacterControllerInterface*> m_characters;
int m_profileTimings;
virtual void predictUnconstraintMotion(btScalar timeStep);
@@ -70,9 +64,7 @@ protected:
void updateActivationState(btScalar timeStep);
void updateVehicles(btScalar timeStep);
void updateCharacters(btScalar timeStep);
void updateActions(btScalar timeStep);
void startProfiling(btScalar timeStep);
@@ -105,15 +97,10 @@ public:
virtual void removeConstraint(btTypedConstraint* constraint);
virtual void addVehicle(btRaycastVehicle* vehicle);
virtual void addAction(btActionInterface*);
virtual void removeVehicle(btRaycastVehicle* vehicle);
virtual void removeAction(btActionInterface*);
virtual void addCharacter(btCharacterControllerInterface* character);
virtual void removeCharacter(btCharacterControllerInterface* character);
btSimulationIslandManager* getSimulationIslandManager()
{
return m_islandManager;
@@ -130,6 +117,7 @@ public:
}
virtual void setGravity(const btVector3& gravity);
virtual btVector3 getGravity () const;
virtual void addRigidBody(btRigidBody* body);
@@ -171,6 +159,15 @@ public:
(void) numTasks;
}
///obsolete, use addAction instead
virtual void addVehicle(btActionInterface* vehicle);
///obsolete, use removeAction instead
virtual void removeVehicle(btActionInterface* vehicle);
///obsolete, use addAction instead
virtual void addCharacter(btActionInterface* character);
///obsolete, use removeAction instead
virtual void removeCharacter(btActionInterface* character);
};
#endif //BT_DISCRETE_DYNAMICS_WORLD_H

View File

@@ -20,10 +20,10 @@ subject to the following restrictions:
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
class btTypedConstraint;
class btRaycastVehicle;
class btActionInterface;
class btConstraintSolver;
class btDynamicsWorld;
class btCharacterControllerInterface;
/// Type for the callback for each tick
typedef void (*btInternalTickCallback)(btDynamicsWorld *world, btScalar timeStep);
@@ -72,14 +72,9 @@ public:
virtual void removeConstraint(btTypedConstraint* constraint) {(void)constraint;}
virtual void addVehicle(btRaycastVehicle* vehicle) {(void)vehicle;}
virtual void removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;}
virtual void addCharacter(btCharacterControllerInterface* character) {(void)character;}
virtual void removeCharacter(btCharacterControllerInterface* character) {(void)character;}
virtual void addAction(btActionInterface* action) = 0;
virtual void removeAction(btActionInterface* action) = 0;
//once a rigidbody is added to the dynamics world, it will get this gravity assigned
//existing rigidbodies in the world get gravity assigned too, during this method
@@ -129,6 +124,16 @@ public:
}
///obsolete, use addAction instead.
virtual void addVehicle(btActionInterface* vehicle) {(void)vehicle;}
///obsolete, use removeAction instead
virtual void removeVehicle(btActionInterface* vehicle) {(void)vehicle;}
///obsolete, use addAction instead.
virtual void addCharacter(btActionInterface* character) {(void)character;}
///obsolete, use removeAction instead
virtual void removeCharacter(btActionInterface* character) {(void)character;}
};
#endif //BT_DYNAMICS_WORLD_H