forked from teamnwah/openmw-tes3coop
Sun trajectory: handle mNightStart <= mSunriseTime
OMW Bug #781 Note: mNightStart == mSunriseTime is treated as 24-hour night.
This commit is contained in:
parent
23024d2beb
commit
ec3487b669
1 changed files with 10 additions and 8 deletions
|
@ -429,30 +429,32 @@ void WeatherManager::update(float duration, bool paused)
|
|||
else
|
||||
mRendering->getSkyManager()->sunEnable();
|
||||
|
||||
// Update the sun direction. Run it east to west at 15 degrees south from overhead.
|
||||
// The sun's speed at day and night will differ, since mSunriseTime and mNightStart
|
||||
// Update the sun direction. Run it east to west at a fixed angle from overhead.
|
||||
// The sun's speed at day and night may differ, since mSunriseTime and mNightStart
|
||||
// mark when the sun is level with the horizon.
|
||||
{
|
||||
assert( mNightStart > mSunriseTime );
|
||||
|
||||
// Shift times into a 24-hour window beginning at mSunriseTime...
|
||||
float adjustedHour = mHour;
|
||||
float adjustedNightStart = mNightStart;
|
||||
if ( mHour < mSunriseTime )
|
||||
adjustedHour += 24.f;
|
||||
if ( mNightStart < mSunriseTime )
|
||||
adjustedNightStart += 24.f;
|
||||
|
||||
const bool is_night = mHour >= mNightStart || mHour <= mSunriseTime;
|
||||
const float dayDuration = mNightStart - mSunriseTime;
|
||||
const bool is_night = adjustedHour >= adjustedNightStart;
|
||||
const float dayDuration = adjustedNightStart - mSunriseTime;
|
||||
const float nightDuration = 24.f - dayDuration;
|
||||
|
||||
double theta;
|
||||
if ( !is_night ) {
|
||||
theta = M_PI * (adjustedHour - mSunriseTime) / dayDuration;
|
||||
} else {
|
||||
theta = M_PI * (adjustedHour - mNightStart) / nightDuration;
|
||||
theta = M_PI * (adjustedHour - adjustedNightStart) / nightDuration;
|
||||
}
|
||||
|
||||
Vector3 final(
|
||||
cos( theta ),
|
||||
-0.268, // approx tan( 15 degrees )
|
||||
-0.268f, // approx tan( -15 degrees )
|
||||
sin( theta ) );
|
||||
mRendering->setSunDirection( final, is_night );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue