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