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