mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +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)
|
||||
{
|
||||
if (mSun) mSun->setPosition(direction);
|
||||
mSkyManager->setSunDirection(direction);
|
||||
}
|
||||
|
||||
void RenderingManager::setGlare(bool glare)
|
||||
|
|
|
@ -39,7 +39,10 @@ void BillboardObject::setVisible(const bool visible)
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
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);
|
||||
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);
|
||||
mMasser->setType(Moon::Type_Masser);
|
||||
mSecunda->setType(Moon::Type_Secunda);
|
||||
|
@ -517,10 +520,30 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
|||
|
||||
void SkyManager::setGlare(bool glare)
|
||||
{
|
||||
mSunGlare->setVisible(glare && mEnabled);
|
||||
mGlareEnabled = glare;
|
||||
}
|
||||
|
||||
Vector3 SkyManager::getRealSunPos()
|
||||
{
|
||||
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 sunEnable();
|
||||
|
||||
void sunDisable();
|
||||
|
||||
void setSunDirection(const Ogre::Vector3& direction);
|
||||
|
||||
void setGlare(bool glare);
|
||||
Ogre::Vector3 getRealSunPos();
|
||||
|
||||
|
@ -163,6 +169,8 @@ namespace MWRender
|
|||
void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType);
|
||||
|
||||
bool mEnabled;
|
||||
bool mGlareEnabled;
|
||||
bool mSunEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ WeatherResult WeatherManager::getResult(const String& weather)
|
|||
result.mGlareView = current.mGlareView;
|
||||
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
||||
|
||||
const float fade_duration = current.mTransitionDelta;
|
||||
const float fade_duration = 0.15 /*current.mTransitionDelta*/;
|
||||
|
||||
// night
|
||||
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) || mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
|
||||
|
@ -272,6 +272,23 @@ void WeatherManager::update(float duration)
|
|||
mRendering->sunDisable();
|
||||
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)
|
||||
|
|
|
@ -142,9 +142,9 @@ namespace MWWorld
|
|||
{
|
||||
if (mSky)
|
||||
{
|
||||
toggleSky();
|
||||
// TODO set weather
|
||||
toggleSky();
|
||||
mRendering->skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
||||
mRendering->skySetDate (mGlobalVariables->getInt ("day"),
|
||||
mGlobalVariables->getInt ("month"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,10 +452,6 @@ namespace MWWorld
|
|||
else
|
||||
{
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue