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