fc3786885b79958f3eb4a54a9228a4e36ccc3900
[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 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         
30         public:
31                 CcdPhysicsEnvironment(ToiContactDispatcher* dispatcher=0, BroadphaseInterface* broadphase=0);
32
33                 virtual         ~CcdPhysicsEnvironment();
34
35                 /////////////////////////////////////
36                 //PHY_IPhysicsEnvironment interface
37                 /////////////////////////////////////
38
39                 /// Perform an integration step of duration 'timeStep'.
40
41                 virtual void setDebugDrawer(IDebugDraw* debugDrawer)
42                 {
43                         m_debugDrawer = debugDrawer;
44                 }
45
46
47                 virtual void            beginFrame() {};
48                 virtual void            endFrame() {};
49                 /// Perform an integration step of duration 'timeStep'.
50                 virtual bool            proceedDeltaTime(double curTime,float timeStep);
51                 virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
52                 //returns 0.f if no fixed timestep is used
53                 virtual float           getFixedTimeStep(){ return 0.f;};
54
55                 virtual void            setGravity(float x,float y,float z);
56
57                 virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
58                         float pivotX,float pivotY,float pivotZ,
59                         float axisX,float axisY,float axisZ);
60                 virtual void            removeConstraint(int constraintid);
61
62
63                 virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
64                                                                                 float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
65
66
67                 //Methods for gamelogic collision/physics callbacks
68                 //todo:
69                 virtual void addSensor(PHY_IPhysicsController* ctrl) {};
70                 virtual void removeSensor(PHY_IPhysicsController* ctrl){};
71                 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user){};
72                 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl){};
73                 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;};
74                 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight){ return 0;};
75         
76
77                 virtual int     getNumContactPoints();
78
79                 virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
80
81                 //////////////////////
82                 //CcdPhysicsEnvironment interface
83                 ////////////////////////
84         
85                 void    addCcdPhysicsController(CcdPhysicsController* ctrl);
86
87                 void    removeCcdPhysicsController(CcdPhysicsController* ctrl);
88
89                 BroadphaseInterface*    GetBroadphase() { return m_broadphase; }
90
91                 Dispatcher* GetDispatcher();
92
93                 int     GetNumControllers();
94
95                 CcdPhysicsController* GetPhysicsController( int index);
96
97                 int     GetNumManifolds() const;
98
99                 const PersistentManifold*       GetManifold(int index) const;
100
101         private:
102                 
103                 void    UpdateActivationState();        
104                 void    SyncMotionStates(float timeStep);
105                 
106                 std::vector<CcdPhysicsController*> m_controllers;
107
108                 std::vector<Point2PointConstraint*> m_p2pConstraints;
109
110                 std::vector<Vehicle*>   m_vehicles;
111
112                 class ToiContactDispatcher* m_dispatcher;
113
114                 bool    m_scalingPropagated;
115
116 };
117
118 #endif //CCDPHYSICSENVIRONMENT