1 #pragma once 2 #include <OgreCommon.h> 3 #include <OgreVector2.h> 4 #include <OgreVector3.h> 5 #include <OgreVector4.h> 6 #include <OgreColourValue.h> 7 #include <OgreQuaternion.h> 8 #include "../../../vdrift/mathvector.h" 9 #include "../../../vdrift/quaternion.h" 10 11 namespace Ogre { class SceneNode; class Entity; } 12 namespace Forests { class GrassLayer; } 13 14 15 // custom Color . . . . . . . 16 class SColor 17 { 18 public: 19 // hue,sat 0..1 a = anything 20 // val 0..a over 1 are additive, eg. bright desert 21 // alpha 0..a over 1 are additive, for light fog 22 // neg 0..a gives negative offset, for darkening, antilight 23 float h, s, v, a, n; 24 25 // load from old and convert, ver < 2.4 26 void LoadRGB(Ogre::Vector3 rgb); // can be -a..a 27 28 // get rgba value for shaders 29 Ogre::Vector3 GetRGB() const; 30 Ogre::Vector3 GetRGB1() const; // limited to 0..1 for image 31 Ogre::Vector4 GetRGBA() const; 32 Ogre::ColourValue GetClr() const; 33 34 // from string, old r g b, r g b a, or h s v a n 35 void Load(const char* s); 36 std::string Save() const; 37 std::string Check(std::string t); 38 39 SColor(); 40 SColor(float h, float s, float v, float a=1.f, float n=0.f); 41 }; 42 43 44 struct TerLayer // terrain texture layer 45 { 46 bool on, triplanar; // for highest slopes 47 float tiling; // scale, texture repeat 48 Ogre::String texFile, texNorm; // textures _d, _n 49 50 float dust, mud, dustS, smoke; // particles intensities, S size 51 SColor tclr; Ogre::Vector4 tcl; // trail color, rgba copy 52 53 /// blendmap 54 // min,max range and smooth range for terrain angle and height 55 float angMin,angMax,angSm, hMin,hMax,hSm; 56 bool nOnly; // ignores above range 57 // noise 58 float noise, nprev, nnext2; // factors to blend layer +1,-1,+2 59 float nFreq[2], nPers[2], nPow[2]; int nOct[2]; 60 float fDamage; // car damage per sec 61 62 // surface params bind 63 std::string surfName; int surfId; 64 TerLayer(); 65 }; 66 67 68 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 class TerData /// Terrain 70 { 71 public: 72 // height field 73 float* hfHeight; 74 75 // size 76 int iVertsX, iVertsY, iTerSize; // size in vertices 77 float fTriangleSize, fTerWorldSize; // scale size 78 float errorNorm; // terrain error % at default quality 79 void UpdVals(); 80 81 // layers 82 const static int ciNumLay = 6; // all, for edit 83 TerLayer layersAll[ciNumLay]; 84 std::vector<int> layers; // active only (on) 85 86 bool road1mtr; // if true (default) road has only 1 surface type 87 TerLayer layerRoad[4]; // pipe[4] //todo... 88 void UpdLayers(); 89 90 // which should have triplanar most (eg high mountains) 91 int triplanarLayer1, triplanarLayer2, triplCnt; 92 float normScale; // scale terrain normals 93 94 bool emissive; // emissive light from specular 95 float specularPow, specularPowEm; // specular power (exponent) 96 97 // methods 98 TerData(); void Default(); 99 float getHeight(const float& fi, const float& fj); 100 }; 101 102 103 class PagedLayer // vegetation model 104 { 105 public: 106 bool on; 107 Ogre::String name; float dens; 108 float windFx, windFy; 109 int addRdist, maxRdist; // add,max dist to road 110 float minScale, maxScale, ofsY; 111 float maxTerAng, minTerH, maxTerH; // terrain 112 float maxDepth; // in fluid 113 int cnt; // count on track, for stats 114 PagedLayer(); 115 }; 116 117 118 class SGrassLayer // grass layer 119 { 120 public: 121 bool on; 122 float dens; 123 float minSx,minSy, maxSx,maxSy; // sizes 124 float swayDistr, swayLen, swaySpeed; // sway 125 int iChan; // which channel to use 126 Ogre::String material, colorMap; 127 Forests::GrassLayer *grl; // for update 128 SGrassLayer(); 129 }; 130 131 class SGrassChannel // grass channel 132 { 133 public: 134 // min,max range and smooth range for terrain angle and height 135 float angMin,angMax,angSm, hMin,hMax,hSm; 136 float noise, nFreq, nPers, nPow; int nOct; // noise params 137 float rdPow; // road border adjust 138 SGrassChannel(); 139 }; 140 141 142 // Presets 143 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 145 ///---- Sky 146 struct PSky 147 { 148 Ogre::String mtr, clr; 149 float ldYaw, ldPitch; // sun dir 150 PSky(); 151 }; 152 153 ///---- Terrain layer 154 struct PTer 155 { 156 Ogre::String texFile, texNorm, sc; 157 std::string surfName, scn; 158 float tiling; bool triplanar; 159 160 float dust, mud, dustS; 161 SColor tclr; // trail 162 163 float angMin,angMax; 164 float dmg; 165 PTer(); 166 }; 167 168 ///---- Road 169 struct PRoad 170 { 171 Ogre::String mtr, sc; 172 std::string surfName, scn; 173 174 float dust, mud, dustS; 175 SColor tclr; 176 PRoad(); 177 }; 178 179 ///---- Grass 180 struct PGrass 181 { 182 Ogre::String mtr, clr, sc; // material, colormap 183 std::string scn; 184 float minSx,minSy, maxSx,maxSy; // sizes 185 PGrass(); 186 }; 187 188 ///---- Veget model 189 struct PVeget 190 { 191 Ogre::String sc; 192 std::string name, scn; 193 float minScale, maxScale; 194 float windFx, windFy; 195 196 int addRdist; // road dist 197 float maxTerAng; // terrain 198 float maxDepth; // in fluid 199 PVeget(); 200 }; 201 202 /// Presets xml with common params setup 203 class Presets 204 { 205 public: 206 std::vector<PSky> sky; 207 std::map<std::string, int> isky; 208 const PSky* GetSky(std::string mtr); 209 210 std::vector<PTer> ter; 211 std::map<std::string, int> iter; 212 const PTer* GetTer(std::string tex); 213 214 std::vector<PRoad> rd; 215 std::map<std::string, int> ird; 216 const PRoad* GetRoad(std::string mtr); 217 218 std::vector<PGrass> gr; 219 std::map<std::string, int> igr; 220 const PGrass* GetGrass(std::string mtr); 221 222 std::vector<PVeget> veg; 223 std::map<std::string, int> iveg; 224 const PVeget* GetVeget(std::string mesh); 225 226 bool LoadXml(std::string file); 227 }; 228 229 230 class FluidBox /// fluid box shape - water, mud, etc. 231 { 232 public: 233 Ogre::Vector3 pos, rot, size; 234 Ogre::Vector2 tile; 235 236 int id; // auto set, index to FluidParams, -1 doesnt exist 237 std::string name; 238 239 class btCollisionObject* cobj; 240 int idParticles; // auto set index for wheel particles -1 none 241 bool solid, deep; // auto set, from FluidParams 242 243 FluidBox(); 244 }; 245 246 247 class Object // object - mesh (static) or prop (dynamic) 248 { 249 public: 250 MATHVECTOR<float,3> pos; 251 QUATERNION<float> rot; 252 Ogre::Vector3 scale; 253 std::string name; // mesh file name 254 255 Ogre::SceneNode* nd; // ogre 256 Ogre::Entity* ent; 257 class btDefaultMotionState* ms; // bullet 258 class btCollisionObject* co; 259 class btRigidBody* rb; 260 bool dyn; 261 class btTransform* tr1; // 1st pos after load, for reset 262 263 Object(); 264 void SetFromBlt(); 265 }; 266 267 268 /// Scene setup xml 269 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 class Scene 271 { 272 public: 273 // car start pos 274 MATHVECTOR <float,3> startPos; 275 QUATERNION <float> startRot; 276 std::pair <MATHVECTOR<float,3>, QUATERNION<float> > GetStart(int index); 277 278 // sky 279 Ogre::String skyMtr; float skyYaw; 280 int rainEmit,rain2Emit; Ogre::String rainName,rain2Name; 281 // light 282 float ldPitch, ldYaw; // sun dir angles 283 SColor lAmb,lDiff,lSpec; 284 285 // fog 286 float fogStart, fogEnd; // lin range 287 SColor fogClr,fogClr2; // 2colors sun-away .a = intensity 288 289 SColor fogClrH; // height fog color 290 float fogHeight, fogHDensity, fogHStart, fogHEnd; 291 float fHDamage; // damage from low height fog 292 293 294 // game 295 bool asphalt; // use asphalt tires car 296 bool denyReversed; // track (road) dir 297 bool noWrongChks; // dont show "wrong checkpoint" messages 298 299 float windAmt; //, windDirYaw, windTurbulFreq,windTurbulAmp; 300 float damageMul; // reduce car damage in loops 301 float gravity; // 9.81 302 303 // sound 304 std::string sAmbient, sReverbs; void UpdRevSet(); 305 struct RevSet // copy from ReverbSet, name = sReverbs, from base if "" 306 { std::string descr, 307 normal, cave, cavebig, pipe, pipebig, influid; 308 } revSet; 309 class ReverbsXml* pReverbsXml; //! set this after Load 310 311 312 // particle types 313 Ogre::String sParDust, sParMud, sParSmoke; 314 315 // Terrain 316 bool ter; // has terrain 317 bool vdr; // vdrift track 318 TerData td; 319 320 321 // Vegetation params 322 float densTrees, densGrass; int grDensSmooth; 323 float grPage, grDist; 324 float trPage, trDist, trDistImp; 325 int trRdDist; // dist from road to trees 326 327 // grass layers 328 const static int ciNumGrLay = 6; // all, for edit 329 SGrassLayer grLayersAll[ciNumGrLay]; 330 SGrassChannel grChan[4]; 331 332 // paged layers (models: trees,rocks,etc) 333 const static int ciNumPgLay = 10; // all, for edit 334 PagedLayer pgLayersAll[ciNumPgLay]; 335 std::vector<int> pgLayers; // active only (on) 336 void UpdPgLayers(); 337 338 339 // preview cam 340 Ogre::Vector3 camPos,camDir; 341 342 // Fluids 343 std::vector<FluidBox> fluids; 344 class FluidsXml* pFluidsXml; //! set this after Load 345 346 // Objects 347 std::vector<Object> objects; 348 349 // base track (new from) for info 350 std::string baseTrk; 351 int secEdited; // time in seconds of track editing for info 352 353 354 // methods 355 Scene(); void Default(); 356 void UpdateFluidsId(), UpdateSurfId(); 357 358 class GAME* pGame; // for all surfaces by name 359 bool LoadStartPos(Ogre::String file); 360 bool LoadXml(Ogre::String file, bool bTer = true), SaveXml(Ogre::String file); 361 }; 362