From b73947033d2ca0494da5d4b56c8b592b4b02bc2d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 16 Jun 2015 16:33:31 +0200 Subject: [PATCH] Rotate sky meshes --- apps/openmw/mwrender/sky.cpp | 75 +++++++++++++++++++----------------- apps/openmw/mwrender/sky.hpp | 6 ++- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 0cd1f64d2..07e433208 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -204,20 +204,6 @@ public: } }; -class DisableCullingVisitor : public osg::NodeVisitor -{ -public: - DisableCullingVisitor() - : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) - { - } - - void apply(osg::Geode &geode) - { - geode.setCullingActive(false); - } -}; - class ModVertexAlphaVisitor : public osg::NodeVisitor { public: @@ -483,6 +469,7 @@ private: SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) : mSceneManager(sceneManager) + , mAtmosphereNightRoll(0.f) , mCreated(false) , mMoonRed(false) , mIsStorm(false) @@ -528,14 +515,18 @@ void SkyManager::create() mAtmosphereUpdater = new AtmosphereUpdater; mAtmosphereDay->addUpdateCallback(mAtmosphereUpdater); + mAtmosphereNightNode = new osg::PositionAttitudeTransform; + mAtmosphereNightNode->setNodeMask(0); + mRootNode->addChild(mAtmosphereNightNode); + + osg::ref_ptr atmosphereNight; if (mSceneManager->getVFS()->exists("meshes/sky_night_02.nif")) - mAtmosphereNight = mSceneManager->createInstance("meshes/sky_night_02.nif", mRootNode); + atmosphereNight = mSceneManager->createInstance("meshes/sky_night_02.nif", mAtmosphereNightNode); else - mAtmosphereNight = mSceneManager->createInstance("meshes/sky_night_01.nif", mRootNode); - mAtmosphereNight->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + atmosphereNight = mSceneManager->createInstance("meshes/sky_night_01.nif", mAtmosphereNightNode); + atmosphereNight->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); ModVertexAlphaVisitor modStars(2); - mAtmosphereNight->accept(modStars); - mAtmosphereNight->setNodeMask(0); + atmosphereNight->accept(modStars); mSun.reset(new Sun(mRootNode, mSceneManager)); @@ -543,14 +534,16 @@ void SkyManager::create() mMasser.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Masser_Size")/100, Moon::Type_Masser)); mSecunda.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Secunda_Size")/100, Moon::Type_Secunda)); - mCloudNode = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mRootNode); + mCloudNode = new osg::PositionAttitudeTransform; + mRootNode->addChild(mCloudNode); + osg::ref_ptr clouds = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mCloudNode); ModVertexAlphaVisitor modClouds(1); - mCloudNode->accept(modClouds); + clouds->accept(modClouds); mCloudUpdater = new CloudUpdater; - mCloudNode->addUpdateCallback(mCloudUpdater); + clouds->addUpdateCallback(mCloudUpdater); - mCloudNode->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + clouds->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); osg::ref_ptr depth = new osg::Depth; depth->setWriteMask(false); @@ -594,12 +587,18 @@ void SkyManager::updateRain(float dt) void SkyManager::update(float duration) { if (!mEnabled) return; - //const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); - //if (mIsStorm) - // mCloudNode->setOrientation(Ogre::Vector3::UNIT_Y.getRotationTo(mStormDirection)); - //else - // mCloudNode->setOrientation(Ogre::Quaternion::IDENTITY); + if (mIsStorm) + { + osg::Quat quat; + quat.makeRotate(osg::Vec3f(0,1,0), mStormDirection); + + if (mParticleNode) + mParticleNode->setAttitude(quat); + mCloudNode->setAttitude(quat); + } + else + mCloudNode->setAttitude(osg::Quat()); updateRain(duration); @@ -611,6 +610,7 @@ void SkyManager::update(float duration) mMasser->setPhase( static_cast( (int) ((mDay % 32)/4.f)) ); mSecunda->setPhase ( static_cast( (int) ((mDay % 32)/4.f)) ); + //const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); //mSecunda->setColour ( mMoonRed ? fallback->getFallbackColour("Moons_Script_Color") : ColourValue(1,1,1,1)); //mMasser->setColour (ColourValue(1,1,1,1)); @@ -641,7 +641,9 @@ void SkyManager::update(float duration) } // rotate the stars by 360 degrees every 4 days - //mAtmosphereNight->roll(Degree(MWBase::Environment::get().getWorld()->getTimeScaleFactor()*duration*360 / (3600*96.f))); + mAtmosphereNightRoll += MWBase::Environment::get().getWorld()->getTimeScaleFactor()*duration*osg::DegreesToRadians(360.f) / (3600*96.f); + if (mAtmosphereNightNode->getNodeMask() != 0) + mAtmosphereNightNode->setAttitude(osg::Quat(mAtmosphereNightRoll, osg::Vec3f(0,0,1))); } void SkyManager::setEnabled(bool enabled) @@ -678,15 +680,18 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) if (mCurrentParticleEffect.empty()) { - if (mParticleEffect) - mRootNode->removeChild(mParticleEffect); + if (mParticleNode) + mRootNode->removeChild(mParticleNode); mParticleEffect = NULL; } else { - mParticleEffect = mSceneManager->createInstance(mCurrentParticleEffect, mRootNode); - DisableCullingVisitor visitor; - mParticleEffect->accept(visitor); + if (!mParticleNode) + { + mParticleNode = new osg::PositionAttitudeTransform; + mRootNode->addChild(mParticleNode); + } + mParticleEffect = mSceneManager->createInstance(mCurrentParticleEffect, mParticleNode); SceneUtil::AssignControllerSourcesVisitor assignVisitor(boost::shared_ptr(new SceneUtil::FrameTimeSource)); mParticleEffect->accept(assignVisitor); @@ -757,7 +762,7 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) } } - //mAtmosphereNight->setNodeMask((weather.mNight && mEnabled) ? ~0 : 0); + mAtmosphereNightNode->setNodeMask(weather.mNight ? ~0 : 0); /* diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index d7cd88de5..e11f20c18 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -93,15 +93,17 @@ namespace MWRender osg::ref_ptr mRootNode; + osg::ref_ptr mParticleNode; osg::ref_ptr mParticleEffect; - osg::ref_ptr mCloudNode; + osg::ref_ptr mCloudNode; osg::ref_ptr mCloudUpdater; osg::ref_ptr mAtmosphereDay; - osg::ref_ptr mAtmosphereNight; + osg::ref_ptr mAtmosphereNightNode; + float mAtmosphereNightRoll; osg::ref_ptr mAtmosphereUpdater;