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