px3Body.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 _PX3BODY_H_
  23. #define _PX3BODY_H_
  24. #ifndef _T3D_PHYSICS_PHYSICSBODY_H_
  25. #include "T3D/physics/physicsBody.h"
  26. #endif
  27. #ifndef _PHYSICS_PHYSICSUSERDATA_H_
  28. #include "T3D/physics/physicsUserData.h"
  29. #endif
  30. #ifndef _REFBASE_H_
  31. #include "core/util/refBase.h"
  32. #endif
  33. #ifndef _MMATRIX_H_
  34. #include "math/mMatrix.h"
  35. #endif
  36. class Px3World;
  37. class Px3Collision;
  38. struct Px3CollisionDesc;
  39. namespace physx{
  40. class PxRigidActor;
  41. class PxMaterial;
  42. class PxShape;
  43. }
  44. class Px3Body : public PhysicsBody
  45. {
  46. protected:
  47. /// The physics world we are in.
  48. Px3World *mWorld;
  49. /// The physics actor.
  50. physx::PxRigidActor *mActor;
  51. /// The unshared local material used on all the
  52. /// shapes on this actor.
  53. physx::PxMaterial *mMaterial;
  54. /// We hold the collision reference as it contains
  55. /// allocated objects that we own and must free.
  56. StrongRefPtr<Px3Collision> mColShape;
  57. ///
  58. MatrixF mInternalTransform;
  59. /// The body flags set at creation time.
  60. U32 mBodyFlags;
  61. /// Is true if this body is enabled and active
  62. /// in the simulation of the scene.
  63. bool mIsEnabled;
  64. bool mIsStatic;
  65. ///
  66. void _releaseActor();
  67. public:
  68. Px3Body();
  69. virtual ~Px3Body();
  70. // PhysicsObject
  71. virtual PhysicsWorld* getWorld();
  72. virtual void setTransform( const MatrixF &xfm );
  73. virtual MatrixF& getTransform( MatrixF *outMatrix );
  74. virtual Box3F getWorldBounds();
  75. virtual void setSimulationEnabled( bool enabled );
  76. virtual bool isSimulationEnabled() { return mIsEnabled; }
  77. // PhysicsBody
  78. virtual bool init( PhysicsCollision *shape,
  79. F32 mass,
  80. U32 bodyFlags,
  81. SceneObject *obj,
  82. PhysicsWorld *world );
  83. virtual bool isDynamic() const;
  84. virtual PhysicsCollision* getColShape();
  85. virtual void setSleepThreshold( F32 linear, F32 angular );
  86. virtual void setDamping( F32 linear, F32 angular );
  87. virtual void getState( PhysicsState *outState );
  88. virtual F32 getMass() const;
  89. virtual Point3F getCMassPosition() const;
  90. virtual void setLinVelocity( const Point3F &vel );
  91. virtual void setAngVelocity( const Point3F &vel );
  92. virtual Point3F getLinVelocity() const;
  93. virtual Point3F getAngVelocity() const;
  94. virtual void setSleeping( bool sleeping );
  95. virtual void setMaterial( F32 restitution,
  96. F32 friction,
  97. F32 staticFriction );
  98. virtual void applyCorrection( const MatrixF &xfm );
  99. virtual void applyImpulse( const Point3F &origin, const Point3F &force );
  100. virtual void applyTorque( const Point3F &torque );
  101. virtual void applyForce( const Point3F &force );
  102. virtual void findContact(SceneObject **contactObject, VectorF *contactNormal,
  103. Vector<SceneObject*> *outOverlapObjects) const;
  104. virtual void moveKinematicTo(const MatrixF &xfm);
  105. };
  106. #endif // _PX3BODY_H_