My Project
|
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc. More...
#include <SunLight.h>
Public Member Functions | |
CSunLight () | |
virtual int | GetAttributeClassID () |
attribute class ID should be identical, unless one knows how overriding rules work. More... | |
virtual const char * | GetAttributeClassName () |
a static string, describing the attribute class object's name | |
virtual const char * | GetAttributeClassDescription () |
a static string, describing the attribute class object | |
virtual int | InstallFields (CAttributeClass *pClass, bool bOverride) |
this class should be implemented if one wants to add new attribute. More... | |
ATTRIBUTE_METHOD1 (CSunLight, GetTimeOfDay_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetTimeOfDay_s, float) | |
ATTRIBUTE_METHOD1 (CSunLight, GetTimeOfDaySTD_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetTimeOfDaySTD_s, float) | |
ATTRIBUTE_METHOD1 (CSunLight, GetMaximumAngle_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetMaximumAngle_s, float) | |
ATTRIBUTE_METHOD1 (CSunLight, GetSunDiffuse_s, Vector3 *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetSunDiffuse_s, Vector3) | |
ATTRIBUTE_METHOD1 (CSunLight, GetSunAmbient_s, Vector3 *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetSunAmbient_s, Vector3) | |
ATTRIBUTE_METHOD1 (CSunLight, IsAutoSunColorEnable_s, bool *) | |
ATTRIBUTE_METHOD1 (CSunLight, EnableAutoSunColor_s, bool) | |
ATTRIBUTE_METHOD1 (CSunLight, GetDayLength_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetDayLength_s, float) | |
ATTRIBUTE_METHOD1 (CSunLight, GetSunAngle_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetSunAngle_s, float) | |
ATTRIBUTE_METHOD1 (CSunLight, GetShadowFactor_s, float *) | |
ATTRIBUTE_METHOD1 (CSunLight, SetShadowFactor_s, float) | |
float | AdvanceTimeOfDay (float timeDelta) |
advance time is in seconds, this will also change the light direction, sun color and sun ambient color. More... | |
Para3DLight * | GetD3DLight () |
get the equivalent light in d3d format | |
void | SetTimeOfDay (float time) |
set time of day in seconds. More... | |
float | GetTimeOfDay () |
get the current time in seconds | |
float | GetCelestialAngle () |
angle between [0, 1]. More... | |
float | GetCelestialAngleRadian () |
(GetCelestialAngle() * 2 * PI) | |
float | CalculateCelestialAngle (float curTime, float relativeTime=0.f) |
in seconds | |
LinearColor * | CalcSunriseSunsetColors (float fCelestialAngle) |
return NULL if no sun set colors. More... | |
void | SetTimeOfDaySTD (float time) |
set standard time. More... | |
float | GetTimeOfDaySTD () |
get standard time. More... | |
void | SetMaximumAngle (float fMaxAngle) |
set the maximum sun angle with the Y axis. More... | |
float | GetMaximumAngle () |
get the maximum sun angle with the Y axis. More... | |
LinearColor | GetSunDiffuse () |
get the ambient sun color. More... | |
void | SetSunDiffuse (const LinearColor &diffuse) |
Set the ambient sun color. More... | |
LinearColor | GetSunAmbient () |
get the ambient sun color. More... | |
void | SetSunAmbient (const LinearColor &ambient) |
Set the ambient sun color. More... | |
void | SetDayLength (float fMinutes) |
set how many minutes are there in a day, this is used in time simulation. More... | |
float | GetDayLength () |
return how many minutes are there in a day in minutes | |
float | GetSunAngle () |
Get the sun angle, where angle 0 means the noon. More... | |
void | SetSunAngle (float fSunAngle) |
set the sun angle. More... | |
void | EnableAutoSunColor (bool bEnable) |
set whether we will automatically adjust sun diffuse and ambient colors according to time of day. More... | |
bool | IsAutoSunColorEnable () |
get whether we will automatically adjust sun diffuse and ambient colors according to time of day. More... | |
LinearColor | ComputeFogColor () |
compute and return the fog color | |
LinearColor | GetSunColor () |
get the ambient sun color. More... | |
LinearColor | GetSunAmbientHue () |
get the Ambient color of the sun. More... | |
Vector3 | GetSunDirection () |
get the normalized sun direction vector, please note the vector always points from the sun position to the origin. More... | |
CLightScatteringData * | GetLightScatteringData () |
get light Scattering Data object. More... | |
float | GetShadowFactor () |
void | SetShadowFactor (float shadowFactor) |
bool | HasNightHours () const |
void | SetHasNightHours (bool val) |
![]() | |
virtual int | GetChildAttributeColumnCount () |
we support multi-dimensional child object. More... | |
virtual int | GetChildAttributeObjectCount (int nColumnIndex=0) |
get the number of child objects (row count) in the given column. More... | |
virtual IAttributeFields * | GetChildAttributeObject (int nRowIndex, int nColumnIndex=0) |
virtual IAttributeFields * | GetChildAttributeObject (const std::string &sName) |
get attribute by child object. More... | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *) | |
ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s) | |
ATTRIBUTE_METHOD (IAttributeFields, AddRef_s) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *) | |
ATTRIBUTE_METHOD (IAttributeFields, Release_s) | |
virtual const std::string & | GetIdentifier () |
virtual void | SetIdentifier (const std::string &sID) |
virtual bool | IsModified () |
whether some of the fields are modified.It is up to the implementation class to provide this functionality if necessary. More... | |
virtual void | SetModified (bool bModified) |
set whether any field has been modified. More... | |
virtual bool | ValidateFields () |
validate all fields and return true if validation passed. More... | |
virtual string | GetValidationMessage () |
get the recent validation message due to the most recent call to ValidateFields() | |
virtual bool | ResetField (int nFieldID) |
Reset the field to its initial or default value. More... | |
virtual bool | InvokeEditor (int nFieldID, const std::string &sParameters) |
Invoke an (external) editor for a given field. More... | |
virtual bool | AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0) |
add child object. More... | |
virtual void * | QueryObjectByName (const std::string &sObjectType) |
convert to object of a given type. More... | |
virtual void * | QueryObject (int nObjectType) |
convert to object of a given type. More... | |
virtual int | GetTime () |
get the current local time in case it is animated in milli seconds frames. More... | |
virtual void | SetTime (int nTime) |
virtual CDynamicAttributeField * | GetDynamicField (const std::string &sName) |
Get a dynamic field with a given name. More... | |
virtual CDynamicAttributeField * | GetDynamicField (int nIndex) |
Get a dynamic field with a given index. More... | |
virtual const char * | GetDynamicFieldNameByIndex (int nIndex) |
get field name by index | |
virtual int | GetDynamicFieldCount () |
how many dynamic field this object currently have. More... | |
virtual int | SetDynamicField (const std::string &sName, const CVariable &value) |
set a dynamic field with a given name. More... | |
virtual int | AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType) |
add dynamic field and return field index | |
virtual void | RemoveAllDynamicFields () |
remove all dynamic fields | |
virtual int | SaveDynamicFieldsToString (std::string &output) |
save only text dynamic fields to fieldname = value text strings. More... | |
virtual int | LoadDynamicFieldsFromString (const std::string &input) |
load only text dynamic fields from string More... | |
CAttributeClass * | GetAttributeClass () |
get the main attribute class object. More... | |
void | PrintObject () |
print the content of this object to a text file at temp/doc/[ClassName].txt. More... | |
![]() | |
virtual void | Clone (IObject *obj) const |
Clone the object's contains to a pointer. More... | |
virtual IObject * | Clone () const |
Clone the object's contains and return a pointer to the newly created object. More... | |
virtual bool | Equals (const IObject *obj) const |
Compare the object with another object. More... | |
virtual const IType * | GetType () const |
virtual std::string | ToString () const |
WeakPtr_type & | GetWeakReference () |
get weak reference object. More... | |
virtual int | ProcessObjectEvent (const ObjectEvent &event) |
this function is only used to backward compatibility of ParaObject:AddEvent() function. More... | |
![]() | |
void | addref () const |
add reference count of the object. More... | |
bool | delref () const |
decrease reference count of the object. More... | |
int | GetRefCount () const |
get the reference count | |
virtual int | Release () |
CRefCounted * | AddToAutoReleasePool () |
addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More... | |
Friends | |
class | CSkyMesh |
class | CSceneObject |
Additional Inherited Members | |
![]() | |
typedef ParaEngine::weak_ptr< IObject, IAttributeFields > | WeakPtr_type |
![]() | |
typedef ParaEngine::weak_ptr< IObject > | WeakPtr_type |
![]() | |
static HRESULT | GetAttributeClassID_s (IAttributeFields *cls, int *p1) |
static HRESULT | GetAttributeClassName_s (IAttributeFields *cls, const char **p1) |
static bool | OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false) |
Open a given file with the default registered editor in the game engine. More... | |
![]() | |
virtual CAttributeClass * | CreateAttributeClass () |
initialize fields | |
virtual CDynamicAttributesSet * | GetDynamicAttributes (bool bCreateIfNotExist=false) |
![]() | |
WeakPtr_type | m_weak_reference |
![]() | |
int | m_refcount |
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
the sun's direction is defined as below y | | |---—>x / \ / \ z \ sun direction when m_fYaxisRotation = 0, the direction vector is in the x,y plane, point in the opposite y direction. its angle with the y axis is in the range [-m_fMaxAngle, +m_fMaxAngle], when m_fYaxisRotation != 0, the vector is rotated m_fYaxisRotation rad counter clockwise around the y axis. The simulation of the path of the sun only covers very limited situations, e.g. winter and spring sun does not follow this rule exactly.
CSunLight::CSunLight | ( | ) |
create default sun light direction.
float CSunLight::AdvanceTimeOfDay | ( | float | timeDelta | ) |
advance time is in seconds, this will also change the light direction, sun color and sun ambient color.
this function is automatically called by the environment simulator
LinearColor * ParaEngine::CSunLight::CalcSunriseSunsetColors | ( | float | fCelestialAngle | ) |
return NULL if no sun set colors.
void CSunLight::EnableAutoSunColor | ( | bool | bEnable | ) |
set whether we will automatically adjust sun diffuse and ambient colors according to time of day.
if one calls SetSunDiffuse() or SetSunAmbient(), m_bAutoSunColor will be disabled. And one needs to enable by calling EnableAutoSunColor explicitly.
|
inlinevirtual |
attribute class ID should be identical, unless one knows how overriding rules work.
Reimplemented from ParaEngine::IAttributeFields.
float ParaEngine::CSunLight::GetCelestialAngle | ( | ) |
angle between [0, 1].
0.75 is dawn(6:00am), 0 is noon(12:00am), 0.25 is twilight(18:00pm), 0.5 is mid night(24:00pm). matching to a single cycle of day time. beginning from 6 clock.
CLightScatteringData * CSunLight::GetLightScatteringData | ( | ) |
get light Scattering Data object.
More advanced simulation of light.
float CSunLight::GetMaximumAngle | ( | ) |
get the maximum sun angle with the Y axis.
LinearColor CSunLight::GetSunAmbient | ( | ) |
get the ambient sun color.
LinearColor CSunLight::GetSunAmbientHue | ( | ) |
get the Ambient color of the sun.
All objects under the sun will share this ambient color. This parameter will change according to the current time of day.
float CSunLight::GetSunAngle | ( | ) |
Get the sun angle, where angle 0 means the noon.
+/-1.57 means night or morning.
LinearColor CSunLight::GetSunColor | ( | ) |
get the ambient sun color.
Get the color and intensity of the sun.
LinearColor CSunLight::GetSunDiffuse | ( | ) |
get the ambient sun color.
Vector3 CSunLight::GetSunDirection | ( | ) |
get the normalized sun direction vector, please note the vector always points from the sun position to the origin.
One may need to reverse the direction to be used in a shader.
float CSunLight::GetTimeOfDaySTD | ( | ) |
get standard time.
see GetTimeOfDay()
time | always in the range [-1,1], -0.5 is dawn, 0 means at noon, 0.5 is twilight, 1,-1 is midnight |
|
virtual |
this class should be implemented if one wants to add new attribute.
This function is always called internally.
Reimplemented from ParaEngine::IAttributeFields.
bool CSunLight::IsAutoSunColorEnable | ( | ) |
get whether we will automatically adjust sun diffuse and ambient colors according to time of day.
if one calls SetSunDiffuse() or SetSunAmbient(), m_bAutoSunColor will be disabled. And one needs to enable by calling EnableAutoSunColor explicitly.
void CSunLight::SetDayLength | ( | float | fMinutes | ) |
set how many minutes are there in a day, this is used in time simulation.
default value is 300.
fMinutes |
void CSunLight::SetMaximumAngle | ( | float | fMaxAngle | ) |
set the maximum sun angle with the Y axis.
void CSunLight::SetSunAmbient | ( | const LinearColor & | ambient | ) |
Set the ambient sun color.
void CSunLight::SetSunAngle | ( | float | fSunAngle | ) |
set the sun angle.
void CSunLight::SetSunDiffuse | ( | const LinearColor & | diffuse | ) |
Set the ambient sun color.
void CSunLight::SetTimeOfDay | ( | float | time | ) |
set time of day in seconds.
Use SetDayLength() to set the total number of minutes in a day.
time | time in seconds. This can be any non-negative value. 0 means 6:00am at dawn. |
void CSunLight::SetTimeOfDaySTD | ( | float | time | ) |
set standard time.
see SetTimeOfDay() old system does not have night system, hence a day only starts from 6:00am to 18:00pm. newer system (like the simulated sky) have night system. Hence the even number of day is actually rendered as night.
time | always in the range [-1,1], -0.5 is dawn, 0 means at noon, 0.5 is twilight, 1,-1 is midnight |