3a8590e261c6925ff7ff41082a243c110f9275d7
[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_friction(0.1f),
19                 m_restitution(0.1f),
20                 m_linearDamping(0.1f),
21                 m_angularDamping(0.1f),
22                 m_MotionState(0),
23                 m_collisionShape(0)
24
25         {
26         }
27         SimdVector3     m_localInertiaTensor;
28         SimdVector3     m_gravity;
29         SimdScalar      m_mass;
30         SimdScalar      m_friction;
31         SimdScalar      m_restitution;
32         
33         SimdScalar      m_linearDamping;
34         SimdScalar      m_angularDamping;
35         void*           m_broadphaseHandle;
36         class   PHY_IMotionState*                       m_MotionState;
37
38         CollisionShape*                 m_collisionShape;
39         
40 };
41
42
43 class RigidBody;
44
45 ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
46 class CcdPhysicsController : public PHY_IPhysicsController      
47 {
48         RigidBody* m_body;
49         class   PHY_IMotionState*                       m_MotionState;
50         CollisionShape*                 m_collisionShape;
51
52         int                             m_sleepingCounter;
53         public:
54         
55                 int                             m_collisionDelay;
56         
57                 SimdScalar      m_friction;
58                 SimdScalar      m_restitution;
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    SetAabb(const SimdVector3& aabbMin,const SimdVector3& aabbMax);
129
130
131 };
132
133 #endif //BULLET2_PHYSICSCONTROLLER_H