Torque3D Documentation / _generateds / physicsBehavior.h

physicsBehavior.h

Engine/source/T3D/components/physics/physicsBehavior.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Torque Game Engine
  4// Copyright (C) GarageGames.com, Inc.
  5//-----------------------------------------------------------------------------
  6
  7#ifndef _PHYSICSBEHAVIOR_H_
  8#define _PHYSICSBEHAVIOR_H_
  9#include "T3D/components/component.h"
 10
 11#ifndef __RESOURCE_H__
 12#include "core/resource.h"
 13#endif
 14#ifndef _TSSHAPE_H_
 15#include "ts/tsShape.h"
 16#endif
 17#ifndef _SCENERENDERSTATE_H_
 18#include "scene/sceneRenderState.h"
 19#endif
 20#ifndef _MBOX_H_
 21#include "math/mBox.h"
 22#endif
 23#ifndef _ENTITY_H_
 24#include "T3D/entity.h"
 25#endif
 26#ifndef _CONVEX_H_
 27#include "collision/convex.h"
 28#endif
 29#ifndef _BOXCONVEX_H_
 30#include "collision/boxConvex.h"
 31#endif
 32#ifndef _RIGID_H_
 33#include "T3D/rigid.h"
 34#endif
 35#ifndef _T3D_PHYSICS_PHYSICSBODY_H_
 36#include "T3D/physics/physicsBody.h"
 37#endif
 38
 39#ifndef _RENDER_COMPONENT_INTERFACE_H_
 40#include "T3D/components/render/renderComponentInterface.h"
 41#endif
 42
 43class TSShapeInstance;
 44class SceneRenderState;
 45class PhysicsBody;
 46class PhysicsBehaviorInstance;
 47//////////////////////////////////////////////////////////////////////////
 48/// 
 49/// 
 50//////////////////////////////////////////////////////////////////////////
 51class PhysicsComponent : public Component
 52{
 53   typedef Component Parent;
 54
 55protected:
 56   bool mStatic;
 57   bool mAtRest;
 58   S32  mAtRestCounter;
 59
 60   VectorF mGravity;
 61   VectorF mVelocity;
 62   F32     mDrag;
 63   F32      mMass;
 64
 65   F32      mGravityMod;
 66
 67   S32 csmAtRestTimer;
 68   F32 sAtRestVelocity;      // Min speed after collisio
 69
 70public:
 71   enum MaskBits {
 72      PositionMask = Parent::NextFreeMask << 0,
 73      FreezeMask = Parent::NextFreeMask << 1,
 74      ForceMoveMask = Parent::NextFreeMask << 2,
 75      VelocityMask = Parent::NextFreeMask << 3,
 76      NextFreeMask = Parent::NextFreeMask << 4
 77   };
 78
 79   struct StateDelta
 80   {
 81      Move move;                    ///< Last move from server
 82      F32 dt;                       ///< Last interpolation time
 83      // Interpolation data
 84      Point3F pos;
 85      Point3F posVec;
 86      QuatF rot[2];
 87      // Warp data
 88      S32 warpTicks;                ///< Number of ticks to warp
 89      S32 warpCount;                ///< Current pos in warp
 90      Point3F warpOffset;
 91      QuatF warpRot[2];
 92   };
 93
 94   StateDelta mDelta;
 95   S32 mPredictionCount;            ///< Number of ticks to predict
 96
 97public:
 98   PhysicsComponent();
 99   virtual ~PhysicsComponent();
100   DECLARE_CONOBJECT(PhysicsComponent);
101
102   static void initPersistFields();
103
104   virtual void interpolateTick(F32 dt);
105   virtual void updatePos(const U32 /*mask*/, const F32 dt){}
106   virtual void _updatePhysics();
107   virtual PhysicsBody *getPhysicsRep();
108
109   virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
110   virtual void unpackUpdate(NetConnection *con, BitStream *stream);
111
112   virtual void onComponentAdd();
113
114   void updateContainer();
115
116   virtual void updateVelocity(const F32 dt);
117   virtual Point3F getVelocity() { return mVelocity; }
118   virtual void getOriginVector(const Point3F &p, Point3F* r);
119   virtual void getVelocity(const Point3F& r, Point3F* v);
120   virtual void setVelocity(const VectorF& vel);
121   virtual void setTransform(const MatrixF& mat);
122   virtual void setPosition(const Point3F& pos);
123   void setRenderPosition(const Point3F& pos, F32 dt);
124
125   virtual void applyImpulse(const Point3F&, const VectorF& vec);
126   virtual F32 getZeroImpulse(const Point3F& r, const Point3F& normal);
127   virtual void accumulateForce(F32 dt, Point3F force);
128
129   //Rigid Body Collision Conveinence Hooks
130   virtual bool updateCollision(F32 dt, Rigid& ns, CollisionList &cList) { return false; }
131   virtual bool resolveContacts(Rigid& ns, CollisionList& cList, F32 dt) { return false; }
132   //virtual bool resolveCollision(Rigid&  ns, CollisionList& cList) { return false; }
133   virtual bool resolveCollision(const Point3F& p, const Point3F &normal) { return false; }
134};
135
136#endif // _COMPONENT_H_
137