Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::DayNightCycle Class Reference

#include <DayNightCycle.h>

Collaboration diagram for pge::DayNightCycle:

Collaboration graph
[legend]

Public Member Functions

virtual ~DayNightCycle (void)
 Destructor.

void setToNight (void)
void setToDay (void)
void setDayNightCycle (float dayNightCycle)
float getDayNightCycle (void)
Vector3f getAmbientLight (void)
Vector3f getSunPosition (void)
Vector3f getSunDirection (void)
void update (unsigned int delay)

Static Public Member Functions

DayNightCyclegetInstance (void)

Private Member Functions

 DayNightCycle (void)
 Constructor.


Private Attributes

ValueFaderm_fader
float m_sunRadius
Vector3f m_sunPosition
Vector3f m_sunDirection
int m_currentState
int m_dayTimeLength
int m_nightTimeLength
int m_timePassed
bool m_leftToRight

Static Private Attributes

const int STATE_NIGHT = 0
const int STATE_DAY = 1
const int STATE_CHANGE_FROM_DAY_TO_NIGHT = 2
const int STATE_CHANGE_FROM_NIGHT_TO_DAY = 3

Constructor & Destructor Documentation

virtual pge::DayNightCycle::~DayNightCycle void   )  [inline, virtual]
 

Destructor.

Definition at line 24 of file DayNightCycle.h.

00024                                              {
00025                 }

pge::DayNightCycle::DayNightCycle void   )  [inline, private]
 

Constructor.

Definition at line 167 of file DayNightCycle.h.

References m_dayTimeLength, m_fader, m_leftToRight, m_nightTimeLength, m_sunDirection, m_sunPosition, m_sunRadius, m_timePassed, pge::ValueFader::setChange(), and setToDay().

00167                                     {
00168                         m_dayTimeLength = 30000;
00169                         m_nightTimeLength = 30000;
00170                         m_timePassed = 0;
00171                         m_leftToRight = true;
00172                         m_fader = new ValueFader(0.0f, 1.0f);
00173                         m_fader->setChange(0.001f);
00174 
00175                         // Start with day.
00176                         //m_currentState = STATE_DAY;
00177                         //m_fader->setValue(1.0f);
00178 
00179                         setToDay();
00180 
00181                         m_sunRadius = 500.0f;
00182                         m_sunPosition = Vector3f(-m_sunRadius, 0.0f, 0.0f);
00183                         m_sunDirection = Vector3f(0.0f, 1.0f, 0.0f);
00184                 }

Here is the call graph for this function:


Member Function Documentation

Vector3f pge::DayNightCycle::getAmbientLight void   )  [inline]
 

Definition at line 65 of file DayNightCycle.h.

References pge::ValueFader::getValue(), m_fader, and pge::Vector3f::multiply().

00065                                                {
00066                         // TODO: performance. put everything in update.
00067                         Vector3f baseAmbient = Vector3f(1.0f, 1.0f, 1.0f);
00068                         float ambientFactor = mathutils::mapValueToInterval(0.0f, 1.0f, 0.2f, 1.0f, m_fader->getValue());
00069 
00070                         return baseAmbient.multiply(ambientFactor);
00071                 }

Here is the call graph for this function:

float pge::DayNightCycle::getDayNightCycle void   )  [inline]
 

Definition at line 60 of file DayNightCycle.h.

References pge::ValueFader::getValue(), and m_fader.

00060                                              {
00061                         return m_fader->getValue();
00062                 }

Here is the call graph for this function:

DayNightCycle* pge::DayNightCycle::getInstance void   )  [inline, static]
 

Definition at line 33 of file DayNightCycle.h.

00033                                                         {
00034                         static DayNightCycle instance;
00035                         return &instance;
00036                 }

Vector3f pge::DayNightCycle::getSunDirection void   )  [inline]
 

Definition at line 79 of file DayNightCycle.h.

References m_sunDirection.

00079                                                {
00080                         return m_sunDirection;
00081                 }

Vector3f pge::DayNightCycle::getSunPosition void   )  [inline]
 

Definition at line 74 of file DayNightCycle.h.

References m_sunPosition.

00074                                               {
00075                         return m_sunPosition;
00076                 }

void pge::DayNightCycle::setDayNightCycle float  dayNightCycle  )  [inline]
 

Definition at line 55 of file DayNightCycle.h.

References m_fader, and pge::ValueFader::setValue().

00055                                                            {
00056                         m_fader->setValue(dayNightCycle);
00057                 }

Here is the call graph for this function:

void pge::DayNightCycle::setToDay void   )  [inline]
 

Definition at line 47 of file DayNightCycle.h.

References m_currentState, m_fader, m_timePassed, pge::ValueFader::setValue(), and STATE_DAY.

Referenced by DayNightCycle().

00047                                     {
00048                         // TODO: sun direction / position, bool value lefttoright
00049                         m_currentState = STATE_DAY;
00050                         m_timePassed = 0;
00051                         m_fader->setValue(1.0f);
00052                 }

Here is the call graph for this function:

void pge::DayNightCycle::setToNight void   )  [inline]
 

Definition at line 39 of file DayNightCycle.h.

References m_currentState, m_fader, m_timePassed, pge::ValueFader::setValue(), and STATE_NIGHT.

00039                                       {
00040                         // TODO: sun direction / position, bool value lefttoright
00041                         m_currentState = STATE_NIGHT;
00042                         m_timePassed = 0;
00043                         m_fader->setValue(0.0f);
00044                 }

Here is the call graph for this function:

void pge::DayNightCycle::update unsigned int  delay  )  [inline]
 

Definition at line 84 of file DayNightCycle.h.

References pge::ValueFader::getValue(), m_currentState, m_dayTimeLength, m_fader, m_leftToRight, m_nightTimeLength, m_sunDirection, m_sunPosition, m_sunRadius, m_timePassed, pge::Vector3f::m_v, pge::Vector3f::normalize(), pge::ValueFader::setValue(), STATE_CHANGE_FROM_DAY_TO_NIGHT, STATE_CHANGE_FROM_NIGHT_TO_DAY, STATE_DAY, STATE_NIGHT, and pge::ValueFader::update().

00084                                                 {
00085                         float x = 0.0f;
00086                         float y = 0.0f;
00087 
00088 
00089                         switch(m_currentState) {
00090                                 case STATE_DAY:
00091                                 // Count daytime and change state if day is done.
00092                                 m_timePassed += delay;
00093                                 if(m_timePassed >= m_dayTimeLength) {
00094                                         m_timePassed = 0;
00095                                         m_leftToRight = !m_leftToRight;
00096                                         m_currentState = STATE_CHANGE_FROM_DAY_TO_NIGHT;
00097                                 }
00098                                 break;
00099                                 case STATE_NIGHT:
00100                                         // Count nighttime and change state if night is done.
00101                                         m_timePassed += delay;
00102                                         if(m_timePassed >= m_nightTimeLength) {
00103                                                 m_timePassed = 0;
00104                                                 m_currentState = STATE_CHANGE_FROM_NIGHT_TO_DAY;
00105                                         }
00106                                         break;
00107                                 case STATE_CHANGE_FROM_DAY_TO_NIGHT:
00108                                         // Update fader for day / night cycle.
00109                                         m_fader->update();
00110                                         if(m_fader->getValue() <= 0.0f) {
00111                                                 m_currentState = STATE_NIGHT;
00112                                                 m_fader->setValue(0.0f);
00113                                         }
00114 
00115                                         // Update sun position.
00116                                         if(m_leftToRight) {
00117                                                 x = mathutils::mapValueToInterval(0.0f, 1.0f, -500.0f, 0.0f, m_fader->getValue());
00118                                         } else {
00119                                                 x = mathutils::mapValueToInterval(0.0f, 1.0f, 500.0f, 0.0f, m_fader->getValue());
00120                                         }
00121                                         y = (float)sqrt(m_sunRadius * m_sunRadius - x * x);
00122                                         m_sunPosition.m_v[0] = x;
00123                                         m_sunPosition.m_v[1] = y;
00124 
00125                                         // Update sun direction.
00126                                         m_sunDirection.m_v[0] = m_sunPosition.m_v[0];
00127                                         m_sunDirection.m_v[1] = m_sunPosition.m_v[1];
00128                                         m_sunDirection.normalize();
00129                                         break;
00130                 
00131                                 case STATE_CHANGE_FROM_NIGHT_TO_DAY:
00132                                         // Update fader for day / night cycle.
00133                                         m_fader->update();
00134                                         if(m_fader->getValue() >= 1.0f) {
00135                                                 m_currentState = STATE_DAY;
00136                                                 m_fader->setValue(1.0f);
00137                                         }
00138 
00139                                         // Update sun position.
00140                                         if(m_leftToRight) {
00141                                                 x = mathutils::mapValueToInterval(0.0f, 1.0f, -500.0f, 0.0f, m_fader->getValue());
00142                                         } else {
00143                                                 x = mathutils::mapValueToInterval(0.0f, 1.0f, 500.0f, 0.0f, m_fader->getValue());
00144                                         }
00145                                         y = (float)sqrt(m_sunRadius * m_sunRadius - x * x);
00146                                         m_sunPosition.m_v[0] = x;
00147                                         m_sunPosition.m_v[1] = y;
00148 
00149                                         // Update sun direction.
00150                                         m_sunDirection.m_v[0] = m_sunPosition.m_v[0];
00151                                         m_sunDirection.m_v[1] = m_sunPosition.m_v[1];
00152                                         m_sunDirection.normalize();
00153                                         break;
00154                 
00155                                 default:
00156                                         break;
00157                         }
00158                 }

Here is the call graph for this function:


Field Documentation

int pge::DayNightCycle::m_currentState [private]
 

Definition at line 209 of file DayNightCycle.h.

Referenced by setToDay(), setToNight(), and update().

int pge::DayNightCycle::m_dayTimeLength [private]
 

Definition at line 211 of file DayNightCycle.h.

Referenced by DayNightCycle(), and update().

ValueFader* pge::DayNightCycle::m_fader [private]
 

Definition at line 199 of file DayNightCycle.h.

Referenced by DayNightCycle(), getAmbientLight(), getDayNightCycle(), setDayNightCycle(), setToDay(), setToNight(), and update().

bool pge::DayNightCycle::m_leftToRight [private]
 

Definition at line 214 of file DayNightCycle.h.

Referenced by DayNightCycle(), and update().

int pge::DayNightCycle::m_nightTimeLength [private]
 

Definition at line 212 of file DayNightCycle.h.

Referenced by DayNightCycle(), and update().

Vector3f pge::DayNightCycle::m_sunDirection [private]
 

Definition at line 202 of file DayNightCycle.h.

Referenced by DayNightCycle(), getSunDirection(), and update().

Vector3f pge::DayNightCycle::m_sunPosition [private]
 

Definition at line 201 of file DayNightCycle.h.

Referenced by DayNightCycle(), getSunPosition(), and update().

float pge::DayNightCycle::m_sunRadius [private]
 

Definition at line 200 of file DayNightCycle.h.

Referenced by DayNightCycle(), and update().

int pge::DayNightCycle::m_timePassed [private]
 

Definition at line 213 of file DayNightCycle.h.

Referenced by DayNightCycle(), setToDay(), setToNight(), and update().

const int pge::DayNightCycle::STATE_CHANGE_FROM_DAY_TO_NIGHT = 2 [static, private]
 

Definition at line 207 of file DayNightCycle.h.

Referenced by update().

const int pge::DayNightCycle::STATE_CHANGE_FROM_NIGHT_TO_DAY = 3 [static, private]
 

Definition at line 208 of file DayNightCycle.h.

Referenced by update().

const int pge::DayNightCycle::STATE_DAY = 1 [static, private]
 

Definition at line 206 of file DayNightCycle.h.

Referenced by setToDay(), and update().

const int pge::DayNightCycle::STATE_NIGHT = 0 [static, private]
 

Definition at line 205 of file DayNightCycle.h.

Referenced by setToNight(), and update().


The documentation for this class was generated from the following file:
Generated on Mon Oct 16 12:09:03 2006 for Phobosengine by doxygen 1.3.4