1 #pragma once
2 #include <OgreVector2.h>
3 #include <OgreVector3.h>
4 #include <OgreQuaternion.h>
5 #include <OgreVector4.h>
6 #include <OgreMatrix4.h>
7 #include <OgreColourValue.h>
8 #include "../vdrift/mathvector.h"
9 #include "../vdrift/quaternion.h"
10 #include "../shiny/Main/MaterialInstance.hpp"
11 #include "../vdrift/cardefs.h"
12 #include "CarPosInfo.h"
13 
14 namespace Ogre {  class SceneNode;  class Terrain;  class Camera;  class SceneManager;
15 	class ParticleSystem;  class Entity;  class RibbonTrail;  class ManualObject;  class AxisAlignedBox;  }
16 namespace MyGUI {  class TextBox;  }
17 class SETTINGS;  class GAME;  class CAR;
18 class Scene;  class App;  class FollowCamera;  class CarReflection;
19 
20 
21 //  CarModel is the "Ogre" part of the car.
22 //  It is used to put meshes together, particle emitters, etc.
23 
24 class CarModel : public sh::MaterialInstanceListener
25 {
26 public:
27 	/// -------------------- Car Types ---------------------------
28 	//              Source          Physics (VDrift car)    Camera
29 	// CT_LOCAL:    Local player    yes	                    yes
30 	// CT_REMOTE:   Network	        yes	                    no
31 	// CT_REPLAY:   Replay file     no                      yes
32 	// CT_GHOST:	Ghost file		no						no
33 	// CT_GHOST2:	other car's ghost file
34 	// CT_TRACK:	track's ghost file
35 
36 	enum eCarType {  CT_LOCAL=0, CT_REMOTE, CT_REPLAY,  CT_GHOST, CT_GHOST2, CT_TRACK };
37 	eCarType eType;
isGhost()38 	bool isGhost()    const {  return eType >= CT_GHOST;  }
isGhostTrk()39 	bool isGhostTrk() const {  return eType == CT_TRACK;  }
40 
41 	VehicleType vtype;
42 
43 	int numWheels;
44 	void SetNumWheels(int n);
45 
46 	//  ctor
47 	CarModel(int index, int colorId, eCarType type, const std::string& name,
48 		Ogre::SceneManager* sceneMgr, SETTINGS* set, GAME* game, Scene* sc,
49 		Ogre::Camera* cam, App* app);
50 	~CarModel();
51 
52 	Ogre::String sDispName;  // diplay name in opponents list (nick for CT_REMOTE)
53 	MyGUI::TextBox* pNickTxt;  // multiplayer nick above car
54 	bool updTimes, updLap;  float fLapAlpha;
55 
56 
57 	///----  model params  from .car
58 	float driver_view[3], hood_view[3];  // mounted cameras
59 	float interiorOffset[3], boostOffset[3],boostSizeZ;
60 	float thrusterOfs[PAR_THRUST][3],thrusterSizeZ[PAR_THRUST];
61 
62 	std::vector<Ogre::Vector3> brakePos;  // flares
63 	float brakeSize;  Ogre::ColourValue brakeClr;
64 	std::string sBoostParName, sThrusterPar[PAR_THRUST];
65 	bool bRotFix;
66 
67 	std::vector<float> whRadius, whWidth;  // for tire trails
68 	std::vector<MATHVECTOR<float,3> > whPos;
69 	QUATERNION<float> qFixWh[2];
70 	float maxangle;  //steer
71 
72 	//  exhaust position for boost particles
73 	bool manualExhaustPos;  // if true, use values below, if false, guess from bounding box
74 	bool has2exhausts;  // car has 2nd exhaust, if true, mirror exhaust 1 for position
75 	float exhaustPos[3];  // position of first exhaust
76 
77 	void LoadConfig(const std::string & pathCar), Defaults();
78 
79 
80 	///--------  Create
81 	void Load(int startId=-1), Create(), CreateReflection(), Destroy();
82 	void CreatePart(Ogre::SceneNode* ndCar, Ogre::Vector3 vPofs,
83 		Ogre::String sCar2, Ogre::String sCarI, Ogre::String sMesh, Ogre::String sEnt,
84 		bool ghost, Ogre::uint32 visFlags,
85 		Ogre::AxisAlignedBox* bbox=0, Ogre::String stMtr="", bool bLogInfo=true);
86 
87 	void LogMeshInfo(const Ogre::Entity* ent, const Ogre::String& name, int mul=1);
88 	int all_subs, all_tris;  //stats
89 
90 	void RecreateMaterials();
91 	void setMtrNames(); // assign materials to entity / manualobject
92 	void setMtrName(const Ogre::String& entName, const Ogre::String& mtrName);
93 
94 
95 	//--------  Update
96 	void Update(PosInfo& posInfo, PosInfo& posInfoCam, float time);
97 	void UpdateKeys();  // for camera X,C, last chk F12
98 
99 
100 	//  reset camera after pos change etc
101 	void First();
102 	int iFirst;
103 
104 	//  color
105 	Ogre::ColourValue color;  // for minimap pos tri color  //float hue, sat, val;
106 	void ChangeClr();  //  Apply new color
107 
108 	//  track surface for wheels
109 	void UpdWhTerMtr();
110 	Ogre::String txtDbgSurf;
111 
112 	void UpdParsTrails(bool visible=true);
113 
114 
115 	///----  Camera, can be null
116 	FollowCamera* fCam;
117 	int iCamFluid;  // id to fluids[], -1 none
118 	float fCamFl;  // factor, close to surface
119 
120 	//  Main node
121 	Ogre::SceneNode* pMainNode, *ndSph;
122 	Ogre::Vector3 posSph[2];
123 	Ogre::BillboardSet* brakes;
124 
125 	void setVisible(bool visible);  // hide/show
126 	bool mbVisible;  float hideTime;
127 
128 	CarReflection* pReflect;
129 
130 	//  VDrift car
131 	CAR* pCar;  // all need this set (even ghost, has it from 1st car)
132 
133 
134 	///----  Logic vars
135 	float angCarY;  // car yaw angle for minimap
136 	float distFirst, distLast, distTotal;  // checks const distances set at start
137 	float trackPercent;  // % of track driven
138 	void UpdTrackPercent();
139 
140 	///  Checkpoint vars,  start pos, lap
141 	bool bGetStPos;  Ogre::Matrix4 matStPos;  Ogre::Vector4 vStDist;
142 	int iInChk, iCurChk, iNextChk, iNumChks,  // cur checkpoint -1 at start
143 		iInWrChk, iWonPlace, iWonPlaceOld;  float iWonMsgTime;
144 	bool bInSt, bWrongChk;  float fChkTime;
145 	float timeAtCurChk;
146 	//bool Checkpoint(const PosInfo& posInfo, class SplineRoad* road);  // update
147 	Ogre::Vector3 vStartPos;  void ResetChecks(bool bDist=false), UpdNextCheck(), ShowNextChk(bool visible);
148 	Ogre::String sChkMtr;  bool bChkUpd;
149 	//  for loop camera change
150 	int iLoopChk, iLoopLastCam;
151 
152 
153 	///--------  common
154 	GAME* pGame;
155 	Ogre::Camera* mCamera;
156 	Scene* sc;
157 	Ogre::SceneManager* mSceneMgr;
158 	SETTINGS* pSet;
159 	App* pApp;
160 
161 	int iIndex, iColor;  // car id, color id
162 	std::string sDirname;  // dir name of car (e.g. ES)
163 	Ogre::String resGrpId, mtrId;  // resource group name, material suffix
164 	std::string resCar;  // path to car textures
165 
166 
167 	//  Material names
168 	enum eMaterials {  Mtr_CarBody, Mtr_CarBrake,  NumMaterials  };
169 	std::string sMtr[NumMaterials];
170 
171 	//--------  Particle systems
172 	enum EParTypes {  PAR_Smoke=0, PAR_Mud, PAR_Dust, PAR_Water, PAR_MudHard, PAR_MudSoft, PAR_ALL };
173 	//  par-wheels, boost-car rear, spaceship thruster, sparks-world hit
174 	Ogre::ParticleSystem* par[PAR_ALL][MAX_WHEELS];
175 	Ogre::ParticleSystem* parBoost[PAR_BOOST], *parThrust[PAR_THRUST*2], *parHit;
176 	std::vector<Ogre::RibbonTrail*> whTrail;  // tire trail
177 	std::vector<Ogre::Real> whTemp;  // spin time, approx tire temp.
178 
179 	//  Wheels, Nodes
180 	std::vector<Ogre::SceneNode*> ndWh, ndWhE, ndBrake;
181 	Ogre::SceneNode* ndNextChk;
182 	Ogre::Entity* entNextChk;
183 
184 	//  to destroy
185 	std::vector<Ogre::SceneNode*> vDelNd;		void ToDel(Ogre::SceneNode* nd);
186 	std::vector<Ogre::Entity*> vDelEnt;			void ToDel(Ogre::Entity* ent);
187 	std::vector<Ogre::ParticleSystem*> vDelPar;	void ToDel(Ogre::ParticleSystem* par);
188 
189 
190 	//  brake state
191 	bool bBraking;
192 	void UpdateBraking();
193 
194 	//  lightmap toggle depending on distance to terrain
195 	Ogre::Terrain* terrain;
196 	bool bLightMapEnabled;
197 	void UpdateLightMap();
198 
199 	//  cam,chk old states
200 	int iCamNextOld;
201 	bool bLastChkOld;
202 
203 	virtual void requestedConfiguration (sh::MaterialInstance* m, const std::string& configuration);
204 	virtual void createdConfiguration (sh::MaterialInstance* m, const std::string& configuration);
205 };
206