vehicle.h

Engine/source/T3D/vehicles/vehicle.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 _VEHICLE_H_
 25#define _VEHICLE_H_
 26
 27#ifndef _SHAPEBASE_H_
 28#include "T3D/rigidShape.h"
 29#endif
 30
 31class ParticleEmitter;
 32class ParticleEmitterData;
 33class ClippedPolyList;
 34struct RenderInst;
 35class Vehicle;
 36
 37//----------------------------------------------------------------------------
 38
 39struct VehicleData : public RigidShapeData
 40{
 41   typedef RigidShapeData Parent;
 42
 43   struct Body {
 44      enum Sounds {
 45         SoftImpactSound,
 46         HardImpactSound,
 47         MaxSounds,
 48      };
 49      SFXProfile* sound[MaxSounds];
 50      F32 restitution;
 51      F32 friction;
 52   } body;
 53
 54   enum VehicleConsts
 55   {
 56      VC_NUM_DUST_EMITTERS = 1,
 57      VC_NUM_DAMAGE_EMITTER_AREAS = 2,
 58      VC_NUM_DAMAGE_LEVELS = 2,
 59      VC_NUM_BUBBLE_EMITTERS = 1,
 60      VC_NUM_DAMAGE_EMITTERS = VC_NUM_DAMAGE_LEVELS + VC_NUM_BUBBLE_EMITTERS,
 61      VC_NUM_SPLASH_EMITTERS = 2,
 62      VC_BUBBLE_EMITTER = VC_NUM_DAMAGE_EMITTERS - VC_NUM_BUBBLE_EMITTERS,
 63   };
 64
 65  enum Sounds {
 66      ExitWater,
 67      ImpactSoft,
 68      ImpactMedium,
 69      ImpactHard,
 70      Wake,
 71      MaxSounds
 72   };
 73   SFXProfile* waterSound[MaxSounds];
 74   F32 exitSplashSoundVel;
 75   F32 softSplashSoundVel;
 76   F32 medSplashSoundVel;
 77   F32 hardSplashSoundVel;
 78
 79   F32 minImpactSpeed;
 80   F32 softImpactSpeed;
 81   F32 hardImpactSpeed;
 82   F32 minRollSpeed;
 83   F32 maxSteeringAngle;
 84
 85   F32 collDamageThresholdVel;
 86   F32 collDamageMultiplier;
 87
 88   bool cameraRoll;           ///< Roll the 3rd party camera
 89   F32 cameraLag;             ///< Amount of camera lag (lag += car velocity * lag)
 90   F32 cameraDecay;           ///< Rate at which camera returns to target pos.
 91   F32 cameraOffset;          ///< Vertical offset
 92
 93   F32 minDrag;
 94   F32 maxDrag;
 95   S32 integration;           ///< # of physics steps per tick
 96   F32 collisionTol;          ///< Collision distance tolerance
 97   F32 contactTol;            ///< Contact velocity tolerance
 98   Point3F massCenter;        ///< Center of mass for rigid body
 99   Point3F massBox;           ///< Size of inertial box
100
101   F32 jetForce;
102   F32 jetEnergyDrain;        ///< Energy drain/tick
103   F32 minJetEnergy;
104
105   F32 steeringReturn;
106   F32 steeringReturnSpeedScale;
107   bool powerSteering;
108
109   ParticleEmitterData * dustEmitter;
110   S32 dustID;
111   F32 triggerDustHeight;  ///< height vehicle has to be under to kick up dust
112   F32 dustHeight;         ///< dust height above ground
113
114   ParticleEmitterData *   damageEmitterList[ VC_NUM_DAMAGE_EMITTERS ];
115   Point3F damageEmitterOffset[ VC_NUM_DAMAGE_EMITTER_AREAS ];
116   S32 damageEmitterIDList[ VC_NUM_DAMAGE_EMITTERS ];
117   F32 damageLevelTolerance[ VC_NUM_DAMAGE_LEVELS ];
118   F32 numDmgEmitterAreas;
119
120   ParticleEmitterData* splashEmitterList[VC_NUM_SPLASH_EMITTERS];
121   S32 splashEmitterIDList[VC_NUM_SPLASH_EMITTERS];
122   F32 splashFreqMod;
123   F32 splashVelEpsilon;
124
125   bool enablePhysicsRep;
126
127   //
128   VehicleData();
129   bool preload(bool server, String &errorStr);
130   static void initPersistFields();
131   virtual void packData(BitStream* stream);
132   virtual void unpackData(BitStream* stream);
133
134   DECLARE_CONOBJECT(VehicleData);
135};
136
137
138//----------------------------------------------------------------------------
139class PhysicsBody;
140
141class Vehicle : public RigidShape
142{
143   typedef RigidShape Parent;
144
145  protected:
146
147   VehicleData* mDataBlock;
148   SFXSource* mWakeSound;
149
150   // Control
151   Point2F mSteering;
152   F32 mThrottle;
153   bool mJetting;
154
155   GFXStateBlockRef  mSolidSB;
156
157   SimObjectPtr<ParticleEmitter> mDamageEmitterList[VehicleData::VC_NUM_DAMAGE_EMITTERS];
158
159   //
160   virtual bool onNewDataBlock( GameBaseData *dptr, bool reload );
161   void updatePos(F32 dt);
162   static void findCallback(SceneObject* obj,void * key);
163
164//   virtual bool collideBody(const MatrixF& mat,Collision* info) = 0;
165   virtual void updateMove(const Move* move);
166   virtual void updateForces(F32 dt);
167
168   void writePacketData(GameConnection * conn, BitStream *stream);
169   void readPacketData (GameConnection * conn, BitStream *stream);
170   U32  packUpdate  (NetConnection *conn, U32 mask, BitStream *stream);
171   void unpackUpdate(NetConnection *conn,           BitStream *stream);
172
173   void updateLiftoffDust( F32 dt );
174   void updateDamageSmoke( F32 dt );
175
176   virtual U32 getCollisionMask();
177
178   void updateFroth( F32 dt );
179
180   /// ObjectRenderInst delegate hooked up in prepBatchRender 
181   /// if GameBase::gShowBoundingBox is true.
182   void _renderMassAndContacts( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
183
184   /// ObjectRenderInst delegate hooked up in prepBatchRender 
185   /// if GameBase::gShowBoundingBox is true.
186   void _renderMuzzleVector( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
187
188public:
189   // Test code...
190   static ClippedPolyList* sPolyList;
191   static S32 sVehicleCount;
192
193   //
194   Vehicle();
195   static void consoleInit();
196   static void initPersistFields();
197   void processTick(const Move *move);
198   bool onAdd();
199   void onRemove();
200
201   /// Interpolates between move ticks @see processTick
202   /// @param   dt   Change in time between the last call and this call to the function
203   void advanceTime(F32 dt);
204
205   void prepBatchRender( SceneRenderState *state, S32 mountedImageIndex );
206
207   ///@name Rigid body methods
208   ///@{
209
210   void getCameraParameters(F32 *min, F32* max, Point3F* offset, MatrixF* rot);
211   void getCameraTransform(F32* pos, MatrixF* mat);
212   ///@}
213
214   /// @name Mounted objects
215   /// @{
216   virtual void mountObject( SceneObject *obj, S32 node, const MatrixF &xfm = MatrixF::Identity );
217   /// @}
218
219   DECLARE_CONOBJECT(Vehicle);
220};
221
222
223#endif
224