physicsBody.h

Engine/source/T3D/physics/physicsBody.h

More...

Classes:

class

Simple physics object that represents a single rigid body.

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_PHYSICSBODY_H_
 25#define _T3D_PHYSICS_PHYSICSBODY_H_
 26
 27#ifndef _T3D_PHYSICSCOMMON_H_
 28#include "T3D/physics/physicsCommon.h"
 29#endif
 30#ifndef _T3D_PHYSICS_PHYSICSOBJECT_H_
 31#include "T3D/physics/physicsObject.h"
 32#endif
 33
 34class PhysicsCollision;
 35class SceneObject;
 36
 37
 38/// Simple physics object that represents a single rigid body.
 39class PhysicsBody : public PhysicsObject
 40{
 41public:
 42
 43   virtual ~PhysicsBody() {}
 44
 45   enum
 46   {
 47      /// Marks the body as a trigger object which is only used
 48      /// to get collision events and not get collision response.
 49      BF_TRIGGER = BIT( 0 ),
 50
 51      /// The body is kinematic and assumed to be moved by 
 52      /// the game code via transforms.
 53      BF_KINEMATIC = BIT( 1 ),
 54
 55      /// The body responds to contacts but does not push forces into others.
 56      BF_DEBRIS = BIT( 2 )
 57   };
 58
 59   /// Initialize the body with a collision shape 
 60   /// and basic physics properties.
 61   virtual bool init(   PhysicsCollision *shape, 
 62                        F32 mass,
 63                        U32 bodyFlags,
 64                        SceneObject *obj, 
 65                        PhysicsWorld *world ) = 0;
 66
 67   /// Returns true if the object is a dynamic rigid body 
 68   /// animated by the physics simulation.
 69   ///
 70   /// Kinematics are not considered to be dynamic.
 71   ///
 72   virtual bool isDynamic() const = 0;
 73
 74   /// Returns the collision shape used to create the body.
 75   virtual PhysicsCollision* getColShape() = 0;
 76
 77   ///
 78   virtual void setSleepThreshold( F32 linear, F32 angular ) = 0;
 79
 80   ///
 81   virtual void setDamping( F32 linear, F32 angular ) = 0;
 82
 83   ///
 84   virtual void getState( PhysicsState *outState ) = 0;
 85
 86   ///
 87   virtual F32 getMass() const = 0;
 88
 89   ///
 90   virtual Point3F getCMassPosition() const = 0;
 91
 92   ///
 93   virtual void setLinVelocity( const Point3F &vel ) = 0;
 94
 95   ///
 96   virtual void setAngVelocity( const Point3F &vel ) = 0;
 97
 98   ///
 99   virtual Point3F getLinVelocity() const = 0;
100
101   ///
102   virtual Point3F getAngVelocity() const = 0;
103
104   ///
105   virtual void setSleeping( bool sleeping ) = 0;
106
107   ///
108   virtual void setMaterial(  F32 restitution,
109                              F32 friction, 
110                              F32 staticFriction ) = 0;
111
112   ///
113   virtual void applyCorrection( const MatrixF &xfm ) = 0;
114
115   ///
116   virtual void applyImpulse( const Point3F &origin, const Point3F &force ) = 0;
117
118   ///
119   virtual void applyTorque( const Point3F &torque ) = 0;
120
121   ///
122   virtual void applyForce( const Point3F &force ) = 0;
123
124
125   virtual void findContact(SceneObject **contactObject,
126      VectorF *contactNormal,
127      Vector<SceneObject*> *outOverlapObjects) const = 0;
128
129   ///
130   virtual void moveKinematicTo(const MatrixF &xfm) = 0;
131
132   virtual bool isValid() = 0;
133
134};
135
136
137#endif // _T3D_PHYSICS_PHYSICSBODY_H_
138