From 9746f8bd32487c3de66bec834072c012454ca7ad Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 26 Mar 2014 17:59:42 +0100 Subject: [PATCH] added night lighting mode --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/render/lightingnight.cpp | 36 +++++++++++++++++++++++ apps/opencs/view/render/lightingnight.hpp | 31 +++++++++++++++++++ apps/opencs/view/render/scenewidget.cpp | 2 ++ apps/opencs/view/render/scenewidget.hpp | 2 ++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/view/render/lightingnight.cpp create mode 100644 apps/opencs/view/render/lightingnight.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 608f01d12..a6200062d 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -69,7 +69,7 @@ opencs_units (view/render ) opencs_units_noqt (view/render - navigation navigation1st navigationfree navigationorbit lighting lightingday + navigation navigation1st navigationfree navigationorbit lighting lightingday lightingnight ) opencs_units_noqt (view/world diff --git a/apps/opencs/view/render/lightingnight.cpp b/apps/opencs/view/render/lightingnight.cpp new file mode 100644 index 000000000..516bb3f40 --- /dev/null +++ b/apps/opencs/view/render/lightingnight.cpp @@ -0,0 +1,36 @@ + +#include "lightingnight.hpp" + +#include + +CSVRender::LightingNight::LightingNight() : mSceneManager (0), mLight (0) {} + +void CSVRender::LightingNight::activate (Ogre::SceneManager *sceneManager, + const Ogre::ColourValue *defaultAmbient) +{ + mSceneManager = sceneManager; + + if (defaultAmbient) + mSceneManager->setAmbientLight (*defaultAmbient); + else + mSceneManager->setAmbientLight (Ogre::ColourValue (0.2, 0.2, 0.2, 1)); + + mLight = mSceneManager->createLight(); + mLight->setType (Ogre::Light::LT_DIRECTIONAL); + mLight->setDirection (Ogre::Vector3 (0, 0, -1)); + mLight->setDiffuseColour (Ogre::ColourValue (0.2, 0.2, 0.2)); +} + +void CSVRender::LightingNight::deactivate() +{ + if (mLight) + { + mSceneManager->destroyLight (mLight); + mLight = 0; + } +} + +void CSVRender::LightingNight::setDefaultAmbient (const Ogre::ColourValue& colour) +{ + mSceneManager->setAmbientLight (colour); +} \ No newline at end of file diff --git a/apps/opencs/view/render/lightingnight.hpp b/apps/opencs/view/render/lightingnight.hpp new file mode 100644 index 000000000..47d1d7ce8 --- /dev/null +++ b/apps/opencs/view/render/lightingnight.hpp @@ -0,0 +1,31 @@ +#ifndef OPENCS_VIEW_LIGHTING_NIGHT_H +#define OPENCS_VIEW_LIGHTING_NIGHT_H + +#include "lighting.hpp" + +namespace Ogre +{ + class Light; +} + +namespace CSVRender +{ + class LightingNight : public Lighting + { + Ogre::SceneManager *mSceneManager; + Ogre::Light *mLight; + + public: + + LightingNight(); + + virtual void activate (Ogre::SceneManager *sceneManager, + const Ogre::ColourValue *defaultAmbient = 0); + + virtual void deactivate(); + + virtual void setDefaultAmbient (const Ogre::ColourValue& colour); + }; +} + +#endif diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 77d9ea1e0..f1371041c 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -345,6 +345,8 @@ namespace CSVRender { if (mode=="day") setLighting (&mLightingDay); + else if (mode=="night") + setLighting (&mLightingNight); } } diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index a1ecd733b..96e7d7bb2 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -6,6 +6,7 @@ #include #include "lightingday.hpp" +#include "lightingnight.hpp" namespace Ogre { @@ -99,6 +100,7 @@ namespace CSVRender Ogre::ColourValue mDefaultAmbient; bool mHasDefaultAmbient; LightingDay mLightingDay; + LightingNight mLightingNight; private slots: