My Project
SkyMesh.h
1 #pragma once
2 #include "TileObject.h"
3 
4 namespace ParaEngine
5 {
6  struct AssetEntity;
7  class CMeshObject;
13  class CSkyMesh : public CTileObject
14  {
15 
16  public:
17  CSkyMesh(void);
18  virtual ~CSkyMesh(void);
19  virtual CBaseObject::_SceneObjectType GetType(){ return CBaseObject::SkyMesh; };
20 
21  enum SkyType
22  {
27  };
28 
29  public:
31  virtual int GetAttributeClassID(){ return ATTRIBUTE_CLASSID_CSkyMesh; }
33  virtual const char* GetAttributeClassName(){ static const char name[] = "CSkyMesh"; return name; }
35  virtual const char* GetAttributeClassDescription(){ static const char desc[] = ""; return desc; }
37  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
38 
39  ATTRIBUTE_SUPPORT_CREATE_FACTORY(CSkyMesh);
40  ATTRIBUTE_METHOD1(CSkyMesh, GetSkyColorFactor_s, Vector3*) { (*p1).x = cls->GetSkyColorFactor().r; (*p1).y = cls->GetSkyColorFactor().g; (*p1).z = cls->GetSkyColorFactor().b; return S_OK; }
41  ATTRIBUTE_METHOD1(CSkyMesh, SetSkyColorFactor_s, Vector3) { LinearColor c(p1.x, p1.y, p1.z, 1); cls->SetSkyColorFactor(c); return S_OK; }
42  ATTRIBUTE_METHOD1(CSkyMesh, GetSkyMeshFile_s, const char**) { *p1 = cls->GetSkyMeshFile(); return S_OK; }
43  ATTRIBUTE_METHOD1(CSkyMesh, SetSkyMeshFile_s, const char*) { cls->SetSkyMeshFile(p1); return S_OK; }
44  ATTRIBUTE_METHOD1(CSkyMesh, GetSkyMeshTexture_s, const char**) { *p1 = cls->GetSkyMeshTexture(); return S_OK; }
45  ATTRIBUTE_METHOD1(CSkyMesh, SetSkyMeshTexture_s, const char*) { cls->SetSkyMeshTexture(p1); return S_OK; }
46 
47  ATTRIBUTE_METHOD1(CSkyMesh, GetFogBlendAngleFrom_s, float*) { *p1 = cls->GetFogBlendAngleFrom(); return S_OK; }
48  ATTRIBUTE_METHOD1(CSkyMesh, SetFogBlendAngleFrom_s, float) { cls->SetFogBlendAngleFrom(p1); return S_OK; }
49  ATTRIBUTE_METHOD1(CSkyMesh, GetFogBlendAngleTo_s, float*) { *p1 = cls->GetFogBlendAngleTo(); return S_OK; }
50  ATTRIBUTE_METHOD1(CSkyMesh, SetFogBlendAngleTo_s, float) { cls->SetFogBlendAngleTo(p1); return S_OK; }
51 
52  ATTRIBUTE_METHOD1(CSkyMesh, IsSimulatedSkyEnabled_s, bool*) { *p1 = cls->IsSimulatedSkyEnabled(); return S_OK; }
53  ATTRIBUTE_METHOD1(CSkyMesh, EnableSimulatedSky_s, bool) { cls->EnableSimulatedSky(p1); return S_OK; }
54 
55  ATTRIBUTE_METHOD1(CSkyMesh, GetIsAutoDayTime_s, bool*) { *p1 = cls->GetIsAutoDayTime(); return S_OK; }
56  ATTRIBUTE_METHOD1(CSkyMesh, SetIsAutoDayTime_s, bool) { cls->SetIsAutoDayTime(p1); return S_OK; }
57 
58  ATTRIBUTE_METHOD1(CSkyMesh, GetSunGlowTexture_s, const char**) { *p1 = cls->GetSunGlowTexture(); return S_OK; }
59  ATTRIBUTE_METHOD1(CSkyMesh, SetSunGlowTexture_s, const char*) { cls->SetSunGlowTexture(p1); return S_OK; }
60 
61  ATTRIBUTE_METHOD1(CSkyMesh, GetCloudTexture_s, const char**) { *p1 = cls->GetCloudTexture(); return S_OK; }
62  ATTRIBUTE_METHOD1(CSkyMesh, SetCloudTexture_s, const char*) { cls->SetCloudTexture(p1); return S_OK; }
63 
64  ATTRIBUTE_METHOD1(CSkyMesh, GetSunColor_s, Vector3*) { (*p1) = cls->GetSunColor(); return S_OK; }
65  ATTRIBUTE_METHOD1(CSkyMesh, SetSunColor_s, Vector3) { cls->SetSunColor(p1); return S_OK; }
66 
67  ATTRIBUTE_METHOD1(CSkyMesh, GetLightSkyColor_s, Vector3*) { (*p1) = cls->GetLightSkyColor(); return S_OK; }
68  ATTRIBUTE_METHOD1(CSkyMesh, SetLightSkyColor_s, Vector3) { cls->SetLightSkyColor(p1); return S_OK; }
69 
70  ATTRIBUTE_METHOD1(CSkyMesh, GetDarkSkyColor_s, Vector3*) { (*p1) = cls->GetDarkSkyColor(); return S_OK; }
71  ATTRIBUTE_METHOD1(CSkyMesh, SetDarkSkyColor_s, Vector3) { cls->SetDarkSkyColor(p1); return S_OK; }
72 
73  ATTRIBUTE_METHOD1(CSkyMesh, GetSunIntensity_s, Vector2*) { (*p1) = cls->GetSunIntensity(); return S_OK; }
74  ATTRIBUTE_METHOD1(CSkyMesh, SetSunIntensity_s, Vector2) { cls->SetSunIntensity(p1); return S_OK; }
75 
76  ATTRIBUTE_METHOD1(CSkyMesh, GetCloudColor_s, Vector3*) { (*p1) = cls->GetCloudColor(); return S_OK; }
77  ATTRIBUTE_METHOD1(CSkyMesh, SetCloudColor_s, Vector3) { cls->SetCloudColor(p1); return S_OK; }
78 
79  ATTRIBUTE_METHOD1(CSkyMesh, GetCloudVelocity_s, Vector2*) { (*p1) = cls->GetCloudVelocity(); return S_OK; }
80  ATTRIBUTE_METHOD1(CSkyMesh, SetCloudVelocity_s, Vector2) { cls->SetCloudVelocity(p1); return S_OK; }
81 
82  ATTRIBUTE_METHOD1(CSkyMesh, GetCloudOffset_s, Vector2*) { (*p1) = cls->GetCloudOffset(); return S_OK; }
83  ATTRIBUTE_METHOD1(CSkyMesh, SetCloudOffset_s, Vector2) { cls->SetCloudOffset(p1); return S_OK; }
84 
85  ATTRIBUTE_METHOD1(CSkyMesh, GetCloudThickness_s, float*) { *p1 = cls->GetCloudThickness(); return S_OK; }
86  ATTRIBUTE_METHOD1(CSkyMesh, SetCloudThickness_s, float) { cls->SetCloudThickness(p1); return S_OK; }
87 
88  ATTRIBUTE_METHOD1(CSkyMesh, GetSunSize_s, Vector2*) { (*p1) = cls->GetSunSize(); return S_OK; }
89  ATTRIBUTE_METHOD1(CSkyMesh, SetSunSize_s, Vector2) { cls->SetSunSize(p1); return S_OK; }
90 
91  ATTRIBUTE_METHOD1(CSkyMesh, GetMoonSize_s, Vector2*) { (*p1) = cls->GetMoonSize(); return S_OK; }
92  ATTRIBUTE_METHOD1(CSkyMesh, SetMoonSize_s, Vector2) { cls->SetMoonSize(p1); return S_OK; }
93 
94  ATTRIBUTE_METHOD1(CSkyMesh, GetFogColor_s, Vector3*) { (*p1) = cls->GetFogColor(); return S_OK; }
95  ATTRIBUTE_METHOD1(CSkyMesh, SetFogColor_s, Vector3) { cls->SetFogColor(p1); return S_OK; }
96 
98  void SetSkyMeshFile(const char* filename);
100  const char* GetSkyMeshFile();
101 
103  void SetSkyMeshTexture(const char* filename, int nTexIndex = 2);
105  const char* GetSkyMeshTexture(int nTexIndex = 2);
106 
111  const LinearColor& GetSkyColorFactor(){ return m_skycolorFactor; };
116  void SetSkyColorFactor(const LinearColor& color){ m_skycolorFactor = color; };
117 
119  virtual HRESULT Draw(SceneState * sceneState);
120 
121  void DrawSimulatedSky(EffectManager* pEffectManager, SceneState * sceneState, CSunLight &sunlight, RenderDevicePtr pd3dDevice, Vector3 &vPos);
122 
123  void DrawStaticMeshSky(EffectManager* pEffectManager, SceneState * sceneState, RenderDevicePtr pd3dDevice, CSunLight &sunlight, Vector3 vPos);
124 
125  void DrawStaticMeshSkyInner(SceneState * sceneState);
126 
127  virtual HRESULT RendererRecreated();
128  // -- set current sky mode and parameters
129  void CreateSkyVertexColorSimple();
142  void CreateSkyStaticMesh(const string& strObjectName, AssetEntity& MeshAsset, FLOAT fScaleX, FLOAT fScaleY, FLOAT fScaleZ, FLOAT fHeightOffset = 0);
143 
144  virtual DVector3 GetPosition(){ return m_vPos; };
145  virtual void SetPosition(const DVector3 & v){ m_vPos = v; };
146 
152  void SetFogBlendAngleFrom(float fValue){ m_fFogBlendAngleFrom = fValue; };
153  float GetFogBlendAngleFrom(){ return m_fFogBlendAngleFrom; };
154 
160  void SetFogBlendAngleTo(float fValue){ m_fFogBlendAngleTo = fValue; };
161  float GetFogBlendAngleTo(){ return m_fFogBlendAngleTo; };
162 
164  void EnableSimulatedSky(bool bEnable);
166  bool IsSimulatedSkyEnabled(){ return (m_typeSky == Sky_Simulated); };
167 
170  virtual HRESULT InitDeviceObjects();
172  virtual HRESULT DeleteDeviceObjects();
173 
174  private:
176  SkyType m_typeSky;
177 
179  DVector3 m_vPos;
180 
181  // pointer to the static mesh
182  ref_ptr<CMeshObject> m_pStaticMesh;
183 
186  static float m_fFogBlendAngleFrom;
187  static float m_fFogBlendAngleTo;
189  LinearColor m_skycolorFactor;
190 
191  void SetSkyMesh(AssetEntity& MeshAsset, float fHeightOffset = 0);
192 
194  //
195  // for simulated sky
196  //
198  bool m_bSimsky_BufferInited;
199 
200  bool m_bSimsky_AutoDayTime;
202  bool GetIsAutoDayTime() { return m_bSimsky_AutoDayTime; }
203  void SetIsAutoDayTime(bool bValue) { m_bSimsky_AutoDayTime = bValue; }
204  ParaVertexBuffer m_simsky_vb;
205  ParaIndexBuffer m_simsky_ib;
206 
207  int m_nSimsky_vertexCount;
208  int m_nSimsky_indexCount;
209  int m_nSimsky_primitiveCount;
210  float m_fSimsky_verticalRadius;
211  float m_fSimsky_horizonRadius;
212  int m_nSimsky_verticalSampleCount;
213  int m_nSimsky_horizonSampleCount;
214  Vector3 m_vSimsky_sunDirection;
215  Vector3 m_vSimsky_sunPosition;
216 
217  Vector3 m_vSimsky_position;
218 
220  asset_ptr<TextureEntity> m_texSimsky_sunsetGlowTexture;
221  const char* GetSunGlowTexture();
222  void SetSunGlowTexture(const char* sValue);
223 
226  asset_ptr<TextureEntity> m_texSimsky_cloudTexture;
227  const char* GetCloudTexture();
228  void SetCloudTexture(const char* sValue);
229 
230  Vector3 m_vSimsky_sunColor;
231  Vector3 GetSunColor() { return m_vSimsky_sunColor; }
232  void SetSunColor(const Vector3 & vValue) { m_vSimsky_sunColor = vValue; }
233 
234  Vector3 m_vSimsky_lightSkyColor;
235 
236  Vector3 GetLightSkyColor() { return m_vSimsky_lightSkyColor; }
237  void SetLightSkyColor(const Vector3 & vValue) { m_vSimsky_lightSkyColor = vValue; }
238 
239  Vector3 m_vSimsky_darkSkyColor;
240  Vector3 GetDarkSkyColor() { return m_vSimsky_darkSkyColor; }
241  void SetDarkSkyColor(const Vector3 & vValue) { m_vSimsky_darkSkyColor = vValue; }
242 
243  Vector2 m_vSimsky_sunIntensity;
244  Vector2 GetSunIntensity() { return m_vSimsky_sunIntensity; }
245  void SetSunIntensity(const Vector2 & vValue) { m_vSimsky_sunIntensity = vValue; }
246 
247  Vector3 m_vSimsky_cloudColor;
248  Vector3 GetCloudColor() { return m_vSimsky_cloudColor; }
249  void SetCloudColor(const Vector3 & vValue) { m_vSimsky_cloudColor = vValue; }
250 
251  Vector2 m_vSimsky_cloudDirection;
252  Vector2 GetCloudDirection() { return m_vSimsky_cloudDirection; }
253  void SetCloudDirection(const Vector2 & vValue) { m_vSimsky_cloudDirection = vValue; }
254 
255  Vector2 m_vSimsky_cloudVelocity;
256  Vector2 GetCloudVelocity() { return m_vSimsky_cloudVelocity; }
257  void SetCloudVelocity(const Vector2 & vValue) { m_vSimsky_cloudVelocity = vValue; }
258 
259  Vector2 m_vSimsky_cloudOffset;
260  Vector2 GetCloudOffset() { return m_vSimsky_cloudOffset; }
261  void SetCloudOffset(const Vector2 & vValue) { m_vSimsky_cloudOffset = vValue; }
262 
263  Vector2 m_vSimsky_sunSize;
264  Vector2 GetSunSize() { return m_vSimsky_sunSize; }
265 
270  void SetSunSize(const Vector2 & vValue) { m_vSimsky_sunSize = vValue; }
271 
272  Vector3 m_vSimsky_fogColor;
273  Vector3 GetFogColor() const { return m_vSimsky_fogColor; }
274  void SetFogColor(Vector3 val) { m_vSimsky_fogColor = val; }
275 
276  Vector2 m_vSimsky_moonSize;
277  Vector2 GetMoonSize() const { return m_vSimsky_moonSize; }
278  void SetMoonSize(Vector2 val) { m_vSimsky_moonSize = val; }
279 
280  float m_fSimsky_cloudThickness;
281  float GetCloudThickness() const { return m_fSimsky_cloudThickness; }
282  void SetCloudThickness(float val) { m_fSimsky_cloudThickness = val; }
283 
285  void UpdateSimSky(float fTime);
286  bool m_bSimsky_isDaytime;
287 
291  void CreateSkySimulated(int verticalSampleCount, int horizonSampleCount, float verticalRadius, float horizonRadius);
292  };
293 }
void SetSkyMeshFile(const char *filename)
change the sky mesh model
Definition: SkyMesh.cpp:208
void DrawSimulatedSky(EffectManager *pEffectManager, SceneState *sceneState, CSunLight &sunlight, RenderDevicePtr pd3dDevice, Vector3 &vPos)
Definition: SkyMesh.cpp:657
3-dimensional vector with double precision.
Definition: ParaDVector3.h:17
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual HRESULT DeleteDeviceObjects()
delete device objects
Definition: SkyMesh.cpp:335
void EnableSimulatedSky(bool bEnable)
set whether we render the sky as simulated mesh
Definition: SkyMesh.cpp:239
SkyType
Definition: SkyMesh.h:21
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
different physics engine has different winding order.
Definition: EventBinding.h:32
the mesh is just a static mesh object.
Definition: SkyMesh.h:24
virtual HRESULT InitDeviceObjects()
init device objects.
Definition: SkyMesh.cpp:253
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
Definition: SunLight.h:26
virtual void SetPosition(const DVector3 &v)
always bottom center of the bounding shape
Definition: SkyMesh.h:145
a very thin wrapper to DirectX device with a portable version of openGL implementation.
Definition: RenderDeviceDirectX.h:10
a simulated sky
Definition: SkyMesh.h:26
void DrawStaticMeshSky(EffectManager *pEffectManager, SceneState *sceneState, RenderDevicePtr pd3dDevice, CSunLight &sunlight, Vector3 vPos)
Definition: SkyMesh.cpp:430
the sky object in the scene.
Definition: SkyMesh.h:13
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
const char * GetSkyMeshFile()
get the sky mesh model file name.
Definition: SkyMesh.cpp:228
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
void SetSkyMeshTexture(const char *filename, int nTexIndex=2)
change the sky mesh model
Definition: SkyMesh.cpp:401
void SetFogBlendAngleTo(float fValue)
to which angle the sky fog ends, in most cases.
Definition: SkyMesh.h:160
The ref_ptr class template stores a pointer to a dynamically allocated (AssetEntity|CRefCounted|BaseA...
Definition: PERefPtr.h:13
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
virtual DVector3 GetPosition()
always bottom center of the bounding shape
Definition: SkyMesh.h:144
bool IsSimulatedSkyEnabled()
get whether we render the sky as simulated mesh
Definition: SkyMesh.h:166
virtual HRESULT Draw(SceneState *sceneState)
render the sky
Definition: SkyMesh.cpp:68
Tile Object have position and bounding rect and can usually be attached to quad-tree terrain tile...
Definition: TileObject.h:10
void SetFogBlendAngleFrom(float fValue)
from which angle the sky fog begins, in most cases.
Definition: SkyMesh.h:152
manager all effects file used by the game engine.
Definition: EffectManager.h:16
void SetSkyColorFactor(const LinearColor &color)
a color to be multiplied to the sky, giving it a special color hue
Definition: SkyMesh.h:116
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: SkyMesh.h:35
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: SkyMesh.cpp:830
const LinearColor & GetSkyColorFactor()
a color to be multiplied to the sky, giving it a special color hue
Definition: SkyMesh.h:111
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: SkyMesh.h:33
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: SkyMesh.h:31
const char * GetSkyMeshTexture(int nTexIndex=2)
get the sky mesh model file name.
Definition: SkyMesh.cpp:409
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
void CreateSkyStaticMesh(const string &strObjectName, AssetEntity &MeshAsset, FLOAT fScaleX, FLOAT fScaleY, FLOAT fScaleZ, FLOAT fHeightOffset=0)
Create the sky mesh as a static mesh object.
Definition: SkyMesh.cpp:159