00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00016 #ifndef VEHICLE_H
00017 #define VEHICLE_H
00018
00019 #include <deque>
00020 #include <adsoheightmap.h>
00021 #include <adsomodel.h>
00022 #include "rigidbody.h"
00023 #include "sound.h"
00024 #include "photon.h"
00025 #include "animation.h"
00026 #include "userinput.h"
00027
00028 using namespace std;
00029
00030 #define SOUND_BUMP_NUM 3
00031 #define SOUND_CRASH_NUM 5
00032 #define SOUND_SHOOT_NUM 3
00033 #define SOUND_HIT_NUM 3
00034
00035 struct VehicleStatsTyre {
00036 int contact;
00037 v3f slope, pos;
00038 v3f dn, dr, dd;
00039 v3f vp;
00040 float j_n, j_d, j_r;
00041 };
00042
00043 struct VehicleStats {
00044 VehicleStatsTyre tyre[3];
00045 };
00046
00047 #define FRAMEPOINT_TYRE 1
00048 #define FRAMEPOINT_DRIVE 2
00049 #define FRAMEPOINT_ROTATE 4
00050 #define FRAMEPOINT_BASE 8
00051
00052 class FramePoint {
00053 public:
00054 v3f point;
00055 int type;
00056 v3f dir;
00057
00058 FramePoint(){ type = 0; }
00059 };
00060
00061
00062 class VehicleControl {
00063 protected:
00064 class Vehicle *vehicle;
00065 public:
00066
00067 int turn_left;
00068 int turn_right;
00069 int accelerate;
00070 int brake;
00071 int shoot;
00072 int turbo;
00073
00074 v3f cannonTarget;
00075
00076 virtual void reset(){
00077 turn_left = 0;
00078 turn_right = 0;
00079 accelerate = 0;
00080 brake = 0;
00081 shoot = 0;
00082 turbo = 0;
00083
00084 cannonTarget = v3f(1.0f,0.0f,0.0f);
00085 }
00086
00087 VehicleControl(){ reset(); }
00088 virtual ~VehicleControl(){}
00089 friend class Vehicle;
00090 };
00091
00092 struct VehicleUserCtrl : public VehicleControl, public TimedAnimation, public KeyboardHandler {
00093 void update(double);
00094 bool onKeyEvent(SDLKey key);
00095
00096 VehicleUserCtrl(){
00097 reset();
00098 animationServer.addAnimation(this);
00099 }
00100 };
00101
00102 class Vehicle : public RigidBody, public PhysicalAnimation {
00103 SoundWave soundEngine;
00104 SoundWave soundTyre;
00105 SoundWave soundExplode;
00106 SoundWave soundBump[SOUND_BUMP_NUM];
00107 SoundWave soundCrash[SOUND_CRASH_NUM];
00108 SoundWave soundShoot[SOUND_SHOOT_NUM];
00109 SoundWave soundHit[SOUND_HIT_NUM];
00110 int soundShootIndex, soundHitIndex;
00111
00112 VehicleControl *ctrl;
00113
00114 public:
00115 AdsoHierModel *model;
00116 int tyre_contact;
00117 int tyre_drive_touch;
00118 int tyre_touch;
00119
00120
00121 float weight;
00122 float engine;
00123 float width;
00124 float length;
00125
00126 int nFramePoints;
00127 FramePoint *framePoints;
00128 v3f frameBox[8];
00129 static const int frameBoxFaces[6][4];
00130 v3f massCenter;
00131
00132 v3f cannonPos;
00133 float cannonTemp;
00134
00135
00136 float speed;
00137 float wheel;
00138 float engineSpeed;
00139 float tyreVelocity;
00140 int iBumpSound;
00141 int iCrashSound;
00142 float photonTimer;
00143 deque<struct PhotonDef> scheduledPhotons;
00144
00145 float cannonBearing;
00146 float cannonTilt;
00147
00148
00149 AdsoHeightMap *heightMap;
00150 float gravity;
00151 Vehicle *opponent;
00152 int soundEnabled;
00153
00154 int netLinkControlled;
00155
00156 VehicleStats *stats;
00157
00158 void surfaceAdjust();
00159 void update(double deltaTime);
00160 void rbModelUpdate(float delta_time);
00161 void simpleModelUpdate(float delta_time);
00162 void setPos(v3f p, v3f d);
00163 void setOpponent(Vehicle *o){ opponent = o; }
00164 void enableSound(){ soundEnabled = 1; }
00165 void initSound();
00166 void setAudioPos(v3f ap);
00167 void photonHit(float);
00168 void explode();
00169 void schedulePhoton(PhotonDef &pd){ scheduledPhotons.push_back(pd); }
00170 v3f getVelocity(){ return vel; }
00171 bool isImmobile(){ return tyre_drive_touch==0 && L.length()<1e-2 && P.length()<1e-2; }
00172 void draw(DrawHint);
00173 void setControl(VehicleControl *vc){
00174 ctrl = vc;
00175 vc->vehicle = this;
00176 }
00177 Vehicle(AdsoHeightMap *hm);
00178 friend class ScreenDump;
00179 };
00180
00181 extern VehicleUserCtrl vehicleUserCtrl;
00182
00183 #endif
00184