physicsWorld.h 3.9 KB

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