fixed the mouse-over sensor,
[blender-staging.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 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         void*           m_newClientInfo;
55
56         public:
57         
58                 int                             m_collisionDelay;
59         
60                 void*  m_broadphaseHandle;
61
62                 CcdPhysicsController (const CcdConstructionInfo& ci);
63
64                 virtual ~CcdPhysicsController();
65
66
67                 RigidBody* GetRigidBody() { return m_body;}
68
69                 CollisionShape* GetCollisionShape() { return m_collisionShape;}
70                 ////////////////////////////////////
71                 // PHY_IPhysicsController interface
72                 ////////////////////////////////////
73
74
75                 /**
76                         SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
77                 */
78                 virtual bool            SynchronizeMotionStates(float time);
79                 /**
80                         WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
81                 */
82                 
83                 virtual void            WriteMotionStateToDynamics(bool nondynaonly);
84                 virtual void            WriteDynamicsToMotionState();
85                 // controller replication
86                 virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
87
88                 // kinematic methods
89                 virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
90                 virtual void            RelativeRotate(const float drot[9],bool local);
91                 virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
92                 virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
93                 virtual void            setPosition(float posX,float posY,float posZ);
94                 virtual void            getPosition(PHY__Vector3&       pos) const;
95
96                 virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
97                 
98                 // physics methods
99                 virtual void            ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
100                 virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
101                 virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
102                 virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
103                 virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
104                 virtual void            SetActive(bool active);
105
106                 // reading out information from physics
107                 virtual void            GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
108                 virtual void            GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); 
109                 virtual void            getReactionForce(float& forceX,float& forceY,float& forceZ);
110
111                 // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
112                 virtual void            setRigidBody(bool rigid);
113
114                 
115                 virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
116
117                 // clientinfo for raycasts for example
118                 virtual void*                           getNewClientInfo();
119                 virtual void                            setNewClientInfo(void* clientinfo);
120                 virtual PHY_IPhysicsController* GetReplica() {return 0;}
121
122                 virtual void    calcXform() {} ;
123                 virtual void SetMargin(float margin) {};
124                 virtual float GetMargin() const {return 0.f;};
125
126
127                 bool    wantsSleeping();
128
129                 void    UpdateDeactivation(float timeStep);
130
131                 void    SetAabb(const SimdVector3& aabbMin,const SimdVector3& aabbMax);
132
133
134 };
135
136 #endif //BULLET2_PHYSICSCONTROLLER_H