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:
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
|
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 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue