mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-18 21:10:05 +00:00
added vehicle simulation
This commit is contained in:
parent
2a602aefa1
commit
a54f928b60
@ -1,14 +1,23 @@
|
||||
|
||||
#include "btDiscreteDynamicsWorld.h"
|
||||
|
||||
//collision detection
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
|
||||
|
||||
//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()
|
||||
@ -41,6 +50,9 @@ btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld()
|
||||
|
||||
void btDiscreteDynamicsWorld::stepSimulation(float timeStep)
|
||||
{
|
||||
///update aabbs information
|
||||
updateAabbs();
|
||||
|
||||
///apply gravity, predict motion
|
||||
predictUnconstraintMotion(timeStep);
|
||||
|
||||
@ -55,19 +67,32 @@ void btDiscreteDynamicsWorld::stepSimulation(float timeStep)
|
||||
///solve non-contact constraints
|
||||
solveNoncontactConstraints(infoGlobal);
|
||||
|
||||
///solve contact constraints
|
||||
solveContactConstraints(infoGlobal);
|
||||
|
||||
//CallbackTriggers();
|
||||
///update vehicle simulation
|
||||
updateVehicles(timeStep);
|
||||
|
||||
///CallbackTriggers();
|
||||
|
||||
///integrate transforms
|
||||
integrateTransforms(timeStep);
|
||||
|
||||
updateActivationState( timeStep );
|
||||
|
||||
updateAabbs();
|
||||
|
||||
|
||||
}
|
||||
|
||||
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++)
|
||||
@ -106,6 +131,21 @@ void btDiscreteDynamicsWorld::removeConstraint(TypedConstraint* constraint)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
|
@ -24,6 +24,7 @@ class ConstraintSolver;
|
||||
class SimulationIslandManager;
|
||||
class TypedConstraint;
|
||||
struct ContactSolverInfo;
|
||||
class RaycastVehicle;
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -39,6 +40,8 @@ protected:
|
||||
|
||||
std::vector<TypedConstraint*> m_constraints;
|
||||
|
||||
std::vector<RaycastVehicle*> m_vehicles;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
@ -53,6 +56,7 @@ protected:
|
||||
|
||||
void updateActivationState(float timeStep);
|
||||
|
||||
void updateVehicles(float timeStep);
|
||||
|
||||
public:
|
||||
|
||||
@ -69,6 +73,10 @@ public:
|
||||
|
||||
void removeConstraint(TypedConstraint* constraint);
|
||||
|
||||
void addVehicle(RaycastVehicle* vehicle);
|
||||
|
||||
void removeVehicle(RaycastVehicle* vehicle);
|
||||
|
||||
SimulationIslandManager* GetSimulationIslandManager()
|
||||
{
|
||||
return m_islandManager;
|
||||
|
Loading…
Reference in New Issue
Block a user