#include <DayNightCycle.h>
Collaboration diagram for pge::DayNightCycle:
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 | |
DayNightCycle * | getInstance (void) |
Private Member Functions | |
DayNightCycle (void) | |
Constructor. | |
Private Attributes | |
ValueFader * | m_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 |
|
Destructor.
Definition at line 24 of file DayNightCycle.h.
00024 { 00025 } |
|
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:
|
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:
|
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:
|
Definition at line 33 of file DayNightCycle.h.
00033 { 00034 static DayNightCycle instance; 00035 return &instance; 00036 } |
|
Definition at line 79 of file DayNightCycle.h. References m_sunDirection.
00079 { 00080 return m_sunDirection; 00081 } |
|
Definition at line 74 of file DayNightCycle.h. References m_sunPosition.
00074 { 00075 return m_sunPosition; 00076 } |
|
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:
|
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:
|
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:
|
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:
|
Definition at line 209 of file DayNightCycle.h. Referenced by setToDay(), setToNight(), and update(). |
|
Definition at line 211 of file DayNightCycle.h. Referenced by DayNightCycle(), and update(). |
|
Definition at line 199 of file DayNightCycle.h. Referenced by DayNightCycle(), getAmbientLight(), getDayNightCycle(), setDayNightCycle(), setToDay(), setToNight(), and update(). |
|
Definition at line 214 of file DayNightCycle.h. Referenced by DayNightCycle(), and update(). |
|
Definition at line 212 of file DayNightCycle.h. Referenced by DayNightCycle(), and update(). |
|
Definition at line 202 of file DayNightCycle.h. Referenced by DayNightCycle(), getSunDirection(), and update(). |
|
Definition at line 201 of file DayNightCycle.h. Referenced by DayNightCycle(), getSunPosition(), and update(). |
|
Definition at line 200 of file DayNightCycle.h. Referenced by DayNightCycle(), and update(). |
|
Definition at line 213 of file DayNightCycle.h. Referenced by DayNightCycle(), setToDay(), setToNight(), and update(). |
|
Definition at line 207 of file DayNightCycle.h. Referenced by update(). |
|
Definition at line 208 of file DayNightCycle.h. Referenced by update(). |
|
Definition at line 206 of file DayNightCycle.h. Referenced by setToDay(), and update(). |
|
Definition at line 205 of file DayNightCycle.h. Referenced by setToNight(), and update(). |