btBody.h

Engine/source/T3D/physics/bullet/btBody.h

More...

Classes:

class

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_BTBODY_H_
 25#define _T3D_PHYSICS_BTBODY_H_
 26
 27#ifndef _T3D_PHYSICS_PHYSICSBODY_H_
 28#include "T3D/physics/physicsBody.h"
 29#endif
 30#ifndef _REFBASE_H_
 31#include "core/util/refBase.h"
 32#endif
 33#ifndef _MMATRIX_H_
 34#include "math/mMatrix.h"
 35#endif
 36
 37class BtWorld;
 38class btRigidBody;
 39class btCompoundShape;
 40class BtCollision;
 41
 42
 43class BtBody : public PhysicsBody
 44{
 45protected:
 46
 47   /// The physics world we are in.
 48   BtWorld *mWorld;
 49
 50   /// The physics actor.
 51   btRigidBody *mActor;
 52
 53   /// The collision representation.
 54   StrongRefPtr<BtCollision> mColShape;
 55
 56   /// Our local compound if we had to adjust
 57   /// the mass center on a dynamic.
 58   btCompoundShape *mCompound;
 59
 60   ///
 61   F32 mMass;
 62
 63   ///
 64   bool mIsDynamic;
 65
 66   /// Is the body participating in the physics simulation.
 67   bool mIsEnabled;
 68
 69   /// The center of mass offset used if the graphical
 70   /// transform is not at the mass center.
 71   MatrixF *mCenterOfMass;
 72
 73   /// The inverse center of mass offset.
 74   MatrixF *mInvCenterOfMass;
 75
 76   ///
 77   void _releaseActor();
 78
 79public:
 80
 81   BtBody();
 82   virtual ~BtBody();
 83
 84   // PhysicsObject
 85   virtual PhysicsWorld* getWorld();
 86   virtual void setTransform( const MatrixF &xfm );
 87   virtual MatrixF& getTransform( MatrixF *outMatrix );
 88   virtual Box3F getWorldBounds();
 89   virtual void setSimulationEnabled( bool enabled );
 90   virtual bool isSimulationEnabled() { return mIsEnabled; }
 91
 92   // PhysicsBody
 93   virtual bool init(   PhysicsCollision *shape, 
 94                        F32 mass,
 95                        U32 bodyFlags,
 96                        SceneObject *obj, 
 97                        PhysicsWorld *world );
 98   virtual bool isDynamic() const { return mIsDynamic; }
 99   virtual PhysicsCollision* getColShape();
100   virtual void setSleepThreshold( F32 linear, F32 angular );
101   virtual void setDamping( F32 linear, F32 angular );
102   virtual void getState( PhysicsState *outState );
103   virtual F32 getMass() const { return mMass; }
104   virtual Point3F getCMassPosition() const;
105   virtual void setLinVelocity( const Point3F &vel );
106   virtual void setAngVelocity( const Point3F &vel );
107   virtual Point3F getLinVelocity() const;
108   virtual Point3F getAngVelocity() const;
109   virtual void setSleeping( bool sleeping );
110   virtual void setMaterial(  F32 restitution,
111                              F32 friction, 
112                              F32 staticFriction );
113   virtual void applyCorrection( const MatrixF &xfm );
114   virtual void applyImpulse( const Point3F &origin, const Point3F &force );
115   virtual void applyTorque( const Point3F &torque );
116   virtual void applyForce( const Point3F &force );
117   virtual void findContact(SceneObject **contactObject, VectorF *contactNormal, Vector<SceneObject*> *outOverlapObjects) const;
118   virtual void moveKinematicTo(const MatrixF &xfm);
119
120   virtual bool isValid() { return mActor != nullptr; }
121
122};
123
124#endif // _T3D_PHYSICS_BTBODY_H_
125