physicsBody.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_PHYSICSBODY_H_
  23. #define _T3D_PHYSICS_PHYSICSBODY_H_
  24. #ifndef _T3D_PHYSICSCOMMON_H_
  25. #include "T3D/physics/physicsCommon.h"
  26. #endif
  27. #ifndef _T3D_PHYSICS_PHYSICSOBJECT_H_
  28. #include "T3D/physics/physicsObject.h"
  29. #endif
  30. class PhysicsCollision;
  31. class SceneObject;
  32. /// Simple physics object that represents a single rigid body.
  33. class PhysicsBody : public PhysicsObject
  34. {
  35. public:
  36. virtual ~PhysicsBody() {}
  37. enum
  38. {
  39. /// Marks the body as a trigger object which is only used
  40. /// to get collision events and not get collision response.
  41. BF_TRIGGER = BIT( 0 ),
  42. /// The body is kinematic and assumed to be moved by
  43. /// the game code via transforms.
  44. BF_KINEMATIC = BIT( 1 ),
  45. /// The body responds to contacts but does not push forces into others.
  46. BF_DEBRIS = BIT( 2 )
  47. };
  48. /// Initialize the body with a collision shape
  49. /// and basic physics properties.
  50. virtual bool init( PhysicsCollision *shape,
  51. F32 mass,
  52. U32 bodyFlags,
  53. SceneObject *obj,
  54. PhysicsWorld *world ) = 0;
  55. /// Returns true if the object is a dynamic rigid body
  56. /// animated by the physics simulation.
  57. ///
  58. /// Kinematics are not considered to be dynamic.
  59. ///
  60. virtual bool isDynamic() const = 0;
  61. /// Returns the collision shape used to create the body.
  62. virtual PhysicsCollision* getColShape() = 0;
  63. ///
  64. virtual void setSleepThreshold( F32 linear, F32 angular ) = 0;
  65. ///
  66. virtual void setDamping( F32 linear, F32 angular ) = 0;
  67. ///
  68. virtual void getState( PhysicsState *outState ) = 0;
  69. ///
  70. virtual F32 getMass() const = 0;
  71. ///
  72. virtual Point3F getCMassPosition() const = 0;
  73. ///
  74. virtual void setLinVelocity( const Point3F &vel ) = 0;
  75. ///
  76. virtual void setAngVelocity( const Point3F &vel ) = 0;
  77. ///
  78. virtual Point3F getLinVelocity() const = 0;
  79. ///
  80. virtual Point3F getAngVelocity() const = 0;
  81. ///
  82. virtual void setSleeping( bool sleeping ) = 0;
  83. ///
  84. virtual void setMaterial( F32 restitution,
  85. F32 friction,
  86. F32 staticFriction ) = 0;
  87. ///
  88. virtual void applyCorrection( const MatrixF &xfm ) = 0;
  89. ///
  90. virtual void applyImpulse( const Point3F &origin, const Point3F &force ) = 0;
  91. ///
  92. virtual void applyTorque( const Point3F &torque ) = 0;
  93. ///
  94. virtual void applyForce( const Point3F &force ) = 0;
  95. virtual void findContact(SceneObject **contactObject,
  96. VectorF *contactNormal,
  97. Vector<SceneObject*> *outOverlapObjects) const = 0;
  98. ///
  99. virtual void moveKinematicTo(const MatrixF &xfm) = 0;
  100. virtual bool isValid() = 0;
  101. };
  102. #endif // _T3D_PHYSICS_PHYSICSBODY_H_