2006-04-28 00:08:18 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
#ifndef CCDPHYSICSENVIRONMENT
|
|
|
|
#define CCDPHYSICSENVIRONMENT
|
|
|
|
|
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
|
|
|
#include <vector>
|
2008-07-30 17:41:47 +00:00
|
|
|
#include <set>
|
2005-07-16 10:15:31 +00:00
|
|
|
class CcdPhysicsController;
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "LinearMath/btVector3.h"
|
|
|
|
#include "LinearMath/btTransform.h"
|
2005-07-16 10:15:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
class btTypedConstraint;
|
|
|
|
class btSimulationIslandManager;
|
|
|
|
class btCollisionDispatcher;
|
|
|
|
class btDispatcher;
|
|
|
|
//#include "btBroadphaseInterface.h"
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
//switch on/off new vehicle support
|
2006-02-21 06:08:18 +00:00
|
|
|
#define NEW_BULLET_VEHICLE_SUPPORT 1
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
class WrapperVehicle;
|
2006-11-21 00:53:40 +00:00
|
|
|
class btPersistentManifold;
|
|
|
|
class btBroadphaseInterface;
|
|
|
|
class btOverlappingPairCache;
|
|
|
|
class btIDebugDraw;
|
|
|
|
class PHY_IVehicle;
|
2008-03-01 19:17:37 +00:00
|
|
|
class CcdOverlapFilterCallBack;
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
/// CcdPhysicsEnvironment is an experimental mainloop for physics simulation using optional continuous collision detection.
|
2005-07-16 10:15:31 +00:00
|
|
|
/// Physics Environment takes care of stepping the simulation and is a container for physics entities.
|
|
|
|
/// It stores rigidbodies,constraints, materials etc.
|
|
|
|
/// A derived class may be able to 'construct' entities by loading and/or converting
|
|
|
|
class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
|
|
|
{
|
2008-03-02 09:39:14 +00:00
|
|
|
friend class CcdOverlapFilterCallBack;
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 m_gravity;
|
2006-08-28 06:44:29 +00:00
|
|
|
|
|
|
|
protected:
|
2006-11-21 00:53:40 +00:00
|
|
|
btIDebugDraw* m_debugDrawer;
|
2008-09-03 02:27:16 +00:00
|
|
|
|
|
|
|
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
|
|
|
class btBroadphaseInterface* m_broadphase;
|
|
|
|
|
2006-05-22 21:03:43 +00:00
|
|
|
//solver iterations
|
2005-08-03 18:22:30 +00:00
|
|
|
int m_numIterations;
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
//timestep subdivisions
|
|
|
|
int m_numTimeSubSteps;
|
2006-08-28 06:44:29 +00:00
|
|
|
|
|
|
|
|
2005-08-03 18:22:30 +00:00
|
|
|
int m_ccdMode;
|
2005-08-04 19:07:39 +00:00
|
|
|
int m_solverType;
|
2006-04-13 05:11:34 +00:00
|
|
|
int m_profileTimings;
|
|
|
|
bool m_enableSatCollisionDetection;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btContactSolverInfo m_solverInfo;
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2008-09-29 06:58:49 +00:00
|
|
|
void processFhSprings(double curTime,float timeStep);
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
public:
|
2006-11-21 00:53:40 +00:00
|
|
|
CcdPhysicsEnvironment(btDispatcher* dispatcher=0, btOverlappingPairCache* pairCache=0);
|
2005-07-16 10:15:31 +00:00
|
|
|
|
|
|
|
virtual ~CcdPhysicsEnvironment();
|
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
|
//PHY_IPhysicsEnvironment interface
|
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
|
|
/// Perform an integration step of duration 'timeStep'.
|
|
|
|
|
2006-11-21 12:26:05 +00:00
|
|
|
virtual void setDebugDrawer(btIDebugDraw* debugDrawer);
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2005-08-03 18:22:30 +00:00
|
|
|
virtual void setNumIterations(int numIter);
|
2006-05-22 21:03:43 +00:00
|
|
|
virtual void setNumTimeSubSteps(int numTimeSubSteps)
|
|
|
|
{
|
|
|
|
m_numTimeSubSteps = numTimeSubSteps;
|
|
|
|
}
|
2005-08-03 18:22:30 +00:00
|
|
|
virtual void setDeactivationTime(float dTime);
|
|
|
|
virtual void setDeactivationLinearTreshold(float linTresh) ;
|
|
|
|
virtual void setDeactivationAngularTreshold(float angTresh) ;
|
|
|
|
virtual void setContactBreakingTreshold(float contactBreakingTreshold) ;
|
|
|
|
virtual void setCcdMode(int ccdMode);
|
2005-08-04 19:07:39 +00:00
|
|
|
virtual void setSolverType(int solverType);
|
2005-08-03 18:22:30 +00:00
|
|
|
virtual void setSolverSorConstant(float sor);
|
2005-08-04 19:07:39 +00:00
|
|
|
virtual void setSolverTau(float tau);
|
|
|
|
virtual void setSolverDamping(float damping);
|
|
|
|
virtual void setLinearAirDamping(float damping);
|
|
|
|
virtual void setUseEpa(bool epa) ;
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-01-01 00:20:50 +00:00
|
|
|
virtual void beginFrame();
|
2005-07-16 10:15:31 +00:00
|
|
|
virtual void endFrame() {};
|
|
|
|
/// Perform an integration step of duration 'timeStep'.
|
|
|
|
virtual bool proceedDeltaTime(double curTime,float timeStep);
|
2006-11-21 00:53:40 +00:00
|
|
|
// virtual bool proceedDeltaTimeOneStep(float timeStep);
|
2006-01-15 11:34:55 +00:00
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
|
|
|
|
//returns 0.f if no fixed timestep is used
|
2005-07-29 18:14:41 +00:00
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
virtual float getFixedTimeStep(){ return 0.f;};
|
|
|
|
|
2005-07-29 18:14:41 +00:00
|
|
|
virtual void setDebugMode(int debugMode);
|
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
virtual void setGravity(float x,float y,float z);
|
2008-09-21 15:17:50 +00:00
|
|
|
virtual void getGravity(PHY__Vector3& grav);
|
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
|
|
|
|
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
|
|
|
|
float pivotX,float pivotY,float pivotZ,
|
2006-12-16 05:50:38 +00:00
|
|
|
float axisX,float axisY,float axisZ,
|
|
|
|
float axis1X=0,float axis1Y=0,float axis1Z=0,
|
2008-10-10 05:12:57 +00:00
|
|
|
float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0
|
2006-12-16 05:50:38 +00:00
|
|
|
);
|
2006-08-28 06:44:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Following the COLLADA physics specification for constraints
|
|
|
|
virtual int createUniversalD6Constraint(
|
|
|
|
class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
|
2006-11-21 00:53:40 +00:00
|
|
|
btTransform& localAttachmentFrameRef,
|
|
|
|
btTransform& localAttachmentOther,
|
|
|
|
const btVector3& linearMinLimits,
|
|
|
|
const btVector3& linearMaxLimits,
|
|
|
|
const btVector3& angularMinLimits,
|
2008-10-10 05:12:57 +00:00
|
|
|
const btVector3& angularMaxLimits,int flags
|
2006-08-28 06:44:29 +00:00
|
|
|
);
|
|
|
|
|
2006-12-02 03:48:36 +00:00
|
|
|
virtual void setConstraintParam(int constraintId,int param,float value,float value1);
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2006-01-15 11:34:55 +00:00
|
|
|
virtual void removeConstraint(int constraintid);
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
virtual float getAppliedImpulse(int constraintid);
|
2006-04-17 01:33:10 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
virtual void CallbackTriggers();
|
|
|
|
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
2006-01-30 20:33:59 +00:00
|
|
|
//complex constraint for vehicles
|
2006-02-13 06:28:35 +00:00
|
|
|
virtual PHY_IVehicle* getVehicleConstraint(int constraintId);
|
|
|
|
#else
|
2006-04-06 20:37:38 +00:00
|
|
|
virtual class PHY_IVehicle* getVehicleConstraint(int constraintId)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-13 06:28:35 +00:00
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btTypedConstraint* getConstraintById(int constraintId);
|
2006-04-06 20:37:38 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
|
2005-07-16 10:15:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Methods for gamelogic collision/physics callbacks
|
2006-04-17 01:33:10 +00:00
|
|
|
virtual void addSensor(PHY_IPhysicsController* ctrl);
|
|
|
|
virtual void removeSensor(PHY_IPhysicsController* ctrl);
|
|
|
|
virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
|
|
|
|
virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl);
|
2006-05-22 21:03:43 +00:00
|
|
|
virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl);
|
2008-03-01 19:17:37 +00:00
|
|
|
//These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
|
2006-05-22 21:03:43 +00:00
|
|
|
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
|
|
|
|
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
|
2005-07-16 10:15:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
virtual int getNumContactPoints();
|
|
|
|
|
|
|
|
virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
//CcdPhysicsEnvironment interface
|
|
|
|
////////////////////////
|
|
|
|
|
|
|
|
void addCcdPhysicsController(CcdPhysicsController* ctrl);
|
|
|
|
|
|
|
|
void removeCcdPhysicsController(CcdPhysicsController* ctrl);
|
|
|
|
|
2008-07-20 15:40:03 +00:00
|
|
|
void updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask);
|
|
|
|
|
2008-08-05 16:23:33 +00:00
|
|
|
void disableCcdPhysicsController(CcdPhysicsController* ctrl);
|
2008-07-20 15:40:03 +00:00
|
|
|
|
|
|
|
void enableCcdPhysicsController(CcdPhysicsController* ctrl);
|
2008-07-19 10:27:52 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btBroadphaseInterface* getBroadphase();
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2008-09-21 15:17:50 +00:00
|
|
|
btDispatcher* getDispatcher();
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
bool IsSatCollisionDetectionEnabled() const
|
|
|
|
{
|
|
|
|
return m_enableSatCollisionDetection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableSatCollisionDetection(bool enableSat)
|
|
|
|
{
|
|
|
|
m_enableSatCollisionDetection = enableSat;
|
|
|
|
}
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
|
|
|
const btPersistentManifold* GetManifold(int index) const;
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
void SyncMotionStates(float timeStep);
|
|
|
|
|
2008-09-24 03:12:10 +00:00
|
|
|
class btSoftRigidDynamicsWorld* getDynamicsWorld()
|
|
|
|
{
|
|
|
|
return m_dynamicsWorld;
|
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
|
|
|
|
class btConstraintSolver* GetConstraintSolver();
|
2006-08-28 06:44:29 +00:00
|
|
|
|
|
|
|
protected:
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
|
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
std::set<CcdPhysicsController*> m_controllers;
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
std::set<CcdPhysicsController*> m_triggerControllers;
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
PHY_ResponseCallback m_triggerCallbacks[PHY_NUM_RESPONSE];
|
|
|
|
void* m_triggerCallbacksUserPtrs[PHY_NUM_RESPONSE];
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
std::vector<WrapperVehicle*> m_wrapperVehicles;
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
//use explicit btSoftRigidDynamicsWorld/btDiscreteDynamicsWorld* so that we have access to
|
2008-03-01 19:17:37 +00:00
|
|
|
//btDiscreteDynamicsWorld::addRigidBody(body,filter,group)
|
|
|
|
//so that we can set the body collision filter/group at the time of creation
|
|
|
|
//and not afterwards (breaks the collision system for radar/near sensor)
|
|
|
|
//Ideally we would like to have access to this function from the btDynamicsWorld interface
|
|
|
|
//class btDynamicsWorld* m_dynamicsWorld;
|
2008-09-17 01:49:47 +00:00
|
|
|
class btSoftRigidDynamicsWorld* m_dynamicsWorld;
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
class btConstraintSolver* m_solver;
|
2005-07-16 10:15:31 +00:00
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
class btOverlappingPairCache* m_ownPairCache;
|
|
|
|
|
|
|
|
class CcdOverlapFilterCallBack* m_filterCallback;
|
|
|
|
|
|
|
|
class btDispatcher* m_ownDispatcher;
|
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
bool m_scalingPropagated;
|
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2005-07-29 18:14:41 +00:00
|
|
|
|
2005-07-16 10:15:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //CCDPHYSICSENVIRONMENT
|