Rotate sky meshes

c++11
scrawl 10 years ago
parent 2d072aab2d
commit b73947033d

@ -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 class ModVertexAlphaVisitor : public osg::NodeVisitor
{ {
public: public:
@ -483,6 +469,7 @@ private:
SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager)
: mSceneManager(sceneManager) : mSceneManager(sceneManager)
, mAtmosphereNightRoll(0.f)
, mCreated(false) , mCreated(false)
, mMoonRed(false) , mMoonRed(false)
, mIsStorm(false) , mIsStorm(false)
@ -528,14 +515,18 @@ void SkyManager::create()
mAtmosphereUpdater = new AtmosphereUpdater; mAtmosphereUpdater = new AtmosphereUpdater;
mAtmosphereDay->addUpdateCallback(mAtmosphereUpdater); mAtmosphereDay->addUpdateCallback(mAtmosphereUpdater);
mAtmosphereNightNode = new osg::PositionAttitudeTransform;
mAtmosphereNightNode->setNodeMask(0);
mRootNode->addChild(mAtmosphereNightNode);
osg::ref_ptr<osg::Node> atmosphereNight;
if (mSceneManager->getVFS()->exists("meshes/sky_night_02.nif")) 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 else
mAtmosphereNight = mSceneManager->createInstance("meshes/sky_night_01.nif", mRootNode); atmosphereNight = mSceneManager->createInstance("meshes/sky_night_01.nif", mAtmosphereNightNode);
mAtmosphereNight->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); atmosphereNight->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
ModVertexAlphaVisitor modStars(2); ModVertexAlphaVisitor modStars(2);
mAtmosphereNight->accept(modStars); atmosphereNight->accept(modStars);
mAtmosphereNight->setNodeMask(0);
mSun.reset(new Sun(mRootNode, mSceneManager)); 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)); 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)); 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<osg::Node> clouds = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mCloudNode);
ModVertexAlphaVisitor modClouds(1); ModVertexAlphaVisitor modClouds(1);
mCloudNode->accept(modClouds); clouds->accept(modClouds);
mCloudUpdater = new CloudUpdater; 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<osg::Depth> depth = new osg::Depth; osg::ref_ptr<osg::Depth> depth = new osg::Depth;
depth->setWriteMask(false); depth->setWriteMask(false);
@ -594,12 +587,18 @@ void SkyManager::updateRain(float dt)
void SkyManager::update(float duration) void SkyManager::update(float duration)
{ {
if (!mEnabled) return; if (!mEnabled) return;
//const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback();
//if (mIsStorm) if (mIsStorm)
// mCloudNode->setOrientation(Ogre::Vector3::UNIT_Y.getRotationTo(mStormDirection)); {
//else osg::Quat quat;
// mCloudNode->setOrientation(Ogre::Quaternion::IDENTITY); quat.makeRotate(osg::Vec3f(0,1,0), mStormDirection);
if (mParticleNode)
mParticleNode->setAttitude(quat);
mCloudNode->setAttitude(quat);
}
else
mCloudNode->setAttitude(osg::Quat());
updateRain(duration); updateRain(duration);
@ -611,6 +610,7 @@ void SkyManager::update(float duration)
mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) ); mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) ); mSecunda->setPhase ( static_cast<Moon::Phase>( (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)); //mSecunda->setColour ( mMoonRed ? fallback->getFallbackColour("Moons_Script_Color") : ColourValue(1,1,1,1));
//mMasser->setColour (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 // 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) void SkyManager::setEnabled(bool enabled)
@ -678,15 +680,18 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
if (mCurrentParticleEffect.empty()) if (mCurrentParticleEffect.empty())
{ {
if (mParticleEffect) if (mParticleNode)
mRootNode->removeChild(mParticleEffect); mRootNode->removeChild(mParticleNode);
mParticleEffect = NULL; mParticleEffect = NULL;
} }
else else
{ {
mParticleEffect = mSceneManager->createInstance(mCurrentParticleEffect, mRootNode); if (!mParticleNode)
DisableCullingVisitor visitor; {
mParticleEffect->accept(visitor); mParticleNode = new osg::PositionAttitudeTransform;
mRootNode->addChild(mParticleNode);
}
mParticleEffect = mSceneManager->createInstance(mCurrentParticleEffect, mParticleNode);
SceneUtil::AssignControllerSourcesVisitor assignVisitor(boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource)); SceneUtil::AssignControllerSourcesVisitor assignVisitor(boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource));
mParticleEffect->accept(assignVisitor); 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);
/* /*

@ -93,15 +93,17 @@ namespace MWRender
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mParticleNode;
osg::ref_ptr<osg::Node> mParticleEffect; osg::ref_ptr<osg::Node> mParticleEffect;
osg::ref_ptr<osg::Node> mCloudNode; osg::ref_ptr<osg::PositionAttitudeTransform> mCloudNode;
osg::ref_ptr<CloudUpdater> mCloudUpdater; osg::ref_ptr<CloudUpdater> mCloudUpdater;
osg::ref_ptr<osg::Node> mAtmosphereDay; osg::ref_ptr<osg::Node> mAtmosphereDay;
osg::ref_ptr<osg::Node> mAtmosphereNight; osg::ref_ptr<osg::PositionAttitudeTransform> mAtmosphereNightNode;
float mAtmosphereNightRoll;
osg::ref_ptr<AtmosphereUpdater> mAtmosphereUpdater; osg::ref_ptr<AtmosphereUpdater> mAtmosphereUpdater;

Loading…
Cancel
Save