From d5506172e873836939495aae2805bf2472ec95c4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Mar 2014 15:14:26 +0100 Subject: [PATCH] added lighting switching --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/render/lighting.cpp | 4 ++ apps/opencs/view/render/lighting.hpp | 27 +++++++++++++ apps/opencs/view/render/scenewidget.cpp | 40 +++++++++++++++++++- apps/opencs/view/render/scenewidget.hpp | 22 ++++++++++- apps/opencs/view/render/worldspacewidget.hpp | 2 +- apps/opencs/view/world/previewsubview.cpp | 8 ++-- apps/opencs/view/world/scenesubview.cpp | 7 +++- 8 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 apps/opencs/view/render/lighting.cpp create mode 100644 apps/opencs/view/render/lighting.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index b2b534031..ee7887f3e 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 + navigation navigation1st navigationfree navigationorbit lighting ) opencs_units_noqt (view/world diff --git a/apps/opencs/view/render/lighting.cpp b/apps/opencs/view/render/lighting.cpp new file mode 100644 index 000000000..d57570d69 --- /dev/null +++ b/apps/opencs/view/render/lighting.cpp @@ -0,0 +1,4 @@ + +#include "lighting.hpp" + +CSVRender::Lighting::~Lighting() {} \ No newline at end of file diff --git a/apps/opencs/view/render/lighting.hpp b/apps/opencs/view/render/lighting.hpp new file mode 100644 index 000000000..a1da9f7e3 --- /dev/null +++ b/apps/opencs/view/render/lighting.hpp @@ -0,0 +1,27 @@ +#ifndef OPENCS_VIEW_LIGHTING_H +#define OPENCS_VIEW_LIGHTING_H + +namespace Ogre +{ + class SceneManager; + class ColourValue; +} + +namespace CSVRender +{ + class Lighting + { + public: + + virtual ~Lighting(); + + virtual void activate (Ogre::SceneManager *sceneManager, + const Ogre::ColourValue *defaultAmbient = 0) = 0; + + virtual void deactivate() = 0; + + virtual void setDefaultAmbient (const Ogre::ColourValue& colour) = 0; + }; +} + +#endif diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index c59c142fc..8a1db1da0 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -11,7 +11,10 @@ #include #include +#include "../world/scenetoolmode.hpp" + #include "navigation.hpp" +#include "lighting.hpp" namespace CSVRender { @@ -19,11 +22,12 @@ namespace CSVRender : QWidget(parent) , mWindow(NULL) , mCamera(NULL) - , mSceneMgr(NULL), mNavigation (0), mUpdate (false) + , mSceneMgr(NULL), mNavigation (0), mLighting (0), mUpdate (false) , mKeyForward (false), mKeyBackward (false), mKeyLeft (false), mKeyRight (false) , mKeyRollLeft (false), mKeyRollRight (false) , mFast (false), mDragging (false), mMod1 (false) , mFastFactor (4) /// \todo make this configurable + , mDefaultAmbient (0, 0, 0, 0), mHasDefaultAmbient (false) { setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); @@ -53,9 +57,27 @@ namespace CSVRender timer->start (20); /// \todo make this configurable } + CSVWorld::SceneToolMode *SceneWidget::makeLightingSelector (CSVWorld::SceneToolbar *parent) + { + CSVWorld::SceneToolMode *tool = new CSVWorld::SceneToolMode (parent); + + tool->addButton (":door.png", "day"); /// \todo replace icons + tool->addButton (":GMST.png", "night"); + tool->addButton (":Info.png", "bright"); + + connect (tool, SIGNAL (modeChanged (const std::string&)), + this, SLOT (selectLightingMode (const std::string&))); + + return tool; + } + void SceneWidget::setDefaultAmbient (const Ogre::ColourValue& colour) { - mSceneMgr->setAmbientLight (colour); + mDefaultAmbient = colour; + mHasDefaultAmbient = true; + + if (mLighting) + mLighting->setDefaultAmbient (colour); } void SceneWidget::updateOgreWindow() @@ -312,4 +334,18 @@ namespace CSVRender { return mFast ? mFastFactor : 1; } + + void SceneWidget::setLighting (Lighting *lighting) + { + if (mLighting) + mLighting->deactivate(); + + mLighting = lighting; + mLighting->activate (mSceneManager, mHasDefaultAmbient ? &mDefaultAmbient : 0); + } + + void SceneWidget::selectLightingMode (const std::string& mode) + { + + } } diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index 51d3464ed..5058fb860 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -3,17 +3,25 @@ #include +#include + namespace Ogre { class Camera; class SceneManager; class RenderWindow; - class ColourValue; +} + +namespace CSVWorld +{ + class SceneToolMode; + class SceneToolbar; } namespace CSVRender { class Navigation; + class Lighting; class SceneWidget : public QWidget { @@ -26,6 +34,10 @@ namespace CSVRender QPaintEngine* paintEngine() const; + CSVWorld::SceneToolMode *makeLightingSelector (CSVWorld::SceneToolbar *parent); + ///< \attention The created tool is not added to the toolbar (via addTool). Doing that + /// is the responsibility of the calling function. + protected: void setNavigation (Navigation *navigation); @@ -61,11 +73,15 @@ namespace CSVRender int getFastFactor() const; + void setLighting (Lighting *lighting); + ///< \attention The ownership of \a lighting is not transferred to *this. + Ogre::Camera* mCamera; Ogre::SceneManager* mSceneMgr; Ogre::RenderWindow* mWindow; Navigation *mNavigation; + Lighting *mLighting; bool mUpdate; bool mKeyForward; bool mKeyBackward; @@ -78,10 +94,14 @@ namespace CSVRender bool mMod1; QPoint mOldPos; int mFastFactor; + Ogre::ColourValue mDefaultAmbient; + bool mHasDefaultAmbient; private slots: void update(); + + void selectLightingMode (const std::string& mode); }; } diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 2eccca3bf..7921c3560 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -28,7 +28,7 @@ namespace CSVRender WorldspaceWidget (QWidget *parent = 0); CSVWorld::SceneToolMode *makeNavigationSelector (CSVWorld::SceneToolbar *parent); - ///< \important The created tool is not added to the toolbar (via addTool). Doing that + ///< \attention The created tool is not added to the toolbar (via addTool). Doing that /// is the responsibility of the calling function. void selectDefaultNavigationMode(); diff --git a/apps/opencs/view/world/previewsubview.cpp b/apps/opencs/view/world/previewsubview.cpp index df9c3276c..ac9776d22 100644 --- a/apps/opencs/view/world/previewsubview.cpp +++ b/apps/opencs/view/world/previewsubview.cpp @@ -3,11 +3,10 @@ #include -#include "../render/scenewidget.hpp" +#include "../render/previewwidget.hpp" #include "scenetoolbar.hpp" - -#include "../render/previewwidget.hpp" +#include "scenetoolmode.hpp" CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) : SubView (id) @@ -31,6 +30,9 @@ CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDo SceneToolbar *toolbar = new SceneToolbar (48, this); + SceneToolMode *lightingTool = mScene->makeLightingSelector (toolbar); + toolbar->addTool (lightingTool); + layout->addWidget (toolbar, 0); layout->addWidget (mScene, 1); diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 66e026604..10e8b4071 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -39,8 +39,11 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D else mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); - SceneToolMode *tool = mScene->makeNavigationSelector (toolbar); - toolbar->addTool (tool); + SceneToolMode *navigationTool = mScene->makeNavigationSelector (toolbar); + toolbar->addTool (navigationTool); + + SceneToolMode *lightingTool = mScene->makeLightingSelector (toolbar); + toolbar->addTool (lightingTool); layout2->addWidget (toolbar, 0);