My Project
Public Member Functions | Friends | List of all members
ParaEngine::CSunLight Class Reference

Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc. More...

#include <SunLight.h>

Inheritance diagram for ParaEngine::CSunLight:
ParaEngine::IAttributeFields ParaEngine::IObject ParaEngine::CRefCounted

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...
 
Para3DLightGetD3DLight ()
 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
 
LinearColorCalcSunriseSunsetColors (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...
 
CLightScatteringDataGetLightScatteringData ()
 get light Scattering Data object. More...
 
float GetShadowFactor ()
 
void SetShadowFactor (float shadowFactor)
 
bool HasNightHours () const
 
void SetHasNightHours (bool val)
 
- Public Member Functions inherited from ParaEngine::IAttributeFields
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 IAttributeFieldsGetChildAttributeObject (int nRowIndex, int nColumnIndex=0)
 
virtual IAttributeFieldsGetChildAttributeObject (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 CDynamicAttributeFieldGetDynamicField (const std::string &sName)
 Get a dynamic field with a given name. More...
 
virtual CDynamicAttributeFieldGetDynamicField (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...
 
CAttributeClassGetAttributeClass ()
 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...
 
- Public Member Functions inherited from ParaEngine::IObject
virtual void Clone (IObject *obj) const
 Clone the object's contains to a pointer. More...
 
virtual IObjectClone () 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 ITypeGetType () const
 
virtual std::string ToString () const
 
WeakPtr_typeGetWeakReference ()
 get weak reference object. More...
 
virtual int ProcessObjectEvent (const ObjectEvent &event)
 this function is only used to backward compatibility of ParaObject:AddEvent() function. More...
 
- Public Member Functions inherited from ParaEngine::CRefCounted
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 ()
 
CRefCountedAddToAutoReleasePool ()
 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

- Public Types inherited from ParaEngine::IAttributeFields
typedef ParaEngine::weak_ptr< IObject, IAttributeFieldsWeakPtr_type
 
- Public Types inherited from ParaEngine::IObject
typedef ParaEngine::weak_ptr< IObjectWeakPtr_type
 
- Static Public Member Functions inherited from ParaEngine::IAttributeFields
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...
 
- Protected Member Functions inherited from ParaEngine::IAttributeFields
virtual CAttributeClassCreateAttributeClass ()
 initialize fields
 
virtual CDynamicAttributesSetGetDynamicAttributes (bool bCreateIfNotExist=false)
 
- Protected Attributes inherited from ParaEngine::IObject
WeakPtr_type m_weak_reference
 
- Protected Attributes inherited from ParaEngine::CRefCounted
int m_refcount
 

Detailed Description

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.

Constructor & Destructor Documentation

§ CSunLight()

CSunLight::CSunLight ( )

create default sun light direction.

Member Function Documentation

§ AdvanceTimeOfDay()

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

§ CalcSunriseSunsetColors()

LinearColor * ParaEngine::CSunLight::CalcSunriseSunsetColors ( float  fCelestialAngle)

return NULL if no sun set colors.

§ EnableAutoSunColor()

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.

§ GetAttributeClassID()

virtual int ParaEngine::CSunLight::GetAttributeClassID ( )
inlinevirtual

attribute class ID should be identical, unless one knows how overriding rules work.

Reimplemented from ParaEngine::IAttributeFields.

§ GetCelestialAngle()

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.

§ GetLightScatteringData()

CLightScatteringData * CSunLight::GetLightScatteringData ( )

get light Scattering Data object.

More advanced simulation of light.

§ GetMaximumAngle()

float CSunLight::GetMaximumAngle ( )

get the maximum sun angle with the Y axis.

§ GetSunAmbient()

LinearColor CSunLight::GetSunAmbient ( )

get the ambient sun color.

§ GetSunAmbientHue()

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.

§ GetSunAngle()

float CSunLight::GetSunAngle ( )

Get the sun angle, where angle 0 means the noon.

+/-1.57 means night or morning.

Returns
:the angle between the sun direction and the Y(up) axis. in the range [-m_fMaxAngle, +m_fMaxAngle]

§ GetSunColor()

LinearColor CSunLight::GetSunColor ( )

get the ambient sun color.

Get the color and intensity of the sun.

§ GetSunDiffuse()

LinearColor CSunLight::GetSunDiffuse ( )

get the ambient sun color.

§ GetSunDirection()

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.

§ GetTimeOfDaySTD()

float CSunLight::GetTimeOfDaySTD ( )

get standard time.

see GetTimeOfDay()

Returns
: *
Parameters
timealways in the range [-1,1], -0.5 is dawn, 0 means at noon, 0.5 is twilight, 1,-1 is midnight

§ InstallFields()

int CSunLight::InstallFields ( CAttributeClass pClass,
bool  bOverride 
)
virtual

this class should be implemented if one wants to add new attribute.

This function is always called internally.

Reimplemented from ParaEngine::IAttributeFields.

§ IsAutoSunColorEnable()

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.

§ SetDayLength()

void CSunLight::SetDayLength ( float  fMinutes)

set how many minutes are there in a day, this is used in time simulation.

default value is 300.

Parameters
fMinutes

§ SetMaximumAngle()

void CSunLight::SetMaximumAngle ( float  fMaxAngle)

set the maximum sun angle with the Y axis.

§ SetSunAmbient()

void CSunLight::SetSunAmbient ( const LinearColor ambient)

Set the ambient sun color.

Note
: it will disable AutoSunColor

§ SetSunAngle()

void CSunLight::SetSunAngle ( float  fSunAngle)

set the sun angle.

Note
: it will disable AutoSunColor

§ SetSunDiffuse()

void CSunLight::SetSunDiffuse ( const LinearColor diffuse)

Set the ambient sun color.

Note
: it will disable AutoSunColor

§ SetTimeOfDay()

void CSunLight::SetTimeOfDay ( float  time)

set time of day in seconds.

Use SetDayLength() to set the total number of minutes in a day.

Parameters
timetime in seconds. This can be any non-negative value. 0 means 6:00am at dawn.

§ SetTimeOfDaySTD()

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.

Parameters
timealways in the range [-1,1], -0.5 is dawn, 0 means at noon, 0.5 is twilight, 1,-1 is midnight

The documentation for this class was generated from the following files: