mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 08:45:34 +00:00
calculate a sun position depending on time of day
This commit is contained in:
parent
811c4a41b7
commit
67c7b965f0
5 changed files with 56 additions and 11 deletions
|
@ -303,6 +303,7 @@ void RenderingManager::sunDisable()
|
||||||
void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
|
void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
|
||||||
{
|
{
|
||||||
if (mSun) mSun->setPosition(direction);
|
if (mSun) mSun->setPosition(direction);
|
||||||
|
mSkyManager->setSunDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::setGlare(bool glare)
|
void RenderingManager::setGlare(bool glare)
|
||||||
|
|
|
@ -39,7 +39,10 @@ void BillboardObject::setVisible(const bool visible)
|
||||||
|
|
||||||
void BillboardObject::setPosition(const Vector3& pPosition)
|
void BillboardObject::setPosition(const Vector3& pPosition)
|
||||||
{
|
{
|
||||||
Vector3 finalPosition = pPosition.normalisedCopy() * CELESTIAL_BODY_DISTANCE;
|
Vector3 normalised = pPosition.normalisedCopy();
|
||||||
|
Vector3 finalPosition = normalised * CELESTIAL_BODY_DISTANCE;
|
||||||
|
|
||||||
|
mBBSet->setCommonDirection( -normalised );
|
||||||
|
|
||||||
mNode->setPosition(finalPosition);
|
mNode->setPosition(finalPosition);
|
||||||
}
|
}
|
||||||
|
@ -284,7 +287,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera)
|
||||||
mSun = new BillboardObject("textures\\tx_sun_05.dds", 1, Vector3(0.4, 0.4, 0.4), mRootNode);
|
mSun = new BillboardObject("textures\\tx_sun_05.dds", 1, Vector3(0.4, 0.4, 0.4), mRootNode);
|
||||||
mSunGlare = new BillboardObject("textures\\tx_sun_flash_grey_05.dds", 3, Vector3(0.4, 0.4, 0.4), mRootNode);
|
mSunGlare = new BillboardObject("textures\\tx_sun_flash_grey_05.dds", 3, Vector3(0.4, 0.4, 0.4), mRootNode);
|
||||||
mSunGlare->setRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
mSunGlare->setRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
||||||
mMasser = new Moon("textures\\tx_masser_full.dds", 1, Vector3(-0.4, -0.4, 0.5), mRootNode);
|
mMasser = new Moon("textures\\tx_masser_full.dds", 1, Vector3(-0.4, 0.4, 0.5), mRootNode);
|
||||||
mSecunda = new Moon("textures\\tx_secunda_full.dds", 0.5, Vector3(0.4, -0.4, 0.5), mRootNode);
|
mSecunda = new Moon("textures\\tx_secunda_full.dds", 0.5, Vector3(0.4, -0.4, 0.5), mRootNode);
|
||||||
mMasser->setType(Moon::Type_Masser);
|
mMasser->setType(Moon::Type_Masser);
|
||||||
mSecunda->setType(Moon::Type_Secunda);
|
mSecunda->setType(Moon::Type_Secunda);
|
||||||
|
@ -517,10 +520,30 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
||||||
|
|
||||||
void SkyManager::setGlare(bool glare)
|
void SkyManager::setGlare(bool glare)
|
||||||
{
|
{
|
||||||
mSunGlare->setVisible(glare && mEnabled);
|
mGlareEnabled = glare;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 SkyManager::getRealSunPos()
|
Vector3 SkyManager::getRealSunPos()
|
||||||
{
|
{
|
||||||
return mSun->getNode()->_getDerivedPosition();
|
return mSun->getNode()->_getDerivedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkyManager::sunEnable()
|
||||||
|
{
|
||||||
|
mSun->setVisible(true);
|
||||||
|
mSunGlare->setVisible(mGlareEnabled);
|
||||||
|
mSunEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkyManager::sunDisable()
|
||||||
|
{
|
||||||
|
mSun->setVisible(false);
|
||||||
|
mSunGlare->setVisible(false);
|
||||||
|
mSunEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkyManager::setSunDirection(const Vector3& direction)
|
||||||
|
{
|
||||||
|
mSun->setPosition(direction);
|
||||||
|
mSunGlare->setPosition(direction);
|
||||||
|
}
|
||||||
|
|
|
@ -130,6 +130,12 @@ namespace MWRender
|
||||||
|
|
||||||
void setWeather(const MWWorld::WeatherResult& weather);
|
void setWeather(const MWWorld::WeatherResult& weather);
|
||||||
|
|
||||||
|
void sunEnable();
|
||||||
|
|
||||||
|
void sunDisable();
|
||||||
|
|
||||||
|
void setSunDirection(const Ogre::Vector3& direction);
|
||||||
|
|
||||||
void setGlare(bool glare);
|
void setGlare(bool glare);
|
||||||
Ogre::Vector3 getRealSunPos();
|
Ogre::Vector3 getRealSunPos();
|
||||||
|
|
||||||
|
@ -163,6 +169,8 @@ namespace MWRender
|
||||||
void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType);
|
void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType);
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
|
bool mGlareEnabled;
|
||||||
|
bool mSunEnabled;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ WeatherResult WeatherManager::getResult(const String& weather)
|
||||||
result.mGlareView = current.mGlareView;
|
result.mGlareView = current.mGlareView;
|
||||||
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
||||||
|
|
||||||
const float fade_duration = current.mTransitionDelta;
|
const float fade_duration = 0.15 /*current.mTransitionDelta*/;
|
||||||
|
|
||||||
// night
|
// night
|
||||||
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) || mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
|
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) || mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
|
||||||
|
@ -272,6 +272,23 @@ void WeatherManager::update(float duration)
|
||||||
mRendering->sunDisable();
|
mRendering->sunDisable();
|
||||||
mRendering->skyDisable();
|
mRendering->skyDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disable sun during night
|
||||||
|
if (mHour >= mGlobals.mSunsetTime+mGlobals.mSunsetDuration || mHour <= mGlobals.mSunriseTime-mGlobals.mSunriseDuration)
|
||||||
|
mRendering->getSkyManager()->sunDisable();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// during day, calculate sun angle
|
||||||
|
float height = 1-std::abs(((mHour-13)/7.f));
|
||||||
|
int facing = mHour > 13.f ? 1 : -1;
|
||||||
|
Vector3 final(
|
||||||
|
(1-height)*facing,
|
||||||
|
(1-height)*facing,
|
||||||
|
height);
|
||||||
|
mRendering->setSunDirection(final);
|
||||||
|
|
||||||
|
mRendering->getSkyManager()->sunEnable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeatherManager::setHour(const float hour)
|
void WeatherManager::setHour(const float hour)
|
||||||
|
|
|
@ -142,9 +142,9 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
if (mSky)
|
if (mSky)
|
||||||
{
|
{
|
||||||
toggleSky();
|
mRendering->skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
||||||
// TODO set weather
|
mRendering->skySetDate (mGlobalVariables->getInt ("day"),
|
||||||
toggleSky();
|
mGlobalVariables->getInt ("month"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,10 +452,6 @@ namespace MWWorld
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSky = true;
|
mSky = true;
|
||||||
// TODO check for extorior or interior with sky.
|
|
||||||
mRendering->skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
|
||||||
mRendering->skySetDate (mGlobalVariables->getInt ("day"),
|
|
||||||
mGlobalVariables->getInt ("month"));
|
|
||||||
mRendering->skyEnable();
|
mRendering->skyEnable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue