rigid.h

Engine/source/T3D/rigid.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 _RIGID_H_
 25#define _RIGID_H_
 26
 27#ifndef _PLATFORM_H_
 28#include "platform/platform.h"
 29#endif
 30#ifndef _MPOINT3_H_
 31#include "math/mPoint3.h"
 32#endif
 33#ifndef _MMATRIX_H_
 34#include "math/mMatrix.h"
 35#endif
 36#ifndef _MQUAT_H_
 37#include "math/mQuat.h"
 38#endif
 39
 40//----------------------------------------------------------------------------
 41
 42class Rigid
 43{
 44public:
 45   MatrixF objectInertia;        ///< Moment of inertia
 46   MatrixF invObjectInertia;     ///< Inverse moment of inertia
 47   MatrixF invWorldInertia;      ///< Inverse moment of inertia in world space
 48
 49   Point3F force;
 50   Point3F torque;
 51
 52   Point3F linVelocity;          ///< Linear velocity
 53   Point3F linPosition;          ///< Current position
 54   Point3F linMomentum;          ///< Linear momentum
 55   Point3F angVelocity;          ///< Angular velocity
 56   QuatF   angPosition;          ///< Current rotation
 57   Point3F angMomentum;          ///< Angular momentum
 58
 59   Point3F centerOfMass;         ///< Center of mass in object space
 60   Point3F worldCenterOfMass;    ///< CofM in world space
 61   F32 mass;                     ///< Rigid body mass
 62   F32 oneOverMass;              ///< 1 / mass
 63   F32 restitution;              ///< Collision restitution
 64   F32 friction;                 ///< Friction coefficient
 65   bool atRest;
 66
 67private:
 68   void translateCenterOfMass(const Point3F &oldPos,const Point3F &newPos);
 69
 70public:
 71   //
 72   Rigid();
 73   void clearForces();
 74   void integrate(F32 delta);
 75
 76   void updateInertialTensor();
 77   void updateVelocity();
 78   void updateCenterOfMass();
 79
 80   void applyImpulse(const Point3F &v,const Point3F &impulse);
 81   bool resolveCollision(const Point3F& p,const Point3F &normal,Rigid*);
 82   bool resolveCollision(const Point3F& p,const Point3F &normal);
 83
 84   F32  getZeroImpulse(const Point3F& r,const Point3F& normal);
 85   F32  getKineticEnergy();
 86   void getOriginVector(const Point3F &r,Point3F* v);
 87   void setCenterOfMass(const Point3F &v);
 88   void getVelocity(const Point3F &p,Point3F* r);
 89   void getTransform(MatrixF* mat);
 90   void setTransform(const MatrixF& mat);
 91
 92   void setObjectInertia(const Point3F& r);
 93   void setObjectInertia();
 94   void invertObjectInertia();
 95
 96   bool checkRestCondition();
 97   void setAtRest();
 98};
 99
100
101#endif
102