1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 13:19:40 +00:00

Sun trajectory: handle mNightStart <= mSunriseTime

OMW Bug #781
Note:  mNightStart == mSunriseTime is treated as 24-hour night.
This commit is contained in:
Jordan Ayers 2015-02-08 14:26:38 -06:00
parent 23024d2beb
commit ec3487b669

View file

@ -429,30 +429,32 @@ void WeatherManager::update(float duration, bool paused)
else else
mRendering->getSkyManager()->sunEnable(); mRendering->getSkyManager()->sunEnable();
// Update the sun direction. Run it east to west at 15 degrees south from overhead. // Update the sun direction. Run it east to west at a fixed angle from overhead.
// The sun's speed at day and night will differ, since mSunriseTime and mNightStart // The sun's speed at day and night may differ, since mSunriseTime and mNightStart
// mark when the sun is level with the horizon. // 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 adjustedHour = mHour;
float adjustedNightStart = mNightStart;
if ( mHour < mSunriseTime ) if ( mHour < mSunriseTime )
adjustedHour += 24.f; adjustedHour += 24.f;
if ( mNightStart < mSunriseTime )
adjustedNightStart += 24.f;
const bool is_night = mHour >= mNightStart || mHour <= mSunriseTime; const bool is_night = adjustedHour >= adjustedNightStart;
const float dayDuration = mNightStart - mSunriseTime; const float dayDuration = adjustedNightStart - mSunriseTime;
const float nightDuration = 24.f - dayDuration; const float nightDuration = 24.f - dayDuration;
double theta; double theta;
if ( !is_night ) { if ( !is_night ) {
theta = M_PI * (adjustedHour - mSunriseTime) / dayDuration; theta = M_PI * (adjustedHour - mSunriseTime) / dayDuration;
} else { } else {
theta = M_PI * (adjustedHour - mNightStart) / nightDuration; theta = M_PI * (adjustedHour - adjustedNightStart) / nightDuration;
} }
Vector3 final( Vector3 final(
cos( theta ), cos( theta ),
-0.268, // approx tan( 15 degrees ) -0.268f, // approx tan( -15 degrees )
sin( theta ) ); sin( theta ) );
mRendering->setSunDirection( final, is_night ); mRendering->setSunDirection( final, is_night );
} }