btBody.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _T3D_PHYSICS_BTBODY_H_
  23. #define _T3D_PHYSICS_BTBODY_H_
  24. #ifndef _T3D_PHYSICS_PHYSICSBODY_H_
  25. #include "T3D/physics/physicsBody.h"
  26. #endif
  27. #ifndef _REFBASE_H_
  28. #include "core/util/refBase.h"
  29. #endif
  30. #ifndef _MMATRIX_H_
  31. #include "math/mMatrix.h"
  32. #endif
  33. class BtWorld;
  34. class btRigidBody;
  35. class btCompoundShape;
  36. class BtCollision;
  37. class BtBody : public PhysicsBody
  38. {
  39. protected:
  40. /// The physics world we are in.
  41. BtWorld *mWorld;
  42. /// The physics actor.
  43. btRigidBody *mActor;
  44. /// The collision representation.
  45. StrongRefPtr<BtCollision> mColShape;
  46. /// Our local compound if we had to adjust
  47. /// the mass center on a dynamic.
  48. btCompoundShape *mCompound;
  49. ///
  50. F32 mMass;
  51. ///
  52. bool mIsDynamic;
  53. /// Is the body participating in the physics simulation.
  54. bool mIsEnabled;
  55. /// The center of mass offset used if the graphical
  56. /// transform is not at the mass center.
  57. MatrixF *mCenterOfMass;
  58. /// The inverse center of mass offset.
  59. MatrixF *mInvCenterOfMass;
  60. ///
  61. void _releaseActor();
  62. public:
  63. BtBody();
  64. virtual ~BtBody();
  65. // PhysicsObject
  66. virtual PhysicsWorld* getWorld();
  67. virtual void setTransform( const MatrixF &xfm );
  68. virtual MatrixF& getTransform( MatrixF *outMatrix );
  69. virtual Box3F getWorldBounds();
  70. virtual void setSimulationEnabled( bool enabled );
  71. virtual bool isSimulationEnabled() { return mIsEnabled; }
  72. // PhysicsBody
  73. virtual bool init( PhysicsCollision *shape,
  74. F32 mass,
  75. U32 bodyFlags,
  76. SceneObject *obj,
  77. PhysicsWorld *world );
  78. virtual bool isDynamic() const { return mIsDynamic; }
  79. virtual PhysicsCollision* getColShape();
  80. virtual void setSleepThreshold( F32 linear, F32 angular );
  81. virtual void setDamping( F32 linear, F32 angular );
  82. virtual void getState( PhysicsState *outState );
  83. virtual F32 getMass() const { return mMass; }
  84. virtual Point3F getCMassPosition() const;
  85. virtual void setLinVelocity( const Point3F &vel );
  86. virtual void setAngVelocity( const Point3F &vel );
  87. virtual Point3F getLinVelocity() const;
  88. virtual Point3F getAngVelocity() const;
  89. virtual void setSleeping( bool sleeping );
  90. virtual void setMaterial( F32 restitution,
  91. F32 friction,
  92. F32 staticFriction );
  93. virtual void applyCorrection( const MatrixF &xfm );
  94. virtual void applyImpulse( const Point3F &origin, const Point3F &force );
  95. virtual void applyTorque( const Point3F &torque );
  96. virtual void applyForce( const Point3F &force );
  97. virtual void findContact(SceneObject **contactObject, VectorF *contactNormal, Vector<SceneObject*> *outOverlapObjects) const;
  98. virtual void moveKinematicTo(const MatrixF &xfm);
  99. };
  100. #endif // _T3D_PHYSICS_BTBODY_H_