1 /***************************************************************************
2                           car.h  -  A car, being a moving object
3                              -------------------
4     begin                : Wed Dec 4 2002
5     copyright            : (C) 2002 by CJP
6     email                : cornware-cjp@users.sourceforge.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef CAR_H
19 #define CAR_H
20 
21 #include "movingobject.h"
22 
23 #include "carengine.h"
24 #include "carwheel.h"
25 #include "carrulestatus.h"
26 
27 /**
28   *@author CJP
29   */
30 
31 struct SCarDashboardInfo
32 {
33 	CString background_tex;
34 	float background_hth;
35 
36 	CString crash_background_tex;
37 	CString crash_tex;
38 
39 	CString steer_tex;
40 	CVector steer_pos;
41 	float steer_rad;
42 	float steer_ang;
43 
44 	CString analog_vel_tex;
45 	CVector analog_vel_pos;
46 	float analog_vel_rad;
47 	float analog_vel_an0;
48 	float analog_vel_an1;
49 	float analog_vel_max;
50 
51 	CString analog_rpm_tex;
52 	CVector analog_rpm_pos;
53 	float analog_rpm_rad;
54 	float analog_rpm_an0;
55 	float analog_rpm_an1;
56 	float analog_rpm_max;
57 
58 	CVector digital_vel_pos;
59 	float digital_vel_hth;
60 	float digital_vel_wth;
61 
62 	CVector digital_rpm_pos;
63 	float digital_rpm_hth;
64 	float digital_rpm_wth;
65 
66 	CVector songtitle_pos;
67 	float songtitle_hth;
68 	float songtitle_wth;
69 };
70 
71 class CCar : public CMovingObject  {
72 public:
73 	CCar(CDataManager *manager);
74 	virtual ~CCar();
75 
76 	virtual bool load(const CString &filename, const CParamList &list);
77 	virtual void unload();
78 
79 	virtual void resetBodyPositions();
80 
81 	virtual CBinBuffer &getData(CBinBuffer &b) const;            //override for car-specific data
82 	virtual bool setData(const CBinBuffer &b, unsigned int &pos);//override for car-specific data
getType()83 	virtual CMessageBuffer::eMessageType getType() const {return CMessageBuffer::car;}
84 
85 	virtual void update(CPhysics *simulator, float dt);
86 	virtual void correctCollisions();
87 
88 	CString m_CarName; //is loaded from car file
89 	float m_EngineSoundBaseRPS; //base engine rad/s of the engine sound
90 
91 	//sub objects:
92 	CCarEngine m_Engine;
93 	CCarWheel m_Wheel[4];
94 
95 	SCarDashboardInfo m_Dashboard;
96 
97 
98 	//State variables:
99 	float m_DesiredSteering;
100 	enum {eRiding, eFlying} m_SimState;
101 	CCarRuleStatus m_RuleStatus;
102 
103 protected:
104 	//car specific physics
105 	void simulateGeneral(CPhysics *simulator, float dt);
106 	void simulateAir(CPhysics *simulator, float dt);
107 	void simulateGround(CPhysics *simulator, float dt);
108 
109 	void updateWheelOrientation();
110 	void updateWheelTorques();             //engine + brakes
111 	void calculateNormalForces();          //vertical force through wheels
112 	void applyWheelForces();               //tyre surface
113 
114 	void addDownforce();         //aerodynamic downforce
115 	void doSteering(float dt);
116 
117 	virtual void determineGroundPlane(CPhysics *simulator);
118 	void placeOnGround();
119 	void landOnGround();
120 	void fixFlyingOrientation();
121 
122 	virtual void placeBodies();
123 
124 	//car specific settings:
125 	float m_SteerSpeedOut, m_SteerSpeedIn;
126 	float m_SteerSpeed_v_factor;
127 
128 	//body
129 	CVector m_BodySize;
130 	float m_cwA, m_RotationDamping;
131 	float m_PositionAboveGround;
132 	CVector m_CenterOfMass; //relative to body model
133 
134 	//wheels
135 	float m_FrontSteerMax, m_RearSteerMax;
136 	float m_FrontDownforce, m_RearDownforce;
137 };
138 
139 #endif
140