physicsWorld.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_PHYSICSWORLD_H_
  23. #define _T3D_PHYSICS_PHYSICSWORLD_H_
  24. #ifndef _SIGNAL_H_
  25. #include "core/util/tSignal.h"
  26. #endif
  27. #ifndef _MPOINT3_H_
  28. #include "math/mPoint3.h"
  29. #endif
  30. class ProcessList;
  31. class Point3F;
  32. struct RayInfo;
  33. class SceneRenderState;
  34. class PhysicsBody;
  35. class PhysicsWorld
  36. {
  37. protected:
  38. Signal<void()> mUpdateSignal;
  39. /// The current gravity force.
  40. Point3F mGravity;
  41. public:
  42. /// The constructor.
  43. PhysicsWorld();
  44. /// The destructor.
  45. virtual ~PhysicsWorld() {};
  46. ///
  47. Signal<void()>& getUpdateSignal() { return mUpdateSignal; }
  48. /// Overloaded to do debug drawing.
  49. ///
  50. /// It is assumed the GFX state is setup prior to this call for
  51. /// rendering in world space.
  52. ///
  53. virtual void onDebugDraw( const SceneRenderState *state ) = 0;
  54. /// Prepare the physics world for use.
  55. virtual bool initWorld( bool isServer, ProcessList *processList ) = 0;
  56. /// Tears down the physics world destroying any existing
  57. /// bodies, joints, and controllers.
  58. virtual void destroyWorld() = 0;
  59. ///
  60. virtual void reset() = 0;
  61. /// Returns true if the physics world is active and simulating.
  62. virtual bool isEnabled() const = 0;
  63. /// Returns the active gravity force.
  64. const Point3F& getGravity() const { return mGravity; }
  65. /// An abstract way to raycast into any type of PhysicsWorld, in a way
  66. /// that mirrors a Torque-style raycast.
  67. //
  68. /// This method is not fully developed or very sophisticated. For example,
  69. /// there is no system of collision groups or raycast masks, which could
  70. /// be very complex to write in a PhysicsPlugin-Abstract way...
  71. //
  72. // Optional forceAmt parameter will also apply a force to hit objects.
  73. virtual bool castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse ) = 0;
  74. ///
  75. enum BodyType
  76. {
  77. BT_Static = BIT( 0 ),
  78. BT_Dynamic = BIT( 1 ),
  79. BT_Player = BIT( 2 ),
  80. BT_All = BT_Static | BT_Dynamic | BT_Player
  81. };
  82. ///
  83. virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All ) = 0;
  84. virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ) = 0;
  85. };
  86. #endif // _T3D_PHYSICS_PHYSICSWORLD_H_