From e04100606358f065fc455b883cc253d0f73984af Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 3 Nov 2011 23:47:15 -0400 Subject: [PATCH] Adding light and fog functions --- apps/openmw/mwrender/renderingmanager.cpp | 67 +++++++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 12 +++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 952388fd4..b07251f53 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -154,4 +154,71 @@ bool RenderingManager::toggleRenderMode(int mode){ return mDebugging.toggleRenderMode(mode); } +void RenderingManager::configureFog(ESMS::CellStore &mCell) +{ + Ogre::ColourValue color; + color.setAsABGR (mCell.cell->ambi.fog); + + float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity); + float low = 200; + + rend.getScene()->setFog (FOG_LINEAR, color, 0, low, high); + rend.getCamera()->setFarClipDistance (high + 10); + rend.getViewport()->setBackgroundColour (color); +} + +void RenderingManager::setAmbientMode() +{ + switch (mAmbientMode) + { + case 0: + + rend.getScene()->setAmbientLight(mAmbientColor); + break; + + case 1: + + rend.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1)); + break; + + case 2: + + rend.getScene()->setAmbientLight(ColourValue(1,1,1)); + break; + } +} + +void RenderingManager::configureAmbient(ESMS::CellStore &mCell) +{ + mAmbientColor.setAsABGR (mCell.cell->ambi.ambient); + setAmbientMode(); + + // Create a "sun" that shines light downwards. It doesn't look + // completely right, but leave it for now. + Ogre::Light *light = rend.getScene()->createLight(); + Ogre::ColourValue colour; + colour.setAsABGR (mCell.cell->ambi.sunlight); + light->setDiffuseColour (colour); + light->setType(Ogre::Light::LT_DIRECTIONAL); + light->setDirection(0,-1,0); +} +// Switch through lighting modes. + +void RenderingManager::toggleLight() +{ + if (mAmbientMode==2) + mAmbientMode = 0; + else + ++mAmbientMode; + + switch (mAmbientMode) + { + case 0: std::cout << "Setting lights to normal\n"; break; + case 1: std::cout << "Turning the lights up\n"; break; + case 2: std::cout << "Turning the lights to full\n"; break; + } + + setAmbientMode(); +} + } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index e8989d740..0d2375feb 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -57,6 +57,8 @@ class RenderingManager: private RenderingInterface { virtual MWRender::Creatures& getCreatures(); virtual MWRender::Objects& getObjects(); virtual MWRender::Player& getPlayer(); + + void toggleLight(); bool toggleRenderMode(int mode); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? @@ -86,7 +88,10 @@ class RenderingManager: private RenderingInterface { Ogre::SceneNode *getRoot() { return mwRoot; } private: - + void configureAmbient(ESMS::CellStore &mCell); + /// configure fog according to cell + void configureFog(ESMS::CellStore &mCell); + void setAmbientMode(); SkyManager* mSkyManager; OEngine::Render::OgreRenderer &rend; Ogre::Camera* camera; @@ -94,6 +99,11 @@ class RenderingManager: private RenderingInterface { MWRender::Creatures creatures; MWRender::Objects objects; + // 0 normal, 1 more bright, 2 max + int mAmbientMode; + + Ogre::ColourValue mAmbientColor; + /// Root node for all objects added to the scene. This is rotated so /// that the OGRE coordinate system matches that used internally in /// Morrowind.