updated testbed demo
[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
54                 virtual float           getFixedTimeStep(){ return 0.f;};
55
56                 virtual void            setDebugMode(int debugMode);
57
58                 virtual void            setGravity(float x,float y,float z);
59
60                 virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
61                         float pivotX,float pivotY,float pivotZ,
62                         float axisX,float axisY,float axisZ);
63                 virtual void            removeConstraint(int constraintid);
64
65
66                 virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
67                                                                                 float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
68
69
70                 //Methods for gamelogic collision/physics callbacks
71                 //todo:
72                 virtual void addSensor(PHY_IPhysicsController* ctrl) {};
73                 virtual void removeSensor(PHY_IPhysicsController* ctrl){};
74                 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user){};
75                 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl){};
76                 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;};
77                 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight){ return 0;};
78         
79
80                 virtual int     getNumContactPoints();
81
82                 virtual void getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
83
84                 //////////////////////
85                 //CcdPhysicsEnvironment interface
86                 ////////////////////////
87         
88                 void    addCcdPhysicsController(CcdPhysicsController* ctrl);
89
90                 void    removeCcdPhysicsController(CcdPhysicsController* ctrl);
91
92                 BroadphaseInterface*    GetBroadphase() { return m_broadphase; }
93
94                 Dispatcher* GetDispatcher();
95
96                 int     GetNumControllers();
97
98                 CcdPhysicsController* GetPhysicsController( int index);
99
100                 int     GetNumManifolds() const;
101
102                 const PersistentManifold*       GetManifold(int index) const;
103
104         private:
105                 
106                 void    UpdateActivationState();        
107                 void    SyncMotionStates(float timeStep);
108                 
109                 std::vector<CcdPhysicsController*> m_controllers;
110
111                 std::vector<Point2PointConstraint*> m_p2pConstraints;
112
113                 std::vector<Vehicle*>   m_vehicles;
114
115                 class ToiContactDispatcher* m_dispatcher;
116
117                 bool    m_scalingPropagated;
118
119
120 };
121
122 #endif //CCDPHYSICSENVIRONMENT