2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #ifndef CCDPHYSICSENVIRONMENT
17 #define CCDPHYSICSENVIRONMENT
19 #include "PHY_IPhysicsEnvironment.h"
22 class CcdPhysicsController;
23 #include "LinearMath/btVector3.h"
24 #include "LinearMath/btTransform.h"
29 class btTypedConstraint;
30 class btSimulationIslandManager;
31 class btCollisionDispatcher;
33 //#include "btBroadphaseInterface.h"
35 //switch on/off new vehicle support
36 #define NEW_BULLET_VEHICLE_SUPPORT 1
38 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
41 class btPersistentManifold;
42 class btBroadphaseInterface;
43 class btOverlappingPairCache;
46 class CcdOverlapFilterCallBack;
48 /// CcdPhysicsEnvironment is an experimental mainloop for physics simulation using optional continuous collision detection.
49 /// Physics Environment takes care of stepping the simulation and is a container for physics entities.
50 /// It stores rigidbodies,constraints, materials etc.
51 /// A derived class may be able to 'construct' entities by loading and/or converting
52 class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
54 friend class CcdOverlapFilterCallBack;
58 btIDebugDraw* m_debugDrawer;
60 class btDefaultCollisionConfiguration* m_collisionConfiguration;
61 class btBroadphaseInterface* m_broadphase;
66 //timestep subdivisions
67 int m_numTimeSubSteps;
73 bool m_enableSatCollisionDetection;
75 btContactSolverInfo m_solverInfo;
77 void processFhSprings(double curTime,float timeStep);
80 CcdPhysicsEnvironment(btDispatcher* dispatcher=0, btOverlappingPairCache* pairCache=0);
82 virtual ~CcdPhysicsEnvironment();
84 /////////////////////////////////////
85 //PHY_IPhysicsEnvironment interface
86 /////////////////////////////////////
88 /// Perform an integration step of duration 'timeStep'.
90 virtual void setDebugDrawer(btIDebugDraw* debugDrawer);
92 virtual void setNumIterations(int numIter);
93 virtual void setNumTimeSubSteps(int numTimeSubSteps)
95 m_numTimeSubSteps = numTimeSubSteps;
97 virtual void setDeactivationTime(float dTime);
98 virtual void setDeactivationLinearTreshold(float linTresh) ;
99 virtual void setDeactivationAngularTreshold(float angTresh) ;
100 virtual void setContactBreakingTreshold(float contactBreakingTreshold) ;
101 virtual void setCcdMode(int ccdMode);
102 virtual void setSolverType(int solverType);
103 virtual void setSolverSorConstant(float sor);
104 virtual void setSolverTau(float tau);
105 virtual void setSolverDamping(float damping);
106 virtual void setLinearAirDamping(float damping);
107 virtual void setUseEpa(bool epa) ;
109 virtual void beginFrame();
110 virtual void endFrame() {};
111 /// Perform an integration step of duration 'timeStep'.
112 virtual bool proceedDeltaTime(double curTime,float timeStep);
114 virtual void debugDrawWorld();
115 // virtual bool proceedDeltaTimeOneStep(float timeStep);
117 virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
118 //returns 0.f if no fixed timestep is used
120 virtual float getFixedTimeStep(){ return 0.f;};
122 virtual void setDebugMode(int debugMode);
124 virtual void setGravity(float x,float y,float z);
125 virtual void getGravity(PHY__Vector3& grav);
128 virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
129 float pivotX,float pivotY,float pivotZ,
130 float axisX,float axisY,float axisZ,
131 float axis1X=0,float axis1Y=0,float axis1Z=0,
132 float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0
136 //Following the COLLADA physics specification for constraints
137 virtual int createUniversalD6Constraint(
138 class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
139 btTransform& localAttachmentFrameRef,
140 btTransform& localAttachmentOther,
141 const btVector3& linearMinLimits,
142 const btVector3& linearMaxLimits,
143 const btVector3& angularMinLimits,
144 const btVector3& angularMaxLimits,int flags
147 virtual void setConstraintParam(int constraintId,int param,float value,float value1);
149 virtual void removeConstraint(int constraintid);
151 virtual float getAppliedImpulse(int constraintid);
154 virtual void CallbackTriggers();
157 #ifdef NEW_BULLET_VEHICLE_SUPPORT
158 //complex constraint for vehicles
159 virtual PHY_IVehicle* getVehicleConstraint(int constraintId);
161 virtual class PHY_IVehicle* getVehicleConstraint(int constraintId)
165 #endif //NEW_BULLET_VEHICLE_SUPPORT
167 btTypedConstraint* getConstraintById(int constraintId);
169 virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
172 //Methods for gamelogic collision/physics callbacks
173 virtual void addSensor(PHY_IPhysicsController* ctrl);
174 virtual void removeSensor(PHY_IPhysicsController* ctrl);
175 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
176 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl);
177 virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl);
178 //These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
179 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
180 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
183 virtual int getNumContactPoints();
185 virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
187 //////////////////////
188 //CcdPhysicsEnvironment interface
189 ////////////////////////
191 void addCcdPhysicsController(CcdPhysicsController* ctrl);
193 void removeCcdPhysicsController(CcdPhysicsController* ctrl);
195 void updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask);
197 void disableCcdPhysicsController(CcdPhysicsController* ctrl);
199 void enableCcdPhysicsController(CcdPhysicsController* ctrl);
201 void refreshCcdPhysicsController(CcdPhysicsController* ctrl);
203 btBroadphaseInterface* getBroadphase();
205 btDispatcher* getDispatcher();
208 bool IsSatCollisionDetectionEnabled() const
210 return m_enableSatCollisionDetection;
213 void EnableSatCollisionDetection(bool enableSat)
215 m_enableSatCollisionDetection = enableSat;
219 const btPersistentManifold* GetManifold(int index) const;
222 void SyncMotionStates(float timeStep);
224 class btSoftRigidDynamicsWorld* getDynamicsWorld()
226 return m_dynamicsWorld;
229 class btConstraintSolver* GetConstraintSolver();
236 std::set<CcdPhysicsController*> m_controllers;
238 std::set<CcdPhysicsController*> m_triggerControllers;
240 PHY_ResponseCallback m_triggerCallbacks[PHY_NUM_RESPONSE];
241 void* m_triggerCallbacksUserPtrs[PHY_NUM_RESPONSE];
243 std::vector<WrapperVehicle*> m_wrapperVehicles;
245 //use explicit btSoftRigidDynamicsWorld/btDiscreteDynamicsWorld* so that we have access to
246 //btDiscreteDynamicsWorld::addRigidBody(body,filter,group)
247 //so that we can set the body collision filter/group at the time of creation
248 //and not afterwards (breaks the collision system for radar/near sensor)
249 //Ideally we would like to have access to this function from the btDynamicsWorld interface
250 //class btDynamicsWorld* m_dynamicsWorld;
251 class btSoftRigidDynamicsWorld* m_dynamicsWorld;
253 class btConstraintSolver* m_solver;
255 class btOverlappingPairCache* m_ownPairCache;
257 class CcdOverlapFilterCallBack* m_filterCallback;
259 class btDispatcher* m_ownDispatcher;
261 bool m_scalingPropagated;
267 #endif //CCDPHYSICSENVIRONMENT