37c78168ba67a35d67696173c6fa6e322dc56b40
[blender.git] / extern / bullet / Extras / PhysicsInterface / CcdPhysics / CcdPhysicsEnvironment.h
1 #ifndef CCDPHYSICSENVIRONMENT
2 #define CCDPHYSICSENVIRONMENT
3
4 #include "PHY_IPhysicsEnvironment.h"
5 #include <vector>
6 class CcdPhysicsController;
7 #include "SimdVector3.h"
8
9
10
11 class Point2PointConstraint;
12 class CollisionDispatcher;
13 class Dispatcher;
14 //#include "BroadphaseInterface.h"
15
16 //switch on/off new vehicle support
17 //#define NEW_BULLET_VEHICLE_SUPPORT 1
18
19 #include "ConstraintSolver/ContactSolverInfo.h"
20
21 class WrapperVehicle;
22 class PersistentManifold;
23 class BroadphaseInterface;
24 class IDebugDraw;
25
26 /// Physics Environment takes care of stepping the simulation and is a container for physics entities.
27 /// It stores rigidbodies,constraints, materials etc.
28 /// A derived class may be able to 'construct' entities by loading and/or converting
29 class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
30 {
31         SimdVector3 m_gravity;
32         
33         IDebugDraw*     m_debugDrawer;
34         int     m_numIterations;
35         int     m_ccdMode;
36         int     m_solverType;
37         
38         ContactSolverInfo       m_solverInfo;
39
40         public:
41                 CcdPhysicsEnvironment(CollisionDispatcher* dispatcher=0, BroadphaseInterface* broadphase=0);
42
43                 virtual         ~CcdPhysicsEnvironment();
44
45                 /////////////////////////////////////
46                 //PHY_IPhysicsEnvironment interface
47                 /////////////////////////////////////
48
49                 /// Perform an integration step of duration 'timeStep'.
50
51                 virtual void setDebugDrawer(IDebugDraw* debugDrawer)
52                 {
53                         m_debugDrawer = debugDrawer;
54                 }
55
56                 virtual void            setNumIterations(int numIter);
57                 virtual void            setDeactivationTime(float dTime);
58                 virtual void            setDeactivationLinearTreshold(float linTresh) ;
59                 virtual void            setDeactivationAngularTreshold(float angTresh) ;
60                 virtual void            setContactBreakingTreshold(float contactBreakingTreshold) ;
61                 virtual void            setCcdMode(int ccdMode);
62                 virtual void            setSolverType(int solverType);
63                 virtual void            setSolverSorConstant(float sor);
64                 virtual void            setSolverTau(float tau);
65                 virtual void            setSolverDamping(float damping);
66                 virtual void            setLinearAirDamping(float damping);
67                 virtual void            setUseEpa(bool epa) ;
68
69                 virtual void            beginFrame();
70                 virtual void            endFrame() {};
71                 /// Perform an integration step of duration 'timeStep'.
72                 virtual bool            proceedDeltaTime(double curTime,float timeStep);
73                 bool                            proceedDeltaTimeOneStep(float timeStep);
74
75                 virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
76                 //returns 0.f if no fixed timestep is used
77
78                 virtual float           getFixedTimeStep(){ return 0.f;};
79
80                 virtual void            setDebugMode(int debugMode);
81
82                 virtual void            setGravity(float x,float y,float z);
83
84                 virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
85                         float pivotX,float pivotY,float pivotZ,
86                         float axisX,float axisY,float axisZ);
87             virtual void                removeConstraint(int    constraintid);
88
89 #ifdef NEW_BULLET_VEHICLE_SUPPORT
90                 //complex constraint for vehicles
91                 virtual PHY_IVehicle*   getVehicleConstraint(int constraintId);
92 #else
93                 virtual class PHY_IVehicle*     getVehicleConstraint(int constraintId)
94                 {
95                         return 0;
96                 }
97 #endif //NEW_BULLET_VEHICLE_SUPPORT
98
99                 Point2PointConstraint*  getPoint2PointConstraint(int constraintId);
100
101                 virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
102                                                                                 float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
103
104
105                 //Methods for gamelogic collision/physics callbacks
106                 //todo:
107                 virtual void addSensor(PHY_IPhysicsController* ctrl) {};
108                 virtual void removeSensor(PHY_IPhysicsController* ctrl){};
109                 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user){};
110                 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl){};
111                 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;};
112                 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight){ return 0;};
113         
114
115                 virtual int     getNumContactPoints();
116
117                 virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
118
119                 //////////////////////
120                 //CcdPhysicsEnvironment interface
121                 ////////////////////////
122         
123                 void    addCcdPhysicsController(CcdPhysicsController* ctrl);
124
125                 void    removeCcdPhysicsController(CcdPhysicsController* ctrl);
126
127                 BroadphaseInterface*    GetBroadphase();
128
129                 CollisionDispatcher* GetDispatcher();
130                 
131                 const CollisionDispatcher* GetDispatcher() const;
132
133
134                 int     GetNumControllers();
135
136                 CcdPhysicsController* GetPhysicsController( int index);
137
138                 int     GetNumManifolds() const;
139
140                 const PersistentManifold*       GetManifold(int index) const;
141
142         private:
143                 
144                 
145                 void    SyncMotionStates(float timeStep);
146                 
147                 std::vector<CcdPhysicsController*> m_controllers;
148
149                 std::vector<Point2PointConstraint*> m_p2pConstraints;
150
151                 std::vector<WrapperVehicle*>    m_wrapperVehicles;
152
153                 class CollisionWorld*   m_collisionWorld;
154                 
155                 class ConstraintSolver* m_solver;
156
157                 bool    m_scalingPropagated;
158
159
160 };
161
162 #endif //CCDPHYSICSENVIRONMENT