fixed some merging conflicts
This commit is contained in:
@@ -333,12 +333,12 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const btCollisionShape* shape, const b
|
||||
|
||||
glDisable(GL_DEPTH_BUFFER_BIT);
|
||||
glRasterPos3f(0,0,0);//mvtx.x(), vtx.y(), vtx.z());
|
||||
if (debugMode&IDebugDraw::DBG_DrawText)
|
||||
if (debugMode&btIDebugDraw::DBG_DrawText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->GetName());
|
||||
}
|
||||
|
||||
if (debugMode&IDebugDraw::DBG_DrawFeaturesText)
|
||||
if (debugMode& btIDebugDraw::DBG_DrawFeaturesText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->GetExtraDebugInfo());
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class btCollisionShape;
|
||||
struct btCollisionObject
|
||||
{
|
||||
btTransform m_worldTransform;
|
||||
BroadphaseProxy* m_broadphaseHandle;
|
||||
CollisionShape* m_collisionShape;
|
||||
btBroadphaseProxy* m_broadphaseHandle;
|
||||
btCollisionShape* m_collisionShape;
|
||||
|
||||
//m_interpolationWorldTransform is used for CCD and interpolation
|
||||
//it can be either previous or future (predicted) transform
|
||||
|
||||
@@ -1,327 +1,18 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
#include "btDiscreteDynamicsWorld.h"
|
||||
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:
|
||||
|
||||
//collision detection
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
|
||||
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.
|
||||
*/
|
||||
|
||||
//rigidbody & constraints
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
||||
|
||||
//vehicle
|
||||
#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
|
||||
#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
|
||||
#include "BulletDynamics/Vehicle/btWheelInfo.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld()
|
||||
:btDynamicsWorld(new CollisionDispatcher(),new SimpleBroadphase()),
|
||||
m_constraintSolver(new SequentialImpulseConstraintSolver)
|
||||
{
|
||||
m_islandManager = new SimulationIslandManager();
|
||||
}
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(Dispatcher* dispatcher,OverlappingPairCache* pairCache,ConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver)
|
||||
{
|
||||
m_islandManager = new SimulationIslandManager();
|
||||
}
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld()
|
||||
{
|
||||
delete m_islandManager ;
|
||||
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete the dispatcher and paircache
|
||||
delete m_dispatcher1;
|
||||
m_dispatcher1 = 0;
|
||||
delete m_pairCache;
|
||||
m_pairCache = 0;
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::stepSimulation(float timeStep)
|
||||
{
|
||||
///update aabbs information
|
||||
updateAabbs();
|
||||
|
||||
///apply gravity, predict motion
|
||||
predictUnconstraintMotion(timeStep);
|
||||
|
||||
///perform collision detection
|
||||
PerformDiscreteCollisionDetection();
|
||||
|
||||
calculateSimulationIslands();
|
||||
|
||||
ContactSolverInfo infoGlobal;
|
||||
infoGlobal.m_timeStep = timeStep;
|
||||
|
||||
///solve non-contact constraints
|
||||
solveNoncontactConstraints(infoGlobal);
|
||||
|
||||
///solve contact constraints
|
||||
solveContactConstraints(infoGlobal);
|
||||
|
||||
///update vehicle simulation
|
||||
updateVehicles(timeStep);
|
||||
|
||||
///CallbackTriggers();
|
||||
|
||||
///integrate transforms
|
||||
integrateTransforms(timeStep);
|
||||
|
||||
updateActivationState( timeStep );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::updateVehicles(float timeStep)
|
||||
{
|
||||
for (int i=0;i<m_vehicles.size();i++)
|
||||
{
|
||||
RaycastVehicle* vehicle = m_vehicles[i];
|
||||
vehicle->UpdateVehicle( timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::updateActivationState(float timeStep)
|
||||
{
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
|
||||
body->updateDeactivation(timeStep);
|
||||
|
||||
if (body->wantsSleeping())
|
||||
{
|
||||
if (body->GetActivationState() == ACTIVE_TAG)
|
||||
body->SetActivationState( WANTS_DEACTIVATION );
|
||||
} else
|
||||
{
|
||||
if (body->GetActivationState() != DISABLE_DEACTIVATION)
|
||||
body->SetActivationState( ACTIVE_TAG );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::addConstraint(TypedConstraint* constraint)
|
||||
{
|
||||
m_constraints.push_back(constraint);
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::removeConstraint(TypedConstraint* constraint)
|
||||
{
|
||||
std::vector<TypedConstraint*>::iterator cit = std::find(m_constraints.begin(),m_constraints.end(),constraint);
|
||||
if (!(cit==m_constraints.end()))
|
||||
{
|
||||
m_constraints.erase(cit);
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::addVehicle(RaycastVehicle* vehicle)
|
||||
{
|
||||
m_vehicles.push_back(vehicle);
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::removeVehicle(RaycastVehicle* vehicle)
|
||||
{
|
||||
std::vector<RaycastVehicle*>::iterator vit = std::find(m_vehicles.begin(),m_vehicles.end(),vehicle);
|
||||
if (!(vit==m_vehicles.end()))
|
||||
{
|
||||
m_vehicles.erase(vit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btDiscreteDynamicsWorld::solveContactConstraints(ContactSolverInfo& solverInfo)
|
||||
{
|
||||
|
||||
struct InplaceSolverIslandCallback : public SimulationIslandManager::IslandCallback
|
||||
{
|
||||
|
||||
ContactSolverInfo& m_solverInfo;
|
||||
ConstraintSolver* m_solver;
|
||||
IDebugDraw* m_debugDrawer;
|
||||
|
||||
InplaceSolverIslandCallback(
|
||||
ContactSolverInfo& solverInfo,
|
||||
ConstraintSolver* solver,
|
||||
IDebugDraw* debugDrawer)
|
||||
:m_solverInfo(solverInfo),
|
||||
m_solver(solver),
|
||||
m_debugDrawer(debugDrawer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void ProcessIsland(PersistentManifold** manifolds,int numManifolds)
|
||||
{
|
||||
m_solver->SolveGroup( manifolds, numManifolds,m_solverInfo,m_debugDrawer);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IDebugDraw* debugDraw = 0;
|
||||
InplaceSolverIslandCallback solverCallback( solverInfo, m_constraintSolver, debugDraw);
|
||||
|
||||
|
||||
/// solve all the contact points and contact friction
|
||||
m_islandManager->BuildAndProcessIslands(GetCollisionWorld()->GetDispatcher(),GetCollisionWorld()->GetCollisionObjectArray(),&solverCallback);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void btDiscreteDynamicsWorld::solveNoncontactConstraints(ContactSolverInfo& solverInfo)
|
||||
{
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("SolveConstraint");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
|
||||
int i;
|
||||
int numConstraints = m_constraints.size();
|
||||
|
||||
///constraint preparation: building jacobians
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
constraint->BuildJacobian();
|
||||
}
|
||||
|
||||
//solve the regular non-contact constraints (point 2 point, hinge, generic d6)
|
||||
for (int g=0;g<solverInfo.m_numIterations;g++)
|
||||
{
|
||||
//
|
||||
// constraint solving
|
||||
//
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
constraint->SolveConstraint( solverInfo.m_timeStep );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("SolveConstraint");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::calculateSimulationIslands()
|
||||
{
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("IslandUnionFind");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
GetSimulationIslandManager()->UpdateActivationState(GetCollisionWorld(),GetCollisionWorld()->GetDispatcher());
|
||||
|
||||
{
|
||||
int i;
|
||||
int numConstraints = m_constraints.size();
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
|
||||
const RigidBody* colObj0 = &constraint->GetRigidBodyA();
|
||||
const RigidBody* colObj1 = &constraint->GetRigidBodyB();
|
||||
|
||||
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
|
||||
((colObj1) && ((colObj1)->mergesSimulationIslands())))
|
||||
{
|
||||
if (colObj0->IsActive() || colObj1->IsActive())
|
||||
{
|
||||
|
||||
GetSimulationIslandManager()->GetUnionFind().unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Store the island id in each body
|
||||
GetSimulationIslandManager()->StoreIslandActivationState(GetCollisionWorld());
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("IslandUnionFind");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::updateAabbs()
|
||||
{
|
||||
SimdTransform predictedTrans;
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
SimdPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->GetAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
SimpleBroadphase* bp = (SimpleBroadphase*)m_pairCache;
|
||||
bp->SetAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::integrateTransforms(float timeStep)
|
||||
{
|
||||
SimdTransform predictedTrans;
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||
body->proceedToTransform( predictedTrans);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btDiscreteDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
{
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
body->m_cachedInvertedWorldTransform = body->m_worldTransform.inverse();
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
body->integrateVelocities( timeStep);
|
||||
body->predictIntegratedTransform(timeStep,body->m_interpolationWorldTransform);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}=======
|
||||
|
||||
#include "btDiscreteDynamicsWorld.h"
|
||||
|
||||
|
||||
@@ -18,103 +18,6 @@ subject to the following restrictions:
|
||||
|
||||
#include "btDynamicsWorld.h"
|
||||
|
||||
class Dispatcher;
|
||||
class OverlappingPairCache;
|
||||
class ConstraintSolver;
|
||||
class SimulationIslandManager;
|
||||
class TypedConstraint;
|
||||
struct ContactSolverInfo;
|
||||
class RaycastVehicle;
|
||||
|
||||
#include <vector>
|
||||
|
||||
///btDiscreteDynamicsWorld provides discrete rigid body simulation
|
||||
///those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController
|
||||
class btDiscreteDynamicsWorld : public btDynamicsWorld
|
||||
{
|
||||
protected:
|
||||
|
||||
ConstraintSolver* m_constraintSolver;
|
||||
|
||||
SimulationIslandManager* m_islandManager;
|
||||
|
||||
std::vector<TypedConstraint*> m_constraints;
|
||||
|
||||
std::vector<RaycastVehicle*> m_vehicles;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
|
||||
void updateAabbs();
|
||||
|
||||
void calculateSimulationIslands();
|
||||
|
||||
void solveNoncontactConstraints(ContactSolverInfo& solverInfo);
|
||||
|
||||
void solveContactConstraints(ContactSolverInfo& solverInfo);
|
||||
|
||||
void updateActivationState(float timeStep);
|
||||
|
||||
void updateVehicles(float timeStep);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld(Dispatcher* dispatcher,OverlappingPairCache* pairCache,ConstraintSolver* constraintSolver);
|
||||
|
||||
btDiscreteDynamicsWorld();
|
||||
|
||||
virtual ~btDiscreteDynamicsWorld();
|
||||
|
||||
virtual void stepSimulation( float timeStep);
|
||||
|
||||
void addConstraint(TypedConstraint* constraint);
|
||||
|
||||
void removeConstraint(TypedConstraint* constraint);
|
||||
|
||||
void addVehicle(RaycastVehicle* vehicle);
|
||||
|
||||
void removeVehicle(RaycastVehicle* vehicle);
|
||||
|
||||
SimulationIslandManager* GetSimulationIslandManager()
|
||||
{
|
||||
return m_islandManager;
|
||||
}
|
||||
|
||||
const SimulationIslandManager* GetSimulationIslandManager() const
|
||||
{
|
||||
return m_islandManager;
|
||||
}
|
||||
|
||||
CollisionWorld* GetCollisionWorld()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DISCRETE_DYNAMICS_WORLD_H=======
|
||||
/*
|
||||
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_DISCRETE_DYNAMICS_WORLD_H
|
||||
#define BT_DISCRETE_DYNAMICS_WORLD_H
|
||||
|
||||
#include "btDynamicsWorld.h"
|
||||
|
||||
class btDispatcher;
|
||||
class btOverlappingPairCache;
|
||||
class btConstraintSolver;
|
||||
|
||||
@@ -1,50 +1,3 @@
|
||||
<<<<<<< .working
|
||||
/*
|
||||
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_DYNAMICS_WORLD_H
|
||||
#define BT_DYNAMICS_WORLD_H
|
||||
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
class TypedConstraint;
|
||||
|
||||
///btDynamicsWorld is the baseclass for several dynamics implementation, basic, discrete, parallel, and continuous
|
||||
class btDynamicsWorld : public CollisionWorld
|
||||
{
|
||||
public:
|
||||
|
||||
btDynamicsWorld(Dispatcher* dispatcher,OverlappingPairCache* pairCache)
|
||||
:CollisionWorld(dispatcher,pairCache)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~btDynamicsWorld()
|
||||
{
|
||||
}
|
||||
|
||||
///stepSimulation proceeds the simulation over timeStep units
|
||||
virtual void stepSimulation( float timeStep) = 0;
|
||||
|
||||
|
||||
virtual void addConstraint(TypedConstraint* constraint) {};
|
||||
|
||||
virtual void removeConstraint(TypedConstraint* constraint) {};
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DYNAMICS_WORLD_H=======
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
@@ -90,4 +43,5 @@ class btDynamicsWorld : public btCollisionWorld
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DYNAMICS_WORLD_H>>>>>>> .merge-right.r324
|
||||
#endif //BT_DYNAMICS_WORLD_H
|
||||
|
||||
|
||||
@@ -42,22 +42,22 @@ extern float gAngularSleepingTreshold;
|
||||
class btRigidBody : public btCollisionObject
|
||||
{
|
||||
|
||||
SimdMatrix3x3 m_invInertiaTensorWorld;
|
||||
SimdVector3 m_linearVelocity;
|
||||
SimdVector3 m_angularVelocity;
|
||||
SimdScalar m_inverseMass;
|
||||
btMatrix3x3 m_invInertiaTensorWorld;
|
||||
btVector3 m_linearVelocity;
|
||||
btVector3 m_angularVelocity;
|
||||
btScalar m_inverseMass;
|
||||
|
||||
SimdVector3 m_gravity;
|
||||
SimdVector3 m_invInertiaLocal;
|
||||
SimdVector3 m_totalForce;
|
||||
SimdVector3 m_totalTorque;
|
||||
btVector3 m_gravity;
|
||||
btVector3 m_invInertiaLocal;
|
||||
btVector3 m_totalForce;
|
||||
btVector3 m_totalTorque;
|
||||
|
||||
SimdScalar m_linearDamping;
|
||||
SimdScalar m_angularDamping;
|
||||
btScalar m_linearDamping;
|
||||
btScalar m_angularDamping;
|
||||
|
||||
SimdScalar m_kinematicTimeStep;
|
||||
btScalar m_kinematicTimeStep;
|
||||
|
||||
BroadphaseProxy* m_broadphaseProxy;
|
||||
btBroadphaseProxy* m_broadphaseProxy;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -1,123 +1,17 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
#include "btSimpleDynamicsWorld.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
|
||||
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:
|
||||
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld()
|
||||
:btDynamicsWorld(new CollisionDispatcher(),new SimpleBroadphase()),
|
||||
m_constraintSolver(new SequentialImpulseConstraintSolver)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld(Dispatcher* dispatcher,OverlappingPairCache* pairCache,ConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
btSimpleDynamicsWorld::~btSimpleDynamicsWorld()
|
||||
{
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete the dispatcher and paircache
|
||||
delete m_dispatcher1;
|
||||
m_dispatcher1 = 0;
|
||||
delete m_pairCache;
|
||||
m_pairCache = 0;
|
||||
}
|
||||
|
||||
void btSimpleDynamicsWorld::stepSimulation(float timeStep)
|
||||
{
|
||||
///apply gravity, predict motion
|
||||
predictUnconstraintMotion(timeStep);
|
||||
|
||||
///perform collision detection
|
||||
PerformDiscreteCollisionDetection();
|
||||
|
||||
///solve contact constraints
|
||||
PersistentManifold** manifoldPtr = ((CollisionDispatcher*)m_dispatcher1)->getInternalManifoldPointer();
|
||||
int numManifolds = m_dispatcher1->GetNumManifolds();
|
||||
ContactSolverInfo infoGlobal;
|
||||
infoGlobal.m_timeStep = timeStep;
|
||||
IDebugDraw* debugDrawer=0;
|
||||
m_constraintSolver->SolveGroup(manifoldPtr, numManifolds,infoGlobal,debugDrawer);
|
||||
|
||||
///integrate transforms
|
||||
integrateTransforms(timeStep);
|
||||
|
||||
updateAabbs();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btSimpleDynamicsWorld::updateAabbs()
|
||||
{
|
||||
SimdTransform predictedTrans;
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
SimdPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->GetAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
SimpleBroadphase* bp = (SimpleBroadphase*)m_pairCache;
|
||||
bp->SetAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btSimpleDynamicsWorld::integrateTransforms(float timeStep)
|
||||
{
|
||||
SimdTransform predictedTrans;
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||
body->proceedToTransform( predictedTrans);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btSimpleDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
{
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
CollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->m_internalOwner)
|
||||
{
|
||||
RigidBody* body = (RigidBody*)colObj->m_internalOwner;
|
||||
body->m_cachedInvertedWorldTransform = body->m_worldTransform.inverse();
|
||||
if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
body->integrateVelocities( timeStep);
|
||||
body->predictIntegratedTransform(timeStep,body->m_interpolationWorldTransform);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}=======
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "btSimpleDynamicsWorld.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
|
||||
@@ -18,61 +18,6 @@ subject to the following restrictions:
|
||||
|
||||
#include "btDynamicsWorld.h"
|
||||
|
||||
class Dispatcher;
|
||||
class OverlappingPairCache;
|
||||
class ConstraintSolver;
|
||||
|
||||
///btSimpleDynamicsWorld demonstrates very basic usage of Bullet rigid body dynamics
|
||||
///It can be used for basic simulations, and as a starting point for porting Bullet
|
||||
///btSimpleDynamicsWorld lacks object deactivation, island management and other concepts.
|
||||
///For more complicated simulations, btDiscreteDynamicsWorld and btContinuousDynamicsWorld are recommended
|
||||
///those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController
|
||||
class btSimpleDynamicsWorld : public btDynamicsWorld
|
||||
{
|
||||
protected:
|
||||
|
||||
ConstraintSolver* m_constraintSolver;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
|
||||
void updateAabbs();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
btSimpleDynamicsWorld(Dispatcher* dispatcher,OverlappingPairCache* pairCache,ConstraintSolver* constraintSolver);
|
||||
|
||||
btSimpleDynamicsWorld();
|
||||
|
||||
virtual ~btSimpleDynamicsWorld();
|
||||
|
||||
virtual void stepSimulation( float timeStep);
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_SIMPLE_DYNAMICS_WORLD_H=======
|
||||
/*
|
||||
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_SIMPLE_DYNAMICS_WORLD_H
|
||||
#define BT_SIMPLE_DYNAMICS_WORLD_H
|
||||
|
||||
#include "btDynamicsWorld.h"
|
||||
|
||||
class btDispatcher;
|
||||
class btOverlappingPairCache;
|
||||
class btConstraintSolver;
|
||||
|
||||
Reference in New Issue
Block a user