/
car.h
368 lines (293 loc) · 7.36 KB
/
car.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#ifndef _CAR_H
#define _CAR_H
#include "cardynamics.h"
#include "tobullet.h"
#include "scenenode.h"
#include "soundsource.h"
#include "crashdetection.h"
#include "enginesoundinfo.h"
#include "joeserialize.h"
#include "macros.h"
class BEZIER;
class CAMERA;
class PERFORMANCE_TESTING;
class MODEL;
class ContentManager;
class PTree;
class CAR
{
friend class PERFORMANCE_TESTING;
friend class joeserialize::Serializer;
public:
CAR();
virtual ~CAR();
bool LoadGraphics(
const PTree & cfg,
const std::string & carpath,
const std::string & carname,
const std::string & partspath,
const MATHVECTOR <float, 3> & carcolor,
const std::string & carpaint,
const int anisotropy,
const float camerabounce,
const bool damage,
const bool debugmode,
ContentManager & content,
std::ostream & info_output,
std::ostream & error_output);
bool LoadSounds(
const std::string & carpath,
const std::string & carname,
ContentManager & content,
std::ostream & info_output,
std::ostream & error_output);
bool LoadPhysics(
const PTree & cfg,
const std::string & carpath,
const MATHVECTOR <float, 3> & position,
const QUATERNION <float> & orientation,
const bool defaultabs,
const bool defaulttcs,
const bool damage,
ContentManager & content,
DynamicsWorld & world,
std::ostream & info_output,
std::ostream & error_output);
// change car color
void SetColor(float r, float g, float b);
// will align car relative to track surface
void SetPosition(const MATHVECTOR <float, 3> & position);
void Update(double dt);
void GetSoundList(std::list <SOUNDSOURCE *> & outputlist);
void GetEngineSoundList(std::list <SOUNDSOURCE *> & outputlist);
// interpolated
const MATHVECTOR <float, 3> GetWheelPosition(const WHEEL_POSITION wpos) const
{
return ToMathVector<float>(dynamics.GetWheelPosition(wpos));
}
float GetTireRadius(const WHEEL_POSITION wpos) const
{
return dynamics.GetTire(wpos).GetRadius();
}
COLLISION_CONTACT & GetWheelContact(WHEEL_POSITION wheel_index)
{
return dynamics.GetWheelContact(wheel_index);
}
void HandleInputs(const std::vector <float> & inputs, float dt);
const std::vector<CAMERA*> & GetCameras() const
{
return cameras;
}
int GetEngineRedline() const
{
return dynamics.GetEngine().GetRedline();
}
int GetEngineRPMLimit() const
{
return dynamics.GetEngine().GetRPMLimit();
}
bool GetOutOfGas() const
{
return dynamics.GetOutOfGas();
}
float GetNosAmount() const
{
return dynamics.GetNosAmount();
}
bool GetNosActive() const
{
return nosactive;
}
int GetGear() const
{
return dynamics.GetTransmission().GetGear();
}
void SetGear(int gear)
{
dynamics.ShiftGear(gear);
}
float GetClutch()
{
return dynamics.GetClutch().GetClutch();
}
void SetAutoClutch(bool value)
{
dynamics.SetAutoClutch(value);
}
void SetAutoShift(bool value)
{
dynamics.SetAutoShift(value);
}
bool GetABSEnabled() const
{
return dynamics.GetABSEnabled();
}
bool GetABSActive() const
{
return dynamics.GetABSActive();
}
bool GetTCSEnabled() const
{
return dynamics.GetTCSEnabled();
}
bool GetTCSActive() const
{
return dynamics.GetTCSActive();
}
float GetSpeedMPS()
{
return dynamics.GetSpeedMPS();
}
float GetMaxSpeedMPS()
{
return dynamics.GetMaxSpeedMPS();
}
std::string GetCarType() const
{
return cartype;
}
void SetSector(int value)
{
sector = value;
}
int GetSector() const
{
return sector;
}
const BEZIER * GetCurPatch(WHEEL_POSITION wheel) const
{
return dynamics.GetWheelContact(wheel).GetPatch();
}
float GetLastSteer() const
{
return last_steer;
}
float GetSpeed()
{
return dynamics.GetSpeed();
}
MATHVECTOR <float, 3> GetTotalAero() const
{
return ToMathVector<float>(dynamics.GetTotalAero());
}
float GetFeedback();
// returns a float from 0.0 to 1.0 with the amount of tire squealing going on
float GetTireSquealAmount(WHEEL_POSITION i) const;
void EnableGlass(bool enable);
void DebugPrint(std::ostream & out, bool p1, bool p2, bool p3, bool p4) const
{
dynamics.DebugPrint(out, p1, p2, p3, p4);
}
bool Serialize(joeserialize::Serializer & s);
/// AI interface
int GetEngineRPM() const
{
return dynamics.GetTachoRPM();
}
int GetEngineStallRPM() const
{
return dynamics.GetEngine().GetStallRPM();
}
// interpoated position
MATHVECTOR <float, 3> GetCenterOfMassPosition() const
{
return ToMathVector<float>(dynamics.GetCenterOfMass());
}
// interpolated position
MATHVECTOR <float, 3> GetPosition() const
{
return ToMathVector<float>(dynamics.GetPosition());
}
// interpolated orientation
QUATERNION <float> GetOrientation() const
{
return ToMathQuaternion<float>(dynamics.GetOrientation());
}
float GetAerodynamicDownforceCoefficient() const
{
return dynamics.GetAerodynamicDownforceCoefficient();
}
float GetAeordynamicDragCoefficient() const
{
return dynamics.GetAeordynamicDragCoefficient();
}
float GetInvMass() const
{
return dynamics.GetInvMass();
}
MATHVECTOR <float, 3> GetVelocity() const
{
return ToMathVector<float>(dynamics.GetVelocity());
}
float GetTireMaxFx(WHEEL_POSITION tire_index) const
{
return dynamics.GetTire(tire_index).GetMaxFx(0.25*9.81/GetInvMass());
}
float GetTireMaxFy(WHEEL_POSITION tire_index) const
{
return dynamics.GetTire(tire_index).GetMaxFy(0.25*9.81/GetInvMass(), 0.0);
}
float GetTireMaxMz(WHEEL_POSITION tire_index) const
{
return dynamics.GetTire(tire_index).GetMaxMz(0.25*9.81/GetInvMass(), 0.0);
}
// optimum steering angle in degrees
float GetOptimumSteeringAngle() const
{
return dynamics.GetTire(FRONT_LEFT).GetIdealSlip();
}
// maximum steering angle in degrees
float GetMaxSteeringAngle() const
{
return dynamics.GetMaxSteeringAngle();
}
SCENENODE & GetNode() {return topnode;}
protected:
SCENENODE topnode;
CARDYNAMICS dynamics;
keyed_container<SCENENODE>::handle bodynode;
keyed_container<SCENENODE>::handle steernode;
keyed_container<DRAWABLE>::handle brakelights;
keyed_container<DRAWABLE>::handle reverselights;
struct LIGHT
{
keyed_container<SCENENODE>::handle node;
keyed_container<DRAWABLE>::handle draw;
};
std::list<LIGHT> lights;
std::list<std::tr1::shared_ptr<MODEL> > models;
CRASHDETECTION crashdetection;
std::vector<CAMERA*> cameras;
std::list<std::pair <ENGINESOUNDINFO, SOUNDSOURCE> > enginesounds;
SOUNDSOURCE tiresqueal[WHEEL_POSITION_SIZE];
SOUNDSOURCE tirebump[WHEEL_POSITION_SIZE];
SOUNDSOURCE grasssound[WHEEL_POSITION_SIZE];
SOUNDSOURCE gravelsound[WHEEL_POSITION_SIZE];
SOUNDSOURCE crashsound;
SOUNDSOURCE gearsound;
SOUNDSOURCE brakesound;
SOUNDSOURCE handbrakesound;
SOUNDSOURCE roadnoise;
int gearsound_check;
bool brakesound_check;
bool handbrakesound_check;
// steering wheel
QUATERNION<float> steer_orientation;
QUATERNION<float> steer_rotation;
float steer_angle_max;
//internal variables that might change during driving (so, they need to be serialized)
float last_steer;
bool nosactive;
std::string cartype;
int sector; //the last lap timing sector that the car hit
const BEZIER * curpatch[WHEEL_POSITION_SIZE]; //the last bezier patch that each wheel hit
float applied_brakes; ///< cached so we can update the brake light
float mz_nominalmax; //the nominal maximum Mz force, used to scale force feedback
void UpdateSounds(float dt);
void UpdateGraphics();
bool LoadLight(
const PTree & cfg,
ContentManager & content,
std::ostream & error_output);
};
#endif