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