1 #pragma once
2 #include "PreviewTex.h"
3 #include <OgreVector3.h>
4 #include <OgreVector4.h>
5 #include <OgreString.h>
6 #include <OgreTexture.h>
7 #include <OgreShadowCameraSetup.h>
8 
9 namespace Forests {  class PagedGeometry;  }
10 namespace Ogre  {  class Terrain;  class TerrainGlobalOptions;  class TerrainGroup;  class StaticGeometry;
11 	class Light;  class SceneNode;  class Camera;  class Texture;  class SceneManager;  class Entity;
12 	class Rectangle2D;  class RenderTexture;  class Viewport;  class Root;  class ParticleSystem; }
13 class App;  class Scene;  class WaterRTT;  class CData;  class SplineRoad;  class PaceNotes;
14 
15 
16 class CScene
17 {
18 public:
19 	App* app;
20 	CScene(App* app1);
21 	~CScene();
22 
23 	void destroyScene();
24 
25 
26 	//  Shadows
27 	void changeShadows(), UpdShaderParams(), UpdPaceParams(), UpdPSSMMaterials();
28 	Ogre::Vector4 splitPoints;
29 	Ogre::ShadowCameraSetupPtr mPSSMSetup;
30 
31 
32 	///  Setup  scene.xml
33 	Scene* sc;
34 
35 	//  const, xmls
36 	CData* data;
37 
38 
39 	//  Sun
40 	Ogre::Light* sun;
41 	void UpdFog(bool bForce=false), UpdSun(), UpdSky();
42 	void CreateSkyDome(Ogre::String sMater, Ogre::Vector3 scale, float yaw);
43 
44 	//  Weather  rain, snow
45 	Ogre::ParticleSystem *pr,*pr2;
46 	void CreateWeather(), DestroyWeather();
47 	void UpdateWeather(Ogre::Camera* cam, float mul = 1.f);
48 
49 
50 	//  Fluids  water, mud
51 	std::vector<Ogre::String/*MeshPtr*/> vFlSMesh;
52 	std::vector<Ogre::Entity*> vFlEnt;
53 	std::vector<Ogre::SceneNode*> vFlNd;
54 	void CreateFluids(), DestroyFluids(), CreateBltFluids();
55 
56 	WaterRTT* mWaterRTT;
57 	void UpdateWaterRTT(Ogre::Camera* cam);
58 
59 
60 	//  Road
61 	SplineRoad* road;
62 	PaceNotes* pace;
63 	void DestroyRoad(), DestroyPace();
64 
65 	//  vdrift track
66 	Ogre::StaticGeometry* vdrTrack;
67 
68 
69 	//  Vegetation
70 	Forests::PagedGeometry *trees, *grass;
71 	void CreateTrees(), DestroyTrees(), RecreateTrees(), updGrsTer(), UpdCamera();
72 
73 
74 	///  Terrain
75 	//-----------------------------------
76 	PreviewTex texLayD[6],texLayN[6];  // layers
77 	void CreateTerrain(bool bNewHmap=false, bool bTer=true, bool terLoad=true);
78 	void DestroyTerrain(), CreateBltTerrain(), copyTerHmap();
79 
80 	Ogre::Terrain* terrain;
81 	Ogre::TerrainGlobalOptions* mTerrainGlobals;
82 	Ogre::TerrainGroup* mTerrainGroup;
83 	void SetupTerrain(), UpdTerErr();
84 
85 	Ogre::Terrain* horizon;
86 	Ogre::TerrainGlobalOptions* mHorizonGlobals;
87 	Ogre::TerrainGroup* mHorizonGroup;
88 	void SetupHorizon();
89 
90 
91 	//  Blendmap, rtt
92 	//-----------------------------------
93 	void CreateBlendTex(), UpdBlendmap(), UpdLayerPars();
94 	void UpdGrassDens(), UpdGrassPars();
95 
96 	//  tex, mtr names
97 	const static Ogre::String sHmap, sAng,sAngMat,
98 		sBlend,sBlendMat, sGrassDens,sGrassDensMat;
99 
100 	Ogre::TexturePtr heightTex, angleRTex, blendRTex;  // height, angles, blend
101 	Ogre::TexturePtr grassDensRTex;  // grass density and channels
102 	PreviewTex roadDens;
103 
104 	struct RenderToTex  // rtt common
105 	{
106 		Ogre::RenderTexture* rnd;  Ogre::Texture* tex;
107 		Ogre::SceneManager* scm;  Ogre::Camera* cam;  Ogre::Viewport* vp;
108 		Ogre::Rectangle2D* rect;  Ogre::SceneNode* nd;
109 
NullRenderToTex110 		void Null()
111 		{	rnd = 0;  tex = 0;  scm = 0;  cam = 0;  vp = 0;  rect = 0;  nd = 0;   }
RenderToTexRenderToTex112 		RenderToTex()
113 		{	Null();   }
114 
115 		void Setup(Ogre::Root* rt, Ogre::String sName, Ogre::TexturePtr pTex, Ogre::String sMtr);
116 	};
117 	RenderToTex blendRTT, angleRTT, grassDensRTT;
118 
119 
120 	//  noise  -------
121 	static float Noise(float x, float zoom, int octaves, float persistence);
122 	static float Noise(float x, float y, float zoom, int octaves, float persistance);
123 	//     xa  xb
124 	//1    .___.
125 	//0__./     \.___
126 	//   xa-s    xb+s    // val, min, max, smooth range
linRange(const float & x,const float & xa,const float & xb,const float & s)127 	inline static float linRange(const float& x, const float& xa, const float& xb, const float& s)
128 	{
129 		if (x <= xa-s || x >= xb+s)  return 0.f;
130 		if (x >= xa && x <= xb)  return 1.f;
131 		if (x < xa)  return (x-xa)/s+1;
132 		if (x > xb)  return (xb-x)/s+1;
133 		return 0.f;
134 	}
135 
136 };
137