blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h

202 lines
6.4 KiB
C
Raw Normal View History

/*
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>
class CcdPhysicsController;
#include "SimdVector3.h"
class TypedConstraint;
class CollisionDispatcher;
2005-07-16 10:15:31 +00:00
class Dispatcher;
//#include "BroadphaseInterface.h"
//switch on/off new vehicle support
#define NEW_BULLET_VEHICLE_SUPPORT 1
#include "ConstraintSolver/ContactSolverInfo.h"
class WrapperVehicle;
2005-07-16 10:15:31 +00:00
class PersistentManifold;
class BroadphaseInterface;
class IDebugDraw;
2005-07-16 10:15:31 +00:00
/// CcdPhysicsEnvironment is 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
{
SimdVector3 m_gravity;
IDebugDraw* m_debugDrawer;
int m_numIterations;
int m_ccdMode;
int m_solverType;
int m_profileTimings;
bool m_enableSatCollisionDetection;
ContactSolverInfo m_solverInfo;
2005-07-16 10:15:31 +00:00
public:
CcdPhysicsEnvironment(CollisionDispatcher* dispatcher=0, BroadphaseInterface* broadphase=0);
2005-07-16 10:15:31 +00:00
virtual ~CcdPhysicsEnvironment();
/////////////////////////////////////
//PHY_IPhysicsEnvironment interface
/////////////////////////////////////
/// Perform an integration step of duration 'timeStep'.
virtual void setDebugDrawer(IDebugDraw* debugDrawer)
2005-07-16 10:15:31 +00:00
{
m_debugDrawer = debugDrawer;
}
virtual void setNumIterations(int numIter);
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);
virtual void setSolverType(int solverType);
virtual void setSolverSorConstant(float sor);
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
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);
bool proceedDeltaTimeOneStep(float timeStep);
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-16 10:15:31 +00:00
virtual float getFixedTimeStep(){ return 0.f;};
virtual void setDebugMode(int debugMode);
2005-07-16 10:15:31 +00:00
virtual void setGravity(float x,float y,float z);
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
float pivotX,float pivotY,float pivotZ,
float axisX,float axisY,float axisZ);
virtual void removeConstraint(int constraintid);
2005-07-16 10:15:31 +00:00
virtual void CallbackTriggers();
#ifdef NEW_BULLET_VEHICLE_SUPPORT
//complex constraint for vehicles
virtual PHY_IVehicle* getVehicleConstraint(int constraintId);
#else
virtual class PHY_IVehicle* getVehicleConstraint(int constraintId)
{
return 0;
}
#endif //NEW_BULLET_VEHICLE_SUPPORT
2005-07-16 10:15:31 +00:00
TypedConstraint* getConstraintById(int constraintId);
2005-07-16 10:15:31 +00:00
virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ,
float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
//Methods for gamelogic collision/physics callbacks
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);
2005-07-16 10:15:31 +00:00
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;};
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight){ return 0;};
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);
BroadphaseInterface* GetBroadphase();
CollisionDispatcher* GetDispatcher();
const CollisionDispatcher* GetDispatcher() const;
2005-07-16 10:15:31 +00:00
bool IsSatCollisionDetectionEnabled() const
{
return m_enableSatCollisionDetection;
}
void EnableSatCollisionDetection(bool enableSat)
{
m_enableSatCollisionDetection = enableSat;
}
2005-07-16 10:15:31 +00:00
void UpdateAabbs(float timeStep);
2005-07-16 10:15:31 +00:00
int GetNumControllers();
CcdPhysicsController* GetPhysicsController( int index);
int GetNumManifolds() const;
const PersistentManifold* GetManifold(int index) const;
std::vector<TypedConstraint*> m_constraints;
2005-07-16 10:15:31 +00:00
private:
2005-07-16 10:15:31 +00:00
void SyncMotionStates(float timeStep);
std::vector<CcdPhysicsController*> m_controllers;
std::vector<CcdPhysicsController*> m_triggerControllers;
2005-07-16 10:15:31 +00:00
PHY_ResponseCallback m_triggerCallbacks[PHY_NUM_RESPONSE];
void* m_triggerCallbacksUserPtrs[PHY_NUM_RESPONSE];
std::vector<WrapperVehicle*> m_wrapperVehicles;
2005-07-16 10:15:31 +00:00
class CollisionWorld* m_collisionWorld;
class ConstraintSolver* m_solver;
2005-07-16 10:15:31 +00:00
bool m_scalingPropagated;
2005-07-16 10:15:31 +00:00
};
#endif //CCDPHYSICSENVIRONMENT