f1f0ca31419a7d453731b4648fbf983a10484d78
[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_linearFactor(0.f, 0.f, 0.f),
233                 m_angularFactor(0.f, 0.f, 0.f),
234                 m_mass(0.f),
235                 m_clamp_vel_min(-1.f),
236                 m_clamp_vel_max(-1.f),
237                 m_restitution(0.1f),
238                 m_friction(0.5f),
239                 m_linearDamping(0.1f),
240                 m_angularDamping(0.1f),
241                 m_margin(0.06f),
242                 m_gamesoftFlag(0),
243                 m_soft_linStiff(1.f),
244                 m_soft_angStiff(1.f),
245                 m_soft_volume(1.f),
246                 m_soft_viterations(0),
247                 m_soft_piterations(1),
248                 m_soft_diterations(0),
249                 m_soft_citerations(4),
250                 m_soft_kSRHR_CL(0.1f),
251                 m_soft_kSKHR_CL(1.f),
252                 m_soft_kSSHR_CL(0.5f),
253                 m_soft_kSR_SPLT_CL(0.5f),
254                 m_soft_kSK_SPLT_CL(0.5f),
255                 m_soft_kSS_SPLT_CL(0.5f),
256                 m_soft_kVCF(1.f),
257                 m_soft_kDP(0.f),
258                 m_soft_kDG(0.f),
259                 m_soft_kLF(0.f),
260                 m_soft_kPR(0.f),
261                 m_soft_kVC(0.f),
262                 m_soft_kDF(0.2f),
263                 m_soft_kMT(0),
264                 m_soft_kCHR(1.0f),
265                 m_soft_kKHR(0.1f),
266                 m_soft_kSHR(1.0f),
267                 m_soft_kAHR(0.7f),
268                 m_collisionFlags(0),
269                 m_bRigid(false),
270                 m_bSoft(false),
271                 m_bSensor(false),
272                 m_bCharacter(false),
273                 m_bGimpact(false),
274                 m_collisionFilterGroup(DefaultFilter),
275                 m_collisionFilterMask(AllFilter),
276                 m_collisionShape(0),
277                 m_MotionState(0),
278                 m_shapeInfo(0),
279                 m_physicsEnv(0),
280                 m_inertiaFactor(1.f),
281                 m_do_anisotropic(false),
282                 m_anisotropicFriction(1.f,1.f,1.f),
283                 m_do_fh(false),
284                 m_do_rot_fh(false),
285                 m_fh_spring(0.f),
286                 m_fh_damping(0.f),
287                 m_fh_distance(1.f),
288                 m_fh_normal(false),
289                 m_contactProcessingThreshold(1e10f)
290         {
291
292         }
293
294         btVector3       m_localInertiaTensor;
295         btVector3       m_gravity;
296         btVector3       m_scaling;
297         btVector3       m_linearFactor;
298         btVector3       m_angularFactor;
299         btScalar        m_mass;
300         btScalar        m_clamp_vel_min;  
301         btScalar        m_clamp_vel_max;  
302         btScalar        m_restitution;
303         btScalar        m_friction;
304         btScalar        m_linearDamping;
305         btScalar        m_angularDamping;
306         btScalar        m_margin;
307
308         ////////////////////
309         float   m_stepHeight;
310         float   m_jumpSpeed;
311         float   m_fallSpeed;
312         
313         int             m_gamesoftFlag;
314         float   m_soft_linStiff;                        /* linear stiffness 0..1 */
315         float   m_soft_angStiff;                /* angular stiffness 0..1 */
316         float   m_soft_volume;                  /* volume preservation 0..1 */
317
318         int             m_soft_viterations;             /* Velocities solver iterations */
319         int             m_soft_piterations;             /* Positions solver iterations */
320         int             m_soft_diterations;             /* Drift solver iterations */
321         int             m_soft_citerations;             /* Cluster solver iterations */
322
323         float   m_soft_kSRHR_CL;                /* Soft vs rigid hardness [0,1] (cluster only) */
324         float   m_soft_kSKHR_CL;                /* Soft vs kinetic hardness [0,1] (cluster only) */
325         float   m_soft_kSSHR_CL;                /* Soft vs soft hardness [0,1] (cluster only) */
326         float   m_soft_kSR_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
327
328         float   m_soft_kSK_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
329         float   m_soft_kSS_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
330         float   m_soft_kVCF;                    /* Velocities correction factor (Baumgarte) */
331         float   m_soft_kDP;                     /* Damping coefficient [0,1] */
332
333         float   m_soft_kDG;                     /* Drag coefficient [0,+inf] */
334         float   m_soft_kLF;                     /* Lift coefficient [0,+inf] */
335         float   m_soft_kPR;                     /* Pressure coefficient [-inf,+inf] */
336         float   m_soft_kVC;                     /* Volume conversation coefficient [0,+inf] */
337
338         float   m_soft_kDF;                     /* Dynamic friction coefficient [0,1] */
339         float   m_soft_kMT;                     /* Pose matching coefficient [0,1] */
340         float   m_soft_kCHR;                    /* Rigid contacts hardness [0,1] */
341         float   m_soft_kKHR;                    /* Kinetic contacts hardness [0,1] */
342
343         float   m_soft_kSHR;                    /* Soft contacts hardness [0,1] */
344         float   m_soft_kAHR;                    /* Anchors hardness [0,1] */
345         int             m_soft_collisionflags;  /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
346         int             m_soft_numclusteriterations;    /* number of iterations to refine collision clusters*/
347 ///////////////////
348
349
350
351         int                     m_collisionFlags;
352         bool            m_bRigid;
353         bool            m_bSoft;
354         bool            m_bSensor;
355         bool            m_bCharacter;
356         bool            m_bGimpact;                     // use Gimpact for mesh body
357
358         ///optional use of collision group/mask:
359         ///only collision with object goups that match the collision mask.
360         ///this is very basic early out. advanced collision filtering should be
361         ///done in the btCollisionDispatcher::NeedsCollision and NeedsResponse
362         ///both values default to 1
363         short int       m_collisionFilterGroup;
364         short int       m_collisionFilterMask;
365
366         ///these pointers are used as argument passing for the CcdPhysicsController constructor
367         ///and not anymore after that
368         class btCollisionShape* m_collisionShape;
369         class PHY_IMotionState* m_MotionState;
370         class CcdShapeConstructionInfo* m_shapeInfo;
371         
372         CcdPhysicsEnvironment*  m_physicsEnv; //needed for self-replication
373         float   m_inertiaFactor;//tweak the inertia (hooked up to Blender 'formfactor'
374         bool    m_do_anisotropic;
375         btVector3 m_anisotropicFriction;
376
377         bool            m_do_fh;                 ///< Should the object have a linear Fh spring?
378         bool            m_do_rot_fh;             ///< Should the object have an angular Fh spring?
379         btScalar        m_fh_spring;             ///< Spring constant (both linear and angular)
380         btScalar        m_fh_damping;            ///< Damping factor (linear and angular) in range [0, 1]
381         btScalar        m_fh_distance;           ///< The range above the surface where Fh is active.    
382         bool            m_fh_normal;             ///< Should the object slide off slopes?
383         float           m_radius;//for fh backwards compatibility
384         
385         ///m_contactProcessingThreshold allows to process contact points with positive distance
386         ///normally only contacts with negative distance (penetration) are solved
387         ///however, rigid body stacking is more stable when positive contacts are still passed into the constraint solver
388         ///this might sometimes lead to collisions with 'internal edges' such as a sliding character controller
389         ///so disable/set m_contactProcessingThreshold to zero for sliding characters etc.
390         float           m_contactProcessingThreshold;///< Process contacts with positive distance in range [0..INF]
391
392 };
393
394 class btRigidBody;
395 class btCollisionObject;
396 class btSoftBody;
397 class btPairCachingGhostObject;
398
399 class BlenderBulletCharacterController : public btKinematicCharacterController
400 {
401 private:
402         btMotionState* m_motionState;
403         int m_jumps;
404         int m_maxJumps;
405
406 public:
407         BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight);
408
409         virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt);
410
411         int getMaxJumps() const;
412
413         void setMaxJumps(int maxJumps);
414
415         int getJumpCount() const;
416
417         virtual bool canJump() const;
418
419         virtual void jump();
420
421         const btVector3& getWalkDirection();
422 };
423
424 ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
425 class CcdPhysicsController : public PHY_IPhysicsController
426 {
427 protected:
428         btCollisionObject* m_object;
429         BlenderBulletCharacterController* m_characterController;
430         
431
432         class PHY_IMotionState*         m_MotionState;
433         btMotionState*  m_bulletMotionState;
434         class btCollisionShape* m_collisionShape;
435         class CcdShapeConstructionInfo* m_shapeInfo;
436
437         friend class CcdPhysicsEnvironment;     // needed when updating the controller
438
439         //some book keeping for replication
440         bool    m_softbodyMappingDone;
441         bool    m_softBodyTransformInitialized;
442         bool    m_prototypeTransformInitialized;
443         btTransform     m_softbodyStartTrans;
444
445
446         void*           m_newClientInfo;
447         int                     m_registerCount;        // needed when multiple sensors use the same controller
448         CcdConstructionInfo     m_cci;//needed for replication
449
450         CcdPhysicsController* m_parentCtrl;
451
452         void GetWorldOrientation(btMatrix3x3& mat);
453
454         void CreateRigidbody();
455         bool CreateSoftbody();
456         bool CreateCharacterController();
457
458         bool Register() { 
459                 return (m_registerCount++ == 0) ? true : false;
460         }
461         bool Unregister() {
462                 return (--m_registerCount == 0) ? true : false;
463         }
464
465         void setWorldOrientation(const btMatrix3x3& mat);
466         void forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos);
467
468         public:
469         
470                 int                             m_collisionDelay;
471         
472
473                 CcdPhysicsController (const CcdConstructionInfo& ci);
474
475                 bool DeleteControllerShape();
476                 bool ReplaceControllerShape(btCollisionShape *newShape);
477
478                 virtual ~CcdPhysicsController();
479
480                 CcdConstructionInfo& getConstructionInfo()
481                 {
482                         return m_cci;
483                 }
484                 const CcdConstructionInfo& getConstructionInfo() const
485                 {
486                         return m_cci;
487                 }
488
489
490                 btRigidBody* GetRigidBody();
491                 btCollisionObject*      GetCollisionObject();
492                 btSoftBody* GetSoftBody();
493                 btKinematicCharacterController* GetCharacterController();
494
495                 CcdShapeConstructionInfo* GetShapeInfo() { return m_shapeInfo; }
496
497                 btCollisionShape*       GetCollisionShape() { 
498                         return m_object->getCollisionShape();
499                 }
500                 ////////////////////////////////////
501                 // PHY_IPhysicsController interface
502                 ////////////////////////////////////
503
504
505                 /**
506                  * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
507                  */
508                 virtual bool            SynchronizeMotionStates(float time);
509                 /**
510                  * WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
511                  */
512                 
513                 virtual void            WriteMotionStateToDynamics(bool nondynaonly);
514                 virtual void            WriteDynamicsToMotionState();
515
516                 // controller replication
517                 virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
518                 virtual void            SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env);
519
520                 // kinematic methods
521                 virtual void            RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local);
522                 virtual void            SetWalkDirection(float dirX,float dirY,float dirZ,bool local);
523                 virtual void            RelativeRotate(const float drot[9],bool local);
524                 virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
525                 virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
526                 virtual void            setPosition(float posX,float posY,float posZ);
527                 virtual void            getPosition(MT_Vector3& pos) const;
528
529                 virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
530                 
531                 // physics methods
532                 virtual void            ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local);
533                 virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
534                 virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
535                 virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
536                 virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
537                 virtual void            Jump();
538                 virtual void            SetActive(bool active);
539
540                 // reading out information from physics
541                 virtual void            GetLinearVelocity(float& linvX,float& linvY,float& linvZ);
542                 virtual void            GetAngularVelocity(float& angVelX,float& angVelY,float& angVelZ);
543                 virtual void            GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); 
544                 virtual void            getReactionForce(float& forceX,float& forceY,float& forceZ);
545                 virtual void            GetWalkDirection(float& dirX,float& dirY,float& dirZ);
546
547                 // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
548                 virtual void            setRigidBody(bool rigid);
549
550                 
551                 virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
552
553                 // clientinfo for raycasts for example
554                 virtual void*                           getNewClientInfo();
555                 virtual void                            setNewClientInfo(void* clientinfo);
556                 virtual PHY_IPhysicsController* GetReplica();
557                 
558                 ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
559                 short int       GetCollisionFilterGroup() const
560                 {
561                         return m_cci.m_collisionFilterGroup;
562                 }
563                 ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
564                 short int       GetCollisionFilterMask() const
565                 {
566                         return m_cci.m_collisionFilterMask;
567                 }
568
569                 virtual void calcXform() {}
570                 virtual void SetMargin(float margin) 
571                 {
572                         if (m_collisionShape)
573                                 m_collisionShape->setMargin(btScalar(margin));
574                 }
575                 virtual float GetMargin() const 
576                 {
577                         return (m_collisionShape) ? m_collisionShape->getMargin() : 0.f;
578                 }
579                 virtual float GetRadius() const 
580                 { 
581                         // this is not the actual shape radius, it's only used for Fh support
582                         return m_cci.m_radius;
583                 }
584                 virtual void  SetRadius(float margin) 
585                 {
586                         if (m_collisionShape && m_collisionShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
587                         {
588                                 btSphereShape* sphereShape = static_cast<btSphereShape*>(m_collisionShape);
589                                 sphereShape->setUnscaledRadius(margin);
590                         }
591                         m_cci.m_radius = margin;
592                 }
593                 
594                 // velocity clamping
595                 virtual void SetLinVelocityMin(float val) 
596                 {
597                         m_cci.m_clamp_vel_min= val;
598                 }
599                 virtual float GetLinVelocityMin() const 
600                 {
601                         return m_cci.m_clamp_vel_min;
602                 }
603                 virtual void SetLinVelocityMax(float val) 
604                 {
605                         m_cci.m_clamp_vel_max= val;
606                 }
607                 virtual float GetLinVelocityMax() const 
608                 {
609                         return m_cci.m_clamp_vel_max;
610                 }
611
612                 bool    wantsSleeping();
613
614                 void    UpdateDeactivation(float timeStep);
615
616                 void    SetCenterOfMassTransform(btTransform& xform);
617
618                 static btTransform&     GetTransformFromMotionState(PHY_IMotionState* motionState);
619
620                 void    setAabb(const btVector3& aabbMin,const btVector3& aabbMax);
621
622
623                 class   PHY_IMotionState*                       GetMotionState()
624                 {
625                         return m_MotionState;
626                 }
627
628                 const class     PHY_IMotionState*                       GetMotionState() const
629                 {
630                         return m_MotionState;
631                 }
632
633                 class CcdPhysicsEnvironment* GetPhysicsEnvironment()
634                 {
635                         return m_cci.m_physicsEnv;
636                 }
637
638                 void    setParentCtrl(CcdPhysicsController* parentCtrl)
639                 {
640                         m_parentCtrl = parentCtrl;
641                 }
642
643                 CcdPhysicsController*   getParentCtrl()
644                 {
645                         return m_parentCtrl;
646                 }
647
648                 const CcdPhysicsController*     getParentCtrl() const
649                 {
650                         return m_parentCtrl;
651                 }
652
653                 virtual const char* getName()
654                 {
655                         return 0;
656                 }
657
658 #ifdef WITH_CXX_GUARDEDALLOC
659         MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdPhysicsController")
660 #endif
661 };
662
663
664
665
666 ///DefaultMotionState implements standard motionstate, using btTransform
667 class   DefaultMotionState : public PHY_IMotionState
668
669 {
670         public:
671                 DefaultMotionState();
672
673                 virtual ~DefaultMotionState();
674
675                 virtual void    getWorldPosition(float& posX,float& posY,float& posZ);
676                 virtual void    getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
677                 virtual void    getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
678                 
679                 virtual void    setWorldPosition(float posX,float posY,float posZ);
680                 virtual void    setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
681                 virtual void    getWorldOrientation(float* ori);
682                 virtual void    setWorldOrientation(const float* ori);
683                 
684                 virtual void    calculateWorldTransformations();
685                 
686                 btTransform     m_worldTransform;
687                 btVector3               m_localScaling;
688         
689         
690 #ifdef WITH_CXX_GUARDEDALLOC
691         MEM_CXX_CLASS_ALLOC_FUNCS("GE:DefaultMotionState")
692 #endif
693 };
694
695
696 #endif  /* __CCDPHYSICSCONTROLLER_H__ */