1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 05:53:50 +00:00

Merge remote-tracking branch 'jordan-ayers/bugfix/781'

This commit is contained in:
Marc Zinnschlag 2015-02-09 17:44:16 +01:00
commit 4da98ed2a6
5 changed files with 34 additions and 26 deletions

View file

@ -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), // 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)); 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) void RenderingManager::setGlare(bool glare)

View file

@ -141,7 +141,7 @@ public:
void setAmbientColour(const Ogre::ColourValue& colour); void setAmbientColour(const Ogre::ColourValue& colour);
void setSunColour(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 sunEnable(bool real); ///< @param real whether or not to really disable the sunlight (otherwise just set diffuse to 0)
void sunDisable(bool real); void sunDisable(bool real);

View file

@ -767,14 +767,14 @@ void SkyManager::setStormDirection(const Vector3 &direction)
mStormDirection = direction; mStormDirection = direction;
} }
void SkyManager::setSunDirection(const Vector3& direction, bool is_moon) void SkyManager::setSunDirection(const Vector3& direction, bool is_night)
{ {
if (!mCreated) return; if (!mCreated) return;
mSun->setPosition(direction); mSun->setPosition(direction);
mSunGlare->setPosition(direction); mSunGlare->setPosition(direction);
float height = direction.z; 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<sh::Vector2>(new sh::Vector2(fade, height))); sh::Factory::getInstance ().setSharedParameter ("waterSunFade_sunHeight", sh::makeProperty<sh::Vector2>(new sh::Vector2(fade, height)));
} }

View file

@ -153,7 +153,7 @@ namespace MWRender
void setStormDirection(const Ogre::Vector3& direction); 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); void setMasserDirection(const Ogre::Vector3& direction);

View file

@ -1,5 +1,7 @@
#include "weather.hpp" #include "weather.hpp"
#include <cmath>
#include <components/esm/weatherstate.hpp> #include <components/esm/weatherstate.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
@ -427,29 +429,35 @@ void WeatherManager::update(float duration, bool paused)
else else
mRendering->getSkyManager()->sunEnable(); mRendering->getSkyManager()->sunEnable();
// sun angle // Update the sun direction. Run it east to west at a fixed angle from overhead.
float height; // The sun's speed at day and night may differ, since mSunriseTime and mNightStart
// mark when the sun is level with the horizon.
{
// 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;
//Day duration const bool is_night = adjustedHour >= adjustedNightStart;
float dayDuration = (mNightStart - 1) - mSunriseTime; const float dayDuration = adjustedNightStart - mSunriseTime;
const float nightDuration = 24.f - dayDuration;
// rise at 6, set at 20 double theta;
if (mHour >= mSunriseTime && mHour <= mNightStart) if ( !is_night ) {
height = 1 - std::abs(((mHour - dayDuration) / 7.f)); theta = M_PI * (adjustedHour - mSunriseTime) / dayDuration;
else if (mHour > mNightStart) } else {
height = (mHour - mNightStart) / 4.f; theta = M_PI * (adjustedHour - adjustedNightStart) / nightDuration;
else //if (mHour > 0 && mHour < 6) }
height = 1 - (mHour / mSunriseTime);
int facing = (mHour > 13.f) ? 1 : -1; Vector3 final(
cos( theta ),
bool sun_is_moon = mHour >= mNightStart || mHour <= mSunriseTime; -0.268f, // approx tan( -15 degrees )
sin( theta ) );
Vector3 final( mRendering->setSunDirection( final, is_night );
(height - 1) * facing, }
(height - 1) * facing,
height);
mRendering->setSunDirection(final, sun_is_moon);
/* /*
* TODO: import separated fadeInStart/Finish, fadeOutStart/Finish * TODO: import separated fadeInStart/Finish, fadeOutStart/Finish