px3Body.h 4.1 KB

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