physicsWorld.h 3.6 KB

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