From 2d17eaa5ea5ad5e57928649cf0553f01a8413e20 Mon Sep 17 00:00:00 2001 From: Jordan Ayers Date: Fri, 6 Feb 2015 19:21:40 -0600 Subject: [PATCH 1/3] Fix argument name for setSunDirection. --- apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- apps/openmw/mwrender/renderingmanager.hpp | 2 +- apps/openmw/mwrender/sky.cpp | 4 ++-- apps/openmw/mwrender/sky.hpp | 2 +- apps/openmw/mwworld/weather.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 3ffd787c7..3e95648c4 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -630,12 +630,12 @@ void RenderingManager::sunDisable(bool real) } } -void RenderingManager::setSunDirection(const Ogre::Vector3& direction, bool is_moon) +void RenderingManager::setSunDirection(const Ogre::Vector3& direction, bool is_night) { // direction * -1 (because 'direction' is camera to sun vector and not sun to camera), if (mSun) mSun->setDirection(Vector3(-direction.x, -direction.y, -direction.z)); - mSkyManager->setSunDirection(direction, is_moon); + mSkyManager->setSunDirection(direction, is_night); } void RenderingManager::setGlare(bool glare) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index d4b85133d..9f029c1b9 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -141,7 +141,7 @@ public: void setAmbientColour(const Ogre::ColourValue& colour); void setSunColour(const Ogre::ColourValue& colour); - void setSunDirection(const Ogre::Vector3& direction, bool is_moon); + void setSunDirection(const Ogre::Vector3& direction, bool is_night); void sunEnable(bool real); ///< @param real whether or not to really disable the sunlight (otherwise just set diffuse to 0) void sunDisable(bool real); diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 454ed8820..f6287de5e 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -767,14 +767,14 @@ void SkyManager::setStormDirection(const Vector3 &direction) mStormDirection = direction; } -void SkyManager::setSunDirection(const Vector3& direction, bool is_moon) +void SkyManager::setSunDirection(const Vector3& direction, bool is_night) { if (!mCreated) return; mSun->setPosition(direction); mSunGlare->setPosition(direction); float height = direction.z; - float fade = is_moon ? 0.0 : (( height > 0.5) ? 1.0 : height * 2); + float fade = is_night ? 0.0 : (( height > 0.5) ? 1.0 : height * 2); sh::Factory::getInstance ().setSharedParameter ("waterSunFade_sunHeight", sh::makeProperty(new sh::Vector2(fade, height))); } diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 70251f490..6950dbab3 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -153,7 +153,7 @@ namespace MWRender void setStormDirection(const Ogre::Vector3& direction); - void setSunDirection(const Ogre::Vector3& direction, bool is_moon); + void setSunDirection(const Ogre::Vector3& direction, bool is_night); void setMasserDirection(const Ogre::Vector3& direction); diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index a74c24768..a893b657a 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -443,13 +443,13 @@ void WeatherManager::update(float duration, bool paused) int facing = (mHour > 13.f) ? 1 : -1; - bool sun_is_moon = mHour >= mNightStart || mHour <= mSunriseTime; + bool is_night = mHour >= mNightStart || mHour <= mSunriseTime; Vector3 final( (height - 1) * facing, (height - 1) * facing, height); - mRendering->setSunDirection(final, sun_is_moon); + mRendering->setSunDirection(final, is_night); /* * TODO: import separated fadeInStart/Finish, fadeOutStart/Finish From 23024d2bebc2a376b062b2bbe94bfe880f9e975d Mon Sep 17 00:00:00 2001 From: Jordan Ayers Date: Sat, 7 Feb 2015 12:36:27 -0600 Subject: [PATCH 2/3] Re-work the sun's trajectory. OMW Bug #781 Have the sun travel 15 degrees south of vertical. --- apps/openmw/mwworld/weather.cpp | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index a893b657a..dcd8e5a11 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -1,5 +1,7 @@ #include "weather.hpp" +#include + #include #include "../mwbase/environment.hpp" @@ -427,29 +429,33 @@ void WeatherManager::update(float duration, bool paused) else mRendering->getSkyManager()->sunEnable(); - // sun angle - float height; + // 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 + // mark when the sun is level with the horizon. + { + assert( mNightStart > mSunriseTime ); - //Day duration - float dayDuration = (mNightStart - 1) - mSunriseTime; + float adjustedHour = mHour; + if ( mHour < mSunriseTime ) + adjustedHour += 24.f; - // rise at 6, set at 20 - if (mHour >= mSunriseTime && mHour <= mNightStart) - height = 1 - std::abs(((mHour - dayDuration) / 7.f)); - else if (mHour > mNightStart) - height = (mHour - mNightStart) / 4.f; - else //if (mHour > 0 && mHour < 6) - height = 1 - (mHour / mSunriseTime); + const bool is_night = mHour >= mNightStart || mHour <= mSunriseTime; + const float dayDuration = mNightStart - mSunriseTime; + const float nightDuration = 24.f - dayDuration; - int facing = (mHour > 13.f) ? 1 : -1; + double theta; + if ( !is_night ) { + theta = M_PI * (adjustedHour - mSunriseTime) / dayDuration; + } else { + theta = M_PI * (adjustedHour - mNightStart) / nightDuration; + } - bool is_night = mHour >= mNightStart || mHour <= mSunriseTime; - - Vector3 final( - (height - 1) * facing, - (height - 1) * facing, - height); - mRendering->setSunDirection(final, is_night); + Vector3 final( + cos( theta ), + -0.268, // approx tan( 15 degrees ) + sin( theta ) ); + mRendering->setSunDirection( final, is_night ); + } /* * TODO: import separated fadeInStart/Finish, fadeOutStart/Finish From ec3487b669c35e9df8260fa66f0c2f8de904cf5e Mon Sep 17 00:00:00 2001 From: Jordan Ayers Date: Sun, 8 Feb 2015 14:26:38 -0600 Subject: [PATCH 3/3] Sun trajectory: handle mNightStart <= mSunriseTime OMW Bug #781 Note: mNightStart == mSunriseTime is treated as 24-hour night. --- apps/openmw/mwworld/weather.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index dcd8e5a11..7a36d6ac7 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -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 ); }