physicsWorld.h

Engine/source/T3D/physics/physicsWorld.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _T3D_PHYSICS_PHYSICSWORLD_H_
 25#define _T3D_PHYSICS_PHYSICSWORLD_H_
 26
 27#ifndef _SIGNAL_H_
 28#include "core/util/tSignal.h"
 29#endif
 30#ifndef _MPOINT3_H_
 31#include "math/mPoint3.h"
 32#endif
 33
 34class ProcessList;
 35class Point3F;
 36struct RayInfo;
 37class SceneRenderState;
 38class PhysicsBody;
 39
 40
 41
 42class PhysicsWorld
 43{
 44protected:
 45
 46   Signal<void()> mStaticChangedSignal;
 47
 48   Signal<void()> mUpdateSignal;
 49
 50   /// The current gravity force.
 51   Point3F mGravity;
 52
 53   /// Gpu acceleration
 54   static bool smGpuEnabled;
 55
 56public:
 57
 58   /// The constructor.
 59   PhysicsWorld();
 60
 61   /// The destructor.
 62   virtual ~PhysicsWorld() {};
 63
 64   /// 
 65   Signal<void()>& getUpdateSignal() { return mUpdateSignal; }
 66
 67   // Called when a static body in the scene has been removed.
 68   Signal<void()>& getStaticChangedSignal() { return mStaticChangedSignal; }
 69   
 70   /// Overloaded to do debug drawing.
 71   ///
 72   /// It is assumed the GFX state is setup prior to this call for
 73   /// rendering in world space.
 74   ///
 75   virtual void onDebugDraw( const SceneRenderState *state ) = 0;
 76
 77   /// Prepare the physics world for use.
 78   virtual bool initWorld( bool isServer, ProcessList *processList ) = 0;
 79
 80   /// Tears down the physics world destroying any existing
 81   /// bodies, joints, and controllers.
 82   virtual void destroyWorld() = 0;
 83
 84   ///
 85   virtual void reset() = 0;
 86
 87   /// Returns true if the physics world is active and simulating.
 88   virtual bool isEnabled() const = 0;
 89
 90   /// Returns the active gravity force.
 91   const Point3F& getGravity() const { return mGravity; }
 92
 93   /// An abstract way to raycast into any type of PhysicsWorld, in a way 
 94   /// that mirrors a Torque-style raycast.  
 95   //
 96   /// This method is not fully developed or very sophisticated. For example, 
 97   /// there is no system of collision groups or raycast masks, which could 
 98   /// be very complex to write in a PhysicsPlugin-Abstract way...
 99   //
100   // Optional forceAmt parameter will also apply a force to hit objects.
101   virtual bool castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse ) = 0;
102
103
104   ///
105   enum BodyType
106   {
107      BT_Static     = BIT( 0 ),
108      BT_Dynamic    = BIT( 1 ),
109      BT_Player     = BIT( 2 ),
110
111      BT_All = BT_Static | BT_Dynamic | BT_Player
112   };
113
114   ///
115   virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All ) = 0;
116
117   virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ) = 0;
118
119   /// Physics timing
120   static F32 smPhysicsStepTime;
121   static U32 smPhysicsMaxSubSteps;
122
123   /// Gpu acceleration
124   static bool isGpuEnabled() { return smGpuEnabled; }
125};
126
127
128#endif // _T3D_PHYSICS_PHYSICSWORLD_H_
129