329239db667f6a9b33a91ddde002e3b0822374c9
[blender-staging.git] / source / gameengine / Physics / Bullet / 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 ToiContactDispatcher;
13 class Dispatcher;
14 //#include "BroadphaseInterface.h"
15
16 class Vehicle;
17 class PersistentManifold;
18 class BroadphaseInterface;
19 class IDebugDraw;
20
21 /// Physics Environment takes care of stepping the simulation and is a container for physics entities.
22 /// It stores rigidbodies,constraints, materials etc.
23 /// A derived class may be able to 'construct' entities by loading and/or converting
24 class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
25 {
26         SimdVector3 m_gravity;
27         BroadphaseInterface*    m_broadphase;
28         IDebugDraw*     m_debugDrawer;
29         int     m_numIterations;
30         int     m_ccdMode;
31         int     m_solverType;
32         
33         public:
34                 CcdPhysicsEnvironment(ToiContactDispatcher* dispatcher=0, BroadphaseInterface* broadphase=0);
35
36                 virtual         ~CcdPhysicsEnvironment();
37
38                 /////////////////////////////////////
39                 //PHY_IPhysicsEnvironment interface
40                 /////////////////////////////////////
41
42                 /// Perform an integration step of duration 'timeStep'.
43
44                 virtual void setDebugDrawer(IDebugDraw* debugDrawer)
45                 {
46                         m_debugDrawer = debugDrawer;
47                 }
48
49                 virtual void            setNumIterations(int numIter);
50                 virtual void            setDeactivationTime(float dTime);
51                 virtual void            setDeactivationLinearTreshold(float linTresh) ;
52                 virtual void            setDeactivationAngularTreshold(float angTresh) ;
53                 virtual void            setContactBreakingTreshold(float contactBreakingTreshold) ;
54                 virtual void            setCcdMode(int ccdMode);
55                 virtual void            setSolverType(int solverType);
56                 virtual void            setSolverSorConstant(float sor);
57                 virtual void            setSolverTau(float tau);
58                 virtual void            setSolverDamping(float damping);
59                 virtual void            setLinearAirDamping(float damping);
60                 virtual void            setUseEpa(bool epa) ;
61
62                 virtual void            beginFrame();
63                 virtual void            endFrame() {};
64                 /// Perform an integration step of duration 'timeStep'.
65                 virtual bool            proceedDeltaTime(double curTime,float timeStep);
66                 virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
67                 //returns 0.f if no fixed timestep is used
68
69                 virtual float           getFixedTimeStep(){ return 0.f;};
70
71                 virtual void            setDebugMode(int debugMode);
72
73                 virtual void            setGravity(float x,float y,float z);
74
75                 virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
76                         float pivotX,float pivotY,float pivotZ,
77                         float axisX,float axisY,float axisZ);
78                 virtual void            removeConstraint(int constraintid);
79
80
81                 virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
82                                                                                 float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
83
84
85                 //Methods for gamelogic collision/physics callbacks
86                 //todo:
87                 virtual void addSensor(PHY_IPhysicsController* ctrl) {};
88                 virtual void removeSensor(PHY_IPhysicsController* ctrl){};
89                 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user){};
90                 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl){};
91                 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;};
92                 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight){ return 0;};
93         
94
95                 virtual int     getNumContactPoints();
96
97                 virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
98
99                 //////////////////////
100                 //CcdPhysicsEnvironment interface
101                 ////////////////////////
102         
103                 void    addCcdPhysicsController(CcdPhysicsController* ctrl);
104
105                 void    removeCcdPhysicsController(CcdPhysicsController* ctrl);
106
107                 BroadphaseInterface*    GetBroadphase() { return m_broadphase; }
108
109                 Dispatcher* GetDispatcher();
110
111                 int     GetNumControllers();
112
113                 CcdPhysicsController* GetPhysicsController( int index);
114
115                 int     GetNumManifolds() const;
116
117                 const PersistentManifold*       GetManifold(int index) const;
118
119         private:
120                 
121                 void    UpdateActivationState();        
122                 void    SyncMotionStates(float timeStep);
123                 
124                 std::vector<CcdPhysicsController*> m_controllers;
125
126                 std::vector<Point2PointConstraint*> m_p2pConstraints;
127
128                 std::vector<Vehicle*>   m_vehicles;
129
130                 class ToiContactDispatcher* m_dispatcher;
131
132                 bool    m_scalingPropagated;
133
134
135 };
136
137 #endif //CCDPHYSICSENVIRONMENT