My Project
SunLight.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "light_scattering_data.h"
4 #include "LightParam.h"
5 #include "Fog.h"
6 
7 namespace ParaEngine
8 {
26  class CSunLight : public IAttributeFields
27  {
28  public:
29  CSunLight();
30  ~CSunLight();
31 
33  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_CSunLight;}
35  virtual const char* GetAttributeClassName(){static const char name[] = "CSunLight"; return name;}
37  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
39  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
40 
41  ATTRIBUTE_METHOD1(CSunLight, GetTimeOfDay_s, float*) {*p1 = cls->GetTimeOfDay(); return S_OK;}
42  ATTRIBUTE_METHOD1(CSunLight, SetTimeOfDay_s, float) {cls->SetTimeOfDay(p1); return S_OK;}
43 
44  ATTRIBUTE_METHOD1(CSunLight, GetTimeOfDaySTD_s, float*) {*p1 = cls->GetTimeOfDaySTD(); return S_OK;}
45  ATTRIBUTE_METHOD1(CSunLight, SetTimeOfDaySTD_s, float) {cls->SetTimeOfDaySTD(p1); return S_OK;}
46 
47  ATTRIBUTE_METHOD1(CSunLight, GetMaximumAngle_s, float*) {*p1 = cls->GetMaximumAngle(); return S_OK;}
48  ATTRIBUTE_METHOD1(CSunLight, SetMaximumAngle_s, float) {cls->SetMaximumAngle(p1); return S_OK;}
49 
50  ATTRIBUTE_METHOD1(CSunLight, GetSunDiffuse_s, Vector3*) { *p1 = cls->GetSunDiffuse().ToVector3(); return S_OK; }
51  ATTRIBUTE_METHOD1(CSunLight, SetSunDiffuse_s, Vector3) {LinearColor c(p1.x, p1.y,p1.z,1); cls->SetSunDiffuse(c); return S_OK;}
52 
53  ATTRIBUTE_METHOD1(CSunLight, GetSunAmbient_s, Vector3*) { *p1 = cls->GetSunAmbient().ToVector3(); return S_OK; }
54  ATTRIBUTE_METHOD1(CSunLight, SetSunAmbient_s, Vector3) {LinearColor c(p1.x, p1.y,p1.z,1); cls->SetSunAmbient(c); return S_OK;}
55 
56  ATTRIBUTE_METHOD1(CSunLight, IsAutoSunColorEnable_s, bool*) {*p1 = cls->IsAutoSunColorEnable(); return S_OK;}
57  ATTRIBUTE_METHOD1(CSunLight, EnableAutoSunColor_s, bool) {cls->EnableAutoSunColor(p1); return S_OK;}
58 
59  ATTRIBUTE_METHOD1(CSunLight, GetDayLength_s, float*) {*p1 = cls->GetDayLength(); return S_OK;}
60  ATTRIBUTE_METHOD1(CSunLight, SetDayLength_s, float) {cls->SetDayLength(p1); return S_OK;}
61 
62  ATTRIBUTE_METHOD1(CSunLight, GetSunAngle_s, float*) {*p1 = cls->GetSunAngle(); return S_OK;}
63  ATTRIBUTE_METHOD1(CSunLight, SetSunAngle_s, float) {cls->SetSunAngle(p1); return S_OK;}
64 
65  //shadow factor --clayman 2011.9.20
66  ATTRIBUTE_METHOD1(CSunLight, GetShadowFactor_s, float*) {*p1 = cls->GetShadowFactor(); return S_OK;}
67  ATTRIBUTE_METHOD1(CSunLight, SetShadowFactor_s, float) {cls->SetShadowFactor(p1); return S_OK;}
68 
69  public:
73  float AdvanceTimeOfDay(float timeDelta);
74 
80  void SetTimeOfDay(float time);
81 
83  float GetTimeOfDay();
84 
88  float GetCelestialAngle();
91 
93  float CalculateCelestialAngle(float curTime, float relativeTime = 0.f);
95  LinearColor* CalcSunriseSunsetColors(float fCelestialAngle);
96 
102  void SetTimeOfDaySTD(float time);
103 
106  float GetTimeOfDaySTD();
107 
109  void SetMaximumAngle(float fMaxAngle);
110 
112  float GetMaximumAngle();
113 
119  void SetSunDiffuse(const LinearColor& diffuse);
120 
126  void SetSunAmbient(const LinearColor& ambient);
127 
132  void SetDayLength(float fMinutes);
134  float GetDayLength();
135 
140  float GetSunAngle();
144  void SetSunAngle(float fSunAngle);
145 
149  void EnableAutoSunColor(bool bEnable);
153  bool IsAutoSunColorEnable();
154 
156  // following for used by effect manager to get the current state.
158 
161 
164 
168 
173 
176 
177  float GetShadowFactor();
178 
179  void SetShadowFactor(float shadowFactor);
180 
181  bool HasNightHours() const;
182  void SetHasNightHours(bool val);
183  private:
184  CLightParam m_light;
186  float m_seconds;
188  float m_fYaxisRotation;
190  float m_fMaxAngle;
193  float m_fCurrentAngle;
195  float m_fDayLength;
197  CLightScatteringData m_LightScatteringData;
198  LinearColor m_colorsSunriseSunset;
199 
203  bool m_bAutoSunColor;
205  bool m_bHasNightHours;
206 
207  float m_shadowFactor;
208 
209  private:
214  void UpdateSunParameters();
215 
217  void SetPosition(const Vector3& newpos);
218  Vector3 GetSunPosition();
219 
220  friend class CSkyMesh;
221  friend class CSceneObject;
222  };
223 }
void SetSunAngle(float fSunAngle)
set the sun angle.
Definition: SunLight.cpp:119
float GetTimeOfDay()
get the current time in seconds
Definition: SunLight.cpp:54
CLightScatteringData * GetLightScatteringData()
get light Scattering Data object.
Definition: SunLight.cpp:125
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void SetSunAmbient(const LinearColor &ambient)
Set the ambient sun color.
Definition: SunLight.cpp:75
Vector3 GetSunDirection()
get the normalized sun direction vector, please note the vector always points from the sun position t...
Definition: SunLight.cpp:104
float GetMaximumAngle()
get the maximum sun angle with the Y axis.
Definition: SunLight.cpp:135
float CalculateCelestialAngle(float curTime, float relativeTime=0.f)
in seconds
Definition: SunLight.cpp:262
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: SunLight.h:37
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: light_scattering_data.h:26
LinearColor GetSunAmbient()
get the ambient sun color.
Definition: SunLight.cpp:70
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: SunLight.cpp:244
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
Definition: SunLight.h:26
float GetSunAngle()
Get the sun angle, where angle 0 means the noon.
Definition: SunLight.cpp:114
void SetTimeOfDay(float time)
set time of day in seconds.
Definition: SunLight.cpp:161
void SetTimeOfDaySTD(float time)
set standard time.
Definition: SunLight.cpp:174
the sky object in the scene.
Definition: SkyMesh.h:13
float GetCelestialAngle()
angle between [0, 1].
Definition: SunLight.cpp:278
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
float GetDayLength()
return how many minutes are there in a day in minutes
Definition: SunLight.cpp:150
void EnableAutoSunColor(bool bEnable)
set whether we will automatically adjust sun diffuse and ambient colors according to time of day...
Definition: SunLight.cpp:81
bool IsAutoSunColorEnable()
get whether we will automatically adjust sun diffuse and ambient colors according to time of day...
Definition: SunLight.cpp:93
LinearColor GetSunColor()
get the ambient sun color.
Definition: SunLight.cpp:99
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object's name
Definition: SunLight.h:35
void SetMaximumAngle(float fMaxAngle)
set the maximum sun angle with the Y axis.
Definition: SunLight.cpp:130
void SetDayLength(float fMinutes)
set how many minutes are there in a day, this is used in time simulation.
Definition: SunLight.cpp:155
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
The top level scene management class.
Definition: SceneObject.h:58
CSunLight()
Definition: SunLight.cpp:20
void SetSunDiffuse(const LinearColor &diffuse)
Set the ambient sun color.
Definition: SunLight.cpp:64
LinearColor * CalcSunriseSunsetColors(float fCelestialAngle)
return NULL if no sun set colors.
Definition: SunLight.cpp:293
a single light in ParaEngine.
Definition: LightParam.h:6
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: SunLight.h:33
Definition: RenderCore.h:34
float GetTimeOfDaySTD()
get standard time.
Definition: SunLight.cpp:167
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
float AdvanceTimeOfDay(float timeDelta)
advance time is in seconds, this will also change the light direction, sun color and sun ambient colo...
Definition: SunLight.cpp:180
LinearColor GetSunAmbientHue()
get the Ambient color of the sun.
Definition: SunLight.cpp:109
LinearColor GetSunDiffuse()
get the ambient sun color.
Definition: SunLight.cpp:59
Para3DLight * GetD3DLight()
get the equivalent light in d3d format
Definition: SunLight.cpp:49
LinearColor ComputeFogColor()
compute and return the fog color
Definition: SunLight.cpp:230
float GetCelestialAngleRadian()
(GetCelestialAngle() * 2 * PI)
Definition: SunLight.cpp:288