From fa29942b27bc44c0f3e9ce8c97f250541d66d3b7 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Wed, 26 Mar 2014 17:47:56 +0100
Subject: [PATCH] added day lighting mode

---
 apps/opencs/CMakeLists.txt              |  2 +-
 apps/opencs/view/render/lightingday.cpp | 36 +++++++++++++++++++++++++
 apps/opencs/view/render/lightingday.hpp | 31 +++++++++++++++++++++
 apps/opencs/view/render/scenewidget.cpp | 19 +++++++------
 apps/opencs/view/render/scenewidget.hpp |  3 +++
 5 files changed, 80 insertions(+), 11 deletions(-)
 create mode 100644 apps/opencs/view/render/lightingday.cpp
 create mode 100644 apps/opencs/view/render/lightingday.hpp

diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt
index ee7887f3e..608f01d12 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
+    navigation navigation1st navigationfree navigationorbit lighting lightingday
     )
 
 opencs_units_noqt (view/world
diff --git a/apps/opencs/view/render/lightingday.cpp b/apps/opencs/view/render/lightingday.cpp
new file mode 100644
index 000000000..ab0257c0c
--- /dev/null
+++ b/apps/opencs/view/render/lightingday.cpp
@@ -0,0 +1,36 @@
+
+#include "lightingday.hpp"
+
+#include <OgreSceneManager.h>
+
+CSVRender::LightingDay::LightingDay() : mSceneManager (0), mLight (0) {}
+
+void CSVRender::LightingDay::activate (Ogre::SceneManager *sceneManager,
+    const Ogre::ColourValue *defaultAmbient)
+{
+    mSceneManager = sceneManager;
+
+    if (defaultAmbient)
+        mSceneManager->setAmbientLight (*defaultAmbient);
+    else
+        mSceneManager->setAmbientLight (Ogre::ColourValue (0.7, 0.7, 0.7, 1));
+
+    mLight = mSceneManager->createLight();
+    mLight->setType (Ogre::Light::LT_DIRECTIONAL);
+    mLight->setDirection (Ogre::Vector3 (0, 0, -1));
+    mLight->setDiffuseColour (Ogre::ColourValue (1, 1, 1));
+}
+
+void CSVRender::LightingDay::deactivate()
+{
+    if (mLight)
+    {
+        mSceneManager->destroyLight (mLight);
+        mLight = 0;
+    }
+}
+
+void CSVRender::LightingDay::setDefaultAmbient (const Ogre::ColourValue& colour)
+{
+    mSceneManager->setAmbientLight (colour);
+}
\ No newline at end of file
diff --git a/apps/opencs/view/render/lightingday.hpp b/apps/opencs/view/render/lightingday.hpp
new file mode 100644
index 000000000..8638146e2
--- /dev/null
+++ b/apps/opencs/view/render/lightingday.hpp
@@ -0,0 +1,31 @@
+#ifndef OPENCS_VIEW_LIGHTING_DAY_H
+#define OPENCS_VIEW_LIGHTING_DAY_H
+
+#include "lighting.hpp"
+
+namespace Ogre
+{
+    class Light;
+}
+
+namespace CSVRender
+{
+    class LightingDay : public Lighting
+    {
+            Ogre::SceneManager *mSceneManager;
+            Ogre::Light *mLight;
+
+        public:
+
+            LightingDay();
+
+            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 8a1db1da0..77d9ea1e0 100644
--- a/apps/opencs/view/render/scenewidget.cpp
+++ b/apps/opencs/view/render/scenewidget.cpp
@@ -38,19 +38,16 @@ namespace CSVRender
 
         mSceneMgr->setAmbientLight (Ogre::ColourValue (0,0,0,1));
 
-        Ogre::Light* l = mSceneMgr->createLight();
-        l->setType (Ogre::Light::LT_DIRECTIONAL);
-        l->setDirection (Ogre::Vector3(-0.4, -0.7, 0.3));
-        l->setDiffuseColour (Ogre::ColourValue(0.7,0.7,0.7));
-
         mCamera = mSceneMgr->createCamera("foo");
 
-        mCamera->setPosition(300,0,000);
-        mCamera->lookAt(0,0,0);
-        mCamera->setNearClipDistance(0.1);
-        mCamera->setFarClipDistance(30000);
+        mCamera->setPosition (300, 0, 0);
+        mCamera->lookAt (0, 0, 0);
+        mCamera->setNearClipDistance (0.1);
+        mCamera->setFarClipDistance (30000);
         mCamera->roll (Ogre::Degree (90));
 
+        setLighting (&mLightingDay);
+
         QTimer *timer = new QTimer (this);
 
         connect (timer, SIGNAL (timeout()), this, SLOT (update()));
@@ -341,11 +338,13 @@ namespace CSVRender
             mLighting->deactivate();
 
         mLighting = lighting;
-        mLighting->activate (mSceneManager, mHasDefaultAmbient ? &mDefaultAmbient : 0);
+        mLighting->activate (mSceneMgr, mHasDefaultAmbient ? &mDefaultAmbient : 0);
     }
 
     void SceneWidget::selectLightingMode (const std::string& mode)
     {
+        if (mode=="day")
+            setLighting (&mLightingDay);
 
     }
 }
diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp
index 5058fb860..a1ecd733b 100644
--- a/apps/opencs/view/render/scenewidget.hpp
+++ b/apps/opencs/view/render/scenewidget.hpp
@@ -5,6 +5,8 @@
 
 #include <OgreColourValue.h>
 
+#include "lightingday.hpp"
+
 namespace Ogre
 {
     class Camera;
@@ -96,6 +98,7 @@ namespace CSVRender
             int mFastFactor;
             Ogre::ColourValue mDefaultAmbient;
             bool mHasDefaultAmbient;
+            LightingDay mLightingDay;
 
         private slots: