Torque3D Documentation / _generateds / rigidBodyComponent.h

rigidBodyComponent.h

Engine/source/T3D/components/physics/rigidBodyComponent.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 RIGID_BODY_COMPONENT_H
 25#define RIGID_BODY_COMPONENT_H
 26
 27#ifndef COMPONENT_H
 28#include "T3D/components/component.h"
 29#endif
 30#ifndef _T3D_PHYSICSCOMMON_H_
 31#include "T3D/physics/physicsCommon.h"
 32#endif
 33#ifndef COLLISION_COMPONENT_H
 34#include "T3D/components/collision/collisionComponent.h"
 35#endif
 36#ifndef PHYSICS_COMPONENT_INTERFACE_H
 37#include "T3D/components/physics/physicsComponentInterface.h"
 38#endif
 39
 40class PhysicsBody;
 41
 42//////////////////////////////////////////////////////////////////////////
 43/// 
 44/// 
 45//////////////////////////////////////////////////////////////////////////
 46class RigidBodyComponent : public Component, public PhysicsComponentInterface
 47{
 48   typedef Component Parent;
 49
 50   enum SimType
 51   {
 52      /// This physics representation only exists on the client
 53      /// world and the server only does ghosting.
 54      SimType_ClientOnly,
 55
 56      /// The physics representation only exists on the server world
 57      /// and the client gets delta updates for rendering.
 58      SimType_ServerOnly,
 59
 60      /// The physics representation exists on the client and the server
 61      /// worlds with corrections occuring when the client gets out of sync.
 62      SimType_ClientServer,
 63
 64      /// The bits used to pack the SimType field.
 65      SimType_Bits = 3,
 66
 67   } mSimType;
 68
 69   //
 70   //
 71   /// The current physics state.
 72   PhysicsState mState;
 73
 74   /// The previous and current render states.
 75   PhysicsState mRenderState[2];
 76
 77   /// The abstracted physics actor.
 78   PhysicsBody *mPhysicsRep;
 79
 80   PhysicsWorld *mWorld;
 81
 82   /// The starting position to place the shape when
 83   /// the level begins or is reset.
 84   MatrixF mResetPos;
 85   //
 86   //
 87
 88   /// If true then no corrections are sent from the server 
 89   /// and/or applied from the client.
 90   ///
 91   /// This is only ment for debugging.
 92   ///
 93   static bool smNoCorrections;
 94
 95   /// If true then no smoothing is done on the client when
 96   /// applying server corrections.
 97   ///
 98   /// This is only ment for debugging.
 99   ///
100   static bool smNoSmoothing;
101
102   ///
103   F32 mMass;
104
105   /// 
106   F32 mDynamicFriction;
107
108   /// 
109   F32 mStaticFriction;
110
111   ///
112   F32 mRestitution;
113
114   ///
115   F32 mLinearDamping;
116
117   ///
118   F32 mAngularDamping;
119
120   /// 
121   F32 mLinearSleepThreshold;
122
123   ///
124   F32 mAngularSleepThreshold;
125
126   // A scale applied to the normal linear and angular damping
127   // when the object enters a water volume.
128   F32 mWaterDampingScale;
129
130   // The density of this object used for water buoyancy effects.
131   F32 mBuoyancyDensity;
132
133   CollisionComponent* mOwnerColComponent;
134
135   enum MaskBits {
136      PositionMask = Parent::NextFreeMask << 0,
137      FreezeMask = Parent::NextFreeMask << 1,
138      StateMask = Parent::NextFreeMask << 2,
139      VelocityMask = Parent::NextFreeMask << 3,
140      NextFreeMask = Parent::NextFreeMask << 4
141   };
142
143public:
144   RigidBodyComponent();
145   virtual ~RigidBodyComponent();
146   DECLARE_CONOBJECT(RigidBodyComponent);
147
148   virtual bool onAdd();
149   virtual void onRemove();
150   static void initPersistFields();
151
152   virtual void onComponentAdd();
153   virtual void onComponentRemove();
154
155   virtual void componentAddedToOwner(Component *comp);
156   virtual void componentRemovedFromOwner(Component *comp);
157
158   virtual void ownerTransformSet(MatrixF *mat);
159
160   inline F32 getMass() { return mMass; }
161   Point3F getVelocity() const { return mState.linVelocity; }
162   void applyImpulse(const Point3F &pos, const VectorF &vec);
163   void applyRadialImpulse(const Point3F &origin, F32 radius, F32 magnitude);
164
165   void updateContainerForces();
166
167   virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
168   virtual void unpackUpdate(NetConnection *con, BitStream *stream);
169
170   virtual void processTick();
171
172   void findContact();
173
174   /// Save the current transform as where we return to when a physics reset
175   /// event occurs. This is automatically set in onAdd but some manipulators
176   /// such as Prefab need to make use of this.
177   void storeRestorePos();
178
179   void updatePhysics(PhysicsCollision *collision = NULL);
180
181   void _onPhysicsReset(PhysicsResetEvent reset);
182};
183
184#endif // _RIGID_BODY_COMPONENT_H_
185