Fixed several bugs: python refcounting related and Bullet related (basic add/remove...
[blender.git] / source / gameengine / Physics / Bullet / CcdPhysicsController.h
1
2 #ifndef BULLET2_PHYSICSCONTROLLER_H
3 #define BULLET2_PHYSICSCONTROLLER_H
4
5 #include "PHY_IPhysicsController.h"
6
7 ///     PHY_IPhysicsController is the abstract simplified Interface to a physical object.
8 ///     It contains the IMotionState and IDeformableMesh Interfaces.
9 #include "SimdVector3.h"
10 #include "SimdScalar.h" 
11 #include "SimdMatrix3x3.h"
12
13 class CollisionShape;
14
15 extern float gDeactivationTime;
16 extern float gLinearSleepingTreshold;
17 extern float gAngularSleepingTreshold;
18 extern bool gDisableDeactivation;
19 class CcdPhysicsEnvironment;
20
21
22 struct CcdConstructionInfo
23 {
24         CcdConstructionInfo()
25                 : m_gravity(0,0,0),
26                 m_mass(0.f),
27                 m_restitution(0.1f),
28                 m_linearDamping(0.1f),
29                 m_angularDamping(0.1f),
30                 m_MotionState(0),
31                 m_collisionShape(0),
32                 m_physicsEnv(0)
33
34         {
35         }
36         SimdVector3     m_localInertiaTensor;
37         SimdVector3     m_gravity;
38         SimdScalar      m_mass;
39         SimdScalar      m_restitution;
40         SimdScalar      m_friction;
41         SimdScalar      m_linearDamping;
42         SimdScalar      m_angularDamping;
43         void*           m_broadphaseHandle;
44         class   PHY_IMotionState*                       m_MotionState;
45
46         CollisionShape*                 m_collisionShape;
47         CcdPhysicsEnvironment*  m_physicsEnv; //needed for self-replication
48 };
49
50
51 class RigidBody;
52
53 ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
54 class CcdPhysicsController : public PHY_IPhysicsController      
55 {
56         RigidBody* m_body;
57         class   PHY_IMotionState*                       m_MotionState;
58         CollisionShape*                 m_collisionShape;
59         void*           m_newClientInfo;
60
61         CcdConstructionInfo     m_cci;//needed for replication
62         void GetWorldOrientation(SimdMatrix3x3& mat);
63
64         void CreateRigidbody();
65
66         public:
67         
68                 int                             m_collisionDelay;
69         
70                 void*  m_broadphaseHandle;
71
72                 CcdPhysicsController (const CcdConstructionInfo& ci);
73
74                 virtual ~CcdPhysicsController();
75
76
77                 RigidBody* GetRigidBody() { return m_body;}
78
79                 CollisionShape* GetCollisionShape() { return m_collisionShape;}
80                 ////////////////////////////////////
81                 // PHY_IPhysicsController interface
82                 ////////////////////////////////////
83
84
85                 /**
86                         SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
87                 */
88                 virtual bool            SynchronizeMotionStates(float time);
89                 /**
90                         WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
91                 */
92                 
93                 virtual void            WriteMotionStateToDynamics(bool nondynaonly);
94                 virtual void            WriteDynamicsToMotionState();
95                 // controller replication
96                 virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
97
98                 // kinematic methods
99                 virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
100                 virtual void            RelativeRotate(const float drot[9],bool local);
101                 virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
102                 virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
103                 virtual void            setPosition(float posX,float posY,float posZ);
104                 virtual void            getPosition(PHY__Vector3&       pos) const;
105
106                 virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
107                 
108                 // physics methods
109                 virtual void            ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
110                 virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
111                 virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
112                 virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
113                 virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
114                 virtual void            SetActive(bool active);
115
116                 // reading out information from physics
117                 virtual void            GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
118                 virtual void            GetAngularVelocity(float& angVelX,float& angVelY,float& angVelZ);
119                 virtual void            GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); 
120                 virtual void            getReactionForce(float& forceX,float& forceY,float& forceZ);
121
122                 // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
123                 virtual void            setRigidBody(bool rigid);
124
125                 
126                 virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
127
128                 // clientinfo for raycasts for example
129                 virtual void*                           getNewClientInfo();
130                 virtual void                            setNewClientInfo(void* clientinfo);
131                 virtual PHY_IPhysicsController* GetReplica() {return 0;}
132
133                 virtual void    calcXform() {} ;
134                 virtual void SetMargin(float margin) {};
135                 virtual float GetMargin() const {return 0.f;};
136
137
138                 bool    wantsSleeping();
139
140                 void    UpdateDeactivation(float timeStep);
141
142                 void    SetAabb(const SimdVector3& aabbMin,const SimdVector3& aabbMax);
143
144
145 };
146
147 #endif //BULLET2_PHYSICSCONTROLLER_H