2228b6511ce89b1525d00e1ba342530d331e0ca5
[blender.git] / source / gameengine / Physics / Bullet / CcdPhysicsController.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 /** \file CcdPhysicsController.h
17  *  \ingroup physbullet
18  */
19
20
21 #ifndef __CCDPHYSICSCONTROLLER_H__
22 #define __CCDPHYSICSCONTROLLER_H__
23
24 #include <vector>
25 #include <map>
26
27 #include "PHY_IPhysicsController.h"
28
29 ///     PHY_IPhysicsController is the abstract simplified Interface to a physical object.
30 ///     It contains the IMotionState and IDeformableMesh Interfaces.
31 #include "btBulletDynamicsCommon.h"
32 #include "LinearMath/btTransform.h"
33
34 #include "PHY_IMotionState.h"
35
36 extern float gDeactivationTime;
37 extern float gLinearSleepingTreshold;
38 extern float gAngularSleepingTreshold;
39 extern bool gDisableDeactivation;
40 class CcdPhysicsEnvironment;
41 class btMotionState;
42 class RAS_MeshObject;
43 struct DerivedMesh;
44 class btCollisionShape;
45
46
47 #define CCD_BSB_SHAPE_MATCHING  2
48 #define CCD_BSB_BENDING_CONSTRAINTS 8
49 #define CCD_BSB_AERO_VPOINT 16 /* aero model, Vertex normals are oriented toward velocity*/
50 #define CCD_BSB_AERO_VTWOSIDE 32 /* aero model, Vertex normals are flipped to match velocity */
51
52 /* BulletSoftBody.collisionflags */
53 #define CCD_BSB_COL_SDF_RS      2 /* SDF based rigid vs soft */
54 #define CCD_BSB_COL_CL_RS       4 /* Cluster based rigid vs soft */
55 #define CCD_BSB_COL_CL_SS       8 /* Cluster based soft vs soft */
56 #define CCD_BSB_COL_VF_SS       16 /* Vertex/Face based soft vs soft */
57
58
59 // Shape contructor
60 // It contains all the information needed to create a simple bullet shape at runtime
61 class CcdShapeConstructionInfo
62 {
63 public:
64         struct UVco 
65         {
66                 float uv[2];
67         };
68         
69         static CcdShapeConstructionInfo* FindMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope);
70
71         CcdShapeConstructionInfo() :
72                 m_shapeType(PHY_SHAPE_NONE),
73                 m_radius(1.0),
74                 m_height(1.0),
75                 m_halfExtend(0.f,0.f,0.f),
76                 m_childScale(1.0f,1.0f,1.0f),
77                 m_userData(NULL),
78                 m_refCount(1),
79                 m_meshObject(NULL),
80                 m_unscaledShape(NULL),
81                 m_forceReInstance(false),
82                 m_weldingThreshold1(0.f),
83                 m_shapeProxy(NULL)
84         {
85                 m_childTrans.setIdentity();
86         }
87
88         ~CcdShapeConstructionInfo();
89
90         CcdShapeConstructionInfo* AddRef()
91         { 
92                 m_refCount++;
93                 return this;
94         }
95
96         int Release()
97         {
98                 if (--m_refCount > 0)
99                         return m_refCount;
100                 delete this;
101                 return 0;
102         }
103
104         bool IsUnused(void)
105         {
106                 return (m_meshObject==NULL && m_shapeArray.size() == 0 && m_shapeProxy == NULL);
107         }
108
109         void AddShape(CcdShapeConstructionInfo* shapeInfo);
110
111         btTriangleMeshShape* GetMeshShape(void)
112         {
113                 return (m_unscaledShape);
114         }
115         CcdShapeConstructionInfo* GetChildShape(int i)
116         {
117                 if (i < 0 || i >= (int)m_shapeArray.size())
118                         return NULL;
119
120                 return m_shapeArray.at(i);
121         }
122         int FindChildShape(CcdShapeConstructionInfo* shapeInfo, void* userData)
123         {
124                 if (shapeInfo == NULL)
125                         return -1;
126                 for (int i=0; i<(int)m_shapeArray.size(); i++)
127                 {
128                         CcdShapeConstructionInfo* childInfo = m_shapeArray.at(i);
129                         if ((userData == NULL || userData == childInfo->m_userData) &&
130                                 (childInfo == shapeInfo ||
131                                  (childInfo->m_shapeType == PHY_SHAPE_PROXY && 
132                                   childInfo->m_shapeProxy == shapeInfo)))
133                                 return i;
134                 }
135                 return -1;
136         }
137
138         bool RemoveChildShape(int i)
139         {
140                 if (i < 0 || i >= (int)m_shapeArray.size())
141                         return false;
142                 m_shapeArray.at(i)->Release();
143                 if (i < (int)m_shapeArray.size()-1)
144                         m_shapeArray[i] = m_shapeArray.back();
145                 m_shapeArray.pop_back();
146                 return true;
147         }
148
149         bool SetMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope);
150         RAS_MeshObject* GetMesh(void)
151         {
152                 return m_meshObject;
153         }
154
155         bool UpdateMesh(class KX_GameObject* gameobj, class RAS_MeshObject* mesh);
156
157
158         bool SetProxy(CcdShapeConstructionInfo* shapeInfo);
159         CcdShapeConstructionInfo* GetProxy(void)
160         {
161                 return m_shapeProxy;
162         }
163
164         btCollisionShape* CreateBulletShape(btScalar margin, bool useGimpact=false, bool useBvh=true);
165
166         // member variables
167         PHY_ShapeType                   m_shapeType;
168         btScalar                                m_radius;
169         btScalar                                m_height;
170         btVector3                               m_halfExtend;
171         btTransform                             m_childTrans;
172         btVector3                               m_childScale;
173         void*                                   m_userData;     
174         btAlignedObjectArray<btScalar>  m_vertexArray;  // Contains both vertex array for polytope shape and
175                                                                                         // triangle array for concave mesh shape. Each vertex is 3 consecutive values
176                                                                                         // In this case a triangle is made of 3 consecutive points
177         std::vector<int>                m_polygonIndexArray;    // Contains the array of polygon index in the 
178                                                                                                         // original mesh that correspond to shape triangles.
179                                                                                                         // only set for concave mesh shape.
180         
181         std::vector<int>                m_triFaceArray; // Contains an array of triplets of face indices
182                                                                                         // quads turn into 2 tris
183
184         std::vector<UVco>               m_triFaceUVcoArray;     // Contains an array of pair of UV coordinate for each vertex of faces
185                                                                                                 // quads turn into 2 tris
186
187         void    setVertexWeldingThreshold1(float threshold)
188         {
189                 m_weldingThreshold1  = threshold*threshold;
190         }
191 protected:
192         static std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> m_meshShapeMap;
193         int                                             m_refCount;             // this class is shared between replicas
194                                                                                         // keep track of users so that we can release it 
195         RAS_MeshObject* m_meshObject;                   // Keep a pointer to the original mesh 
196         btBvhTriangleMeshShape* m_unscaledShape;// holds the shared unscale BVH mesh shape, 
197                                                                                         // the actual shape is of type btScaledBvhTriangleMeshShape
198         std::vector<CcdShapeConstructionInfo*> m_shapeArray;    // for compound shapes
199         bool    m_forceReInstance; //use gimpact for concave dynamic/moving collision detection
200         float   m_weldingThreshold1;    //welding closeby vertices together can improve softbody stability etc.
201         CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info
202
203
204 #ifdef WITH_CXX_GUARDEDALLOC
205 public:
206         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:CcdShapeConstructionInfo"); }
207         void operator delete( void *mem ) { MEM_freeN(mem); }
208 #endif
209 };
210
211 struct CcdConstructionInfo
212 {
213
214         ///CollisionFilterGroups provides some optional usage of basic collision filtering
215         ///this is done during broadphase, so very early in the pipeline
216         ///more advanced collision filtering should be done in btCollisionDispatcher::NeedsCollision
217         enum CollisionFilterGroups
218         {
219                 DefaultFilter = 1,
220                 StaticFilter = 2,
221                 KinematicFilter = 4,
222                 DebrisFilter = 8,
223                 SensorFilter = 16,
224                 AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorFilter,
225         };
226
227
228         CcdConstructionInfo()
229             :m_localInertiaTensor(1.f, 1.f, 1.f),
230                 m_gravity(0,0,0),
231                 m_scaling(1.f,1.f,1.f),
232                 m_mass(0.f),
233                 m_clamp_vel_min(-1.f),
234                 m_clamp_vel_max(-1.f),
235                 m_restitution(0.1f),
236                 m_friction(0.5f),
237                 m_linearDamping(0.1f),
238                 m_angularDamping(0.1f),
239                 m_margin(0.06f),
240                 m_gamesoftFlag(0),
241                 m_soft_linStiff(1.f),
242                 m_soft_angStiff(1.f),
243                 m_soft_volume(1.f),
244                 m_soft_viterations(0),
245                 m_soft_piterations(1),
246                 m_soft_diterations(0),
247                 m_soft_citerations(4),
248                 m_soft_kSRHR_CL(0.1f),
249                 m_soft_kSKHR_CL(1.f),
250                 m_soft_kSSHR_CL(0.5f),
251                 m_soft_kSR_SPLT_CL(0.5f),
252                 m_soft_kSK_SPLT_CL(0.5f),
253                 m_soft_kSS_SPLT_CL(0.5f),
254                 m_soft_kVCF(1.f),
255                 m_soft_kDP(0.f),
256                 m_soft_kDG(0.f),
257                 m_soft_kLF(0.f),
258                 m_soft_kPR(0.f),
259                 m_soft_kVC(0.f),
260                 m_soft_kDF(0.2f),
261                 m_soft_kMT(0),
262                 m_soft_kCHR(1.0f),
263                 m_soft_kKHR(0.1f),
264                 m_soft_kSHR(1.0f),
265                 m_soft_kAHR(0.7f),
266                 m_collisionFlags(0),
267                 m_bRigid(false),
268                 m_bSoft(false),
269                 m_bSensor(false),
270                 m_bGimpact(false),
271                 m_collisionFilterGroup(DefaultFilter),
272                 m_collisionFilterMask(AllFilter),
273                 m_collisionShape(0),
274                 m_MotionState(0),
275                 m_shapeInfo(0),
276                 m_physicsEnv(0),
277                 m_inertiaFactor(1.f),
278                 m_do_anisotropic(false),
279                 m_anisotropicFriction(1.f,1.f,1.f),
280                 m_do_fh(false),
281                 m_do_rot_fh(false),
282                 m_fh_spring(0.f),
283                 m_fh_damping(0.f),
284                 m_fh_distance(1.f),
285                 m_fh_normal(false),
286                 m_contactProcessingThreshold(1e10f)
287         {
288
289         }
290
291         btVector3       m_localInertiaTensor;
292         btVector3       m_gravity;
293         btVector3       m_scaling;
294         btScalar        m_mass;
295         btScalar        m_clamp_vel_min;  
296         btScalar        m_clamp_vel_max;  
297         btScalar        m_restitution;
298         btScalar        m_friction;
299         btScalar        m_linearDamping;
300         btScalar        m_angularDamping;
301         btScalar        m_margin;
302
303         ////////////////////
304         int             m_gamesoftFlag;
305         float   m_soft_linStiff;                        /* linear stiffness 0..1 */
306         float   m_soft_angStiff;                /* angular stiffness 0..1 */
307         float   m_soft_volume;                  /* volume preservation 0..1 */
308
309         int             m_soft_viterations;             /* Velocities solver iterations */
310         int             m_soft_piterations;             /* Positions solver iterations */
311         int             m_soft_diterations;             /* Drift solver iterations */
312         int             m_soft_citerations;             /* Cluster solver iterations */
313
314         float   m_soft_kSRHR_CL;                /* Soft vs rigid hardness [0,1] (cluster only) */
315         float   m_soft_kSKHR_CL;                /* Soft vs kinetic hardness [0,1] (cluster only) */
316         float   m_soft_kSSHR_CL;                /* Soft vs soft hardness [0,1] (cluster only) */
317         float   m_soft_kSR_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
318
319         float   m_soft_kSK_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
320         float   m_soft_kSS_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
321         float   m_soft_kVCF;                    /* Velocities correction factor (Baumgarte) */
322         float   m_soft_kDP;                     /* Damping coefficient [0,1] */
323
324         float   m_soft_kDG;                     /* Drag coefficient [0,+inf] */
325         float   m_soft_kLF;                     /* Lift coefficient [0,+inf] */
326         float   m_soft_kPR;                     /* Pressure coefficient [-inf,+inf] */
327         float   m_soft_kVC;                     /* Volume conversation coefficient [0,+inf] */
328
329         float   m_soft_kDF;                     /* Dynamic friction coefficient [0,1] */
330         float   m_soft_kMT;                     /* Pose matching coefficient [0,1] */
331         float   m_soft_kCHR;                    /* Rigid contacts hardness [0,1] */
332         float   m_soft_kKHR;                    /* Kinetic contacts hardness [0,1] */
333
334         float   m_soft_kSHR;                    /* Soft contacts hardness [0,1] */
335         float   m_soft_kAHR;                    /* Anchors hardness [0,1] */
336         int             m_soft_collisionflags;  /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
337         int             m_soft_numclusteriterations;    /* number of iterations to refine collision clusters*/
338 ///////////////////
339
340
341
342         int                     m_collisionFlags;
343         bool            m_bRigid;
344         bool            m_bSoft;
345         bool            m_bSensor;
346         bool            m_bGimpact;                     // use Gimpact for mesh body
347
348         ///optional use of collision group/mask:
349         ///only collision with object goups that match the collision mask.
350         ///this is very basic early out. advanced collision filtering should be
351         ///done in the btCollisionDispatcher::NeedsCollision and NeedsResponse
352         ///both values default to 1
353         short int       m_collisionFilterGroup;
354         short int       m_collisionFilterMask;
355
356         ///these pointers are used as argument passing for the CcdPhysicsController constructor
357         ///and not anymore after that
358         class btCollisionShape* m_collisionShape;
359         class PHY_IMotionState* m_MotionState;
360         class CcdShapeConstructionInfo* m_shapeInfo;
361         
362         CcdPhysicsEnvironment*  m_physicsEnv; //needed for self-replication
363         float   m_inertiaFactor;//tweak the inertia (hooked up to Blender 'formfactor'
364         bool    m_do_anisotropic;
365         btVector3 m_anisotropicFriction;
366
367         bool            m_do_fh;                 ///< Should the object have a linear Fh spring?
368         bool            m_do_rot_fh;             ///< Should the object have an angular Fh spring?
369         btScalar        m_fh_spring;             ///< Spring constant (both linear and angular)
370         btScalar        m_fh_damping;            ///< Damping factor (linear and angular) in range [0, 1]
371         btScalar        m_fh_distance;           ///< The range above the surface where Fh is active.    
372         bool            m_fh_normal;             ///< Should the object slide off slopes?
373         float           m_radius;//for fh backwards compatibility
374         
375         ///m_contactProcessingThreshold allows to process contact points with positive distance
376         ///normally only contacts with negative distance (penetration) are solved
377         ///however, rigid body stacking is more stable when positive contacts are still passed into the constraint solver
378         ///this might sometimes lead to collisions with 'internal edges' such as a sliding character controller
379         ///so disable/set m_contactProcessingThreshold to zero for sliding characters etc.
380         float           m_contactProcessingThreshold;///< Process contacts with positive distance in range [0..INF]
381
382 };
383
384
385 class btRigidBody;
386 class btCollisionObject;
387 class btSoftBody;
388
389 ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
390 class CcdPhysicsController : public PHY_IPhysicsController      
391 {
392 protected:
393         btCollisionObject* m_object;
394         
395
396         class PHY_IMotionState*         m_MotionState;
397         btMotionState*  m_bulletMotionState;
398         class btCollisionShape* m_collisionShape;
399         class CcdShapeConstructionInfo* m_shapeInfo;
400
401         friend class CcdPhysicsEnvironment;     // needed when updating the controller
402
403         //some book keeping for replication
404         bool    m_softbodyMappingDone;
405         bool    m_softBodyTransformInitialized;
406         bool    m_prototypeTransformInitialized;
407         btTransform     m_softbodyStartTrans;
408
409
410         void*           m_newClientInfo;
411         int                     m_registerCount;        // needed when multiple sensors use the same controller
412         CcdConstructionInfo     m_cci;//needed for replication
413
414         CcdPhysicsController* m_parentCtrl;
415
416         void GetWorldOrientation(btMatrix3x3& mat);
417
418         void CreateRigidbody();
419         bool CreateSoftbody();
420
421         bool Register() { 
422                 return (m_registerCount++ == 0) ? true : false;
423         }
424         bool Unregister() {
425                 return (--m_registerCount == 0) ? true : false;
426         }
427
428         void setWorldOrientation(const btMatrix3x3& mat);
429         void forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos);
430
431         public:
432         
433                 int                             m_collisionDelay;
434         
435
436                 CcdPhysicsController (const CcdConstructionInfo& ci);
437
438                 bool DeleteControllerShape();
439                 bool ReplaceControllerShape(btCollisionShape *newShape);
440
441                 virtual ~CcdPhysicsController();
442
443                 CcdConstructionInfo& getConstructionInfo()
444                 {
445                         return m_cci;
446                 }
447                 const CcdConstructionInfo& getConstructionInfo() const
448                 {
449                         return m_cci;
450                 }
451
452
453                 btRigidBody* GetRigidBody();
454                 btCollisionObject*      GetCollisionObject();
455                 btSoftBody* GetSoftBody();
456
457                 CcdShapeConstructionInfo* GetShapeInfo() { return m_shapeInfo; }
458
459                 btCollisionShape*       GetCollisionShape() { 
460                         return m_object->getCollisionShape();
461                 }
462                 ////////////////////////////////////
463                 // PHY_IPhysicsController interface
464                 ////////////////////////////////////
465
466
467                 /**
468                         SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
469                 */
470                 virtual bool            SynchronizeMotionStates(float time);
471                 /**
472                         WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
473                 */
474                 
475                 virtual void            WriteMotionStateToDynamics(bool nondynaonly);
476                 virtual void            WriteDynamicsToMotionState();
477
478                 // controller replication
479                 virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
480                 virtual void            SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env);
481
482                 // kinematic methods
483                 virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
484                 virtual void            RelativeRotate(const float drot[9],bool local);
485                 virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
486                 virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
487                 virtual void            setPosition(float posX,float posY,float posZ);
488                 virtual void            getPosition(PHY__Vector3&       pos) const;
489
490                 virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
491                 
492                 // physics methods
493                 virtual void            ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
494                 virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
495                 virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
496                 virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
497                 virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
498                 virtual void            SetActive(bool active);
499
500                 // reading out information from physics
501                 virtual void            GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
502                 virtual void            GetAngularVelocity(float& angVelX,float& angVelY,float& angVelZ);
503                 virtual void            GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); 
504                 virtual void            getReactionForce(float& forceX,float& forceY,float& forceZ);
505
506                 // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
507                 virtual void            setRigidBody(bool rigid);
508
509                 
510                 virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
511
512                 // clientinfo for raycasts for example
513                 virtual void*                           getNewClientInfo();
514                 virtual void                            setNewClientInfo(void* clientinfo);
515                 virtual PHY_IPhysicsController* GetReplica();
516                 
517                 ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
518                 short int       GetCollisionFilterGroup() const
519                 {
520                         return m_cci.m_collisionFilterGroup;
521                 }
522                 ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
523                 short int       GetCollisionFilterMask() const
524                 {
525                         return m_cci.m_collisionFilterMask;
526                 }
527
528                 virtual void calcXform() {}
529                 virtual void SetMargin(float margin) 
530                 {
531                         if (m_collisionShape)
532                                 m_collisionShape->setMargin(btScalar(margin));
533                 }
534                 virtual float GetMargin() const 
535                 {
536                         return (m_collisionShape) ? m_collisionShape->getMargin() : 0.f;
537                 }
538                 virtual float GetRadius() const 
539                 { 
540                         // this is not the actual shape radius, it's only used for Fh support
541                         return m_cci.m_radius;
542                 }
543                 virtual void  SetRadius(float margin) 
544                 {
545                         if (m_collisionShape && m_collisionShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
546                         {
547                                 btSphereShape* sphereShape = static_cast<btSphereShape*>(m_collisionShape);
548                                 sphereShape->setUnscaledRadius(margin);
549                         }
550                         m_cci.m_radius = margin;
551                 }
552                 
553                 // velocity clamping
554                 virtual void SetLinVelocityMin(float val) 
555                 {
556                         m_cci.m_clamp_vel_min= val;
557                 }
558                 virtual float GetLinVelocityMin() const 
559                 {
560                         return m_cci.m_clamp_vel_min;
561                 }
562                 virtual void SetLinVelocityMax(float val) 
563                 {
564                         m_cci.m_clamp_vel_max= val;
565                 }
566                 virtual float GetLinVelocityMax() const 
567                 {
568                         return m_cci.m_clamp_vel_max;
569                 }
570
571                 bool    wantsSleeping();
572
573                 void    UpdateDeactivation(float timeStep);
574
575                 void    SetCenterOfMassTransform(btTransform& xform);
576
577                 static btTransform&     GetTransformFromMotionState(PHY_IMotionState* motionState);
578
579                 void    setAabb(const btVector3& aabbMin,const btVector3& aabbMax);
580
581
582                 class   PHY_IMotionState*                       GetMotionState()
583                 {
584                         return m_MotionState;
585                 }
586
587                 const class     PHY_IMotionState*                       GetMotionState() const
588                 {
589                         return m_MotionState;
590                 }
591
592                 class CcdPhysicsEnvironment* GetPhysicsEnvironment()
593                 {
594                         return m_cci.m_physicsEnv;
595                 }
596
597                 void    setParentCtrl(CcdPhysicsController* parentCtrl)
598                 {
599                         m_parentCtrl = parentCtrl;
600                 }
601
602                 CcdPhysicsController*   getParentCtrl()
603                 {
604                         return m_parentCtrl;
605                 }
606
607                 const CcdPhysicsController*     getParentCtrl() const
608                 {
609                         return m_parentCtrl;
610                 }
611
612                 virtual const char* getName()
613                 {
614                         return 0;
615                 }
616
617 #ifdef WITH_CXX_GUARDEDALLOC
618 public:
619         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:CcdPhysicsController"); }
620         void operator delete( void *mem ) { MEM_freeN(mem); }
621 #endif
622 };
623
624
625
626
627 ///DefaultMotionState implements standard motionstate, using btTransform
628 class   DefaultMotionState : public PHY_IMotionState
629
630 {
631         public:
632                 DefaultMotionState();
633
634                 virtual ~DefaultMotionState();
635
636                 virtual void    getWorldPosition(float& posX,float& posY,float& posZ);
637                 virtual void    getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
638                 virtual void    getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
639                 
640                 virtual void    setWorldPosition(float posX,float posY,float posZ);
641                 virtual void    setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
642                 virtual void    getWorldOrientation(float* ori);
643                 virtual void    setWorldOrientation(const float* ori);
644                 
645                 virtual void    calculateWorldTransformations();
646                 
647                 btTransform     m_worldTransform;
648                 btVector3               m_localScaling;
649         
650         
651 #ifdef WITH_CXX_GUARDEDALLOC
652 public:
653         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:DefaultMotionState"); }
654         void operator delete( void *mem ) { MEM_freeN(mem); }
655 #endif
656 };
657
658
659 #endif //__CCDPHYSICSCONTROLLER_H__