From 4a119c8f465264cd9894c772f8d6e843699e3570 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 6 Mar 2014 13:02:21 +0100 Subject: [PATCH] ambient lighting in interior cells --- apps/opencs/view/render/scenewidget.cpp | 5 ++ apps/opencs/view/render/scenewidget.hpp | 4 ++ .../view/render/unpagedworldspacewidget.cpp | 60 ++++++++++++++++++- .../view/render/unpagedworldspacewidget.hpp | 28 ++++++++- apps/opencs/view/world/scenesubview.cpp | 2 +- 5 files changed, 94 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index f71329c61..2c98b60cf 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -59,6 +59,11 @@ namespace CSVRender timer->start (20); /// \todo make this configurable } + void SceneWidget::setAmbient (const Ogre::ColourValue& colour) + { + mSceneMgr->setAmbientLight (colour); + } + void SceneWidget::updateOgreWindow() { if (mWindow) diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index c0537aa73..ad68897ac 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -8,6 +8,7 @@ namespace Ogre class Camera; class SceneManager; class RenderWindow; + class ColourValue; } namespace CSVRender @@ -25,6 +26,9 @@ namespace CSVRender QPaintEngine* paintEngine() const; + void setAmbient (const Ogre::ColourValue& colour); + ///< \note The actual ambient colour may differ based on lighting settings. + protected: void setNavigation (Navigation *navigation); diff --git a/apps/opencs/view/render/unpagedworldspacewidget.cpp b/apps/opencs/view/render/unpagedworldspacewidget.cpp index 6ccb1b99b..812a3b165 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.cpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.cpp @@ -1,6 +1,60 @@ #include "unpagedworldspacewidget.hpp" -CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (QWidget *parent) -: WorldspaceWidget (parent) -{} \ No newline at end of file +#include + +#include "../../model/doc/document.hpp" + +#include "../../model/world/data.hpp" +#include "../../model/world/idtable.hpp" + +void CSVRender::UnpagedWorldspaceWidget::update() +{ + const CSMWorld::Record& record = + dynamic_cast&> (mCellsModel->getRecord (mCellId)); + + Ogre::ColourValue colour; + colour.setAsABGR (record.get().mAmbi.mAmbient); + setAmbient (colour); + + /// \todo deal with mSunlight and mFog/mForDensity +} + +CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, + CSMDoc::Document& document, QWidget *parent) +: WorldspaceWidget (parent), mCellId (cellId) +{ + mCellsModel = &dynamic_cast ( + *document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells)); + + connect (mCellsModel, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), + this, SLOT (cellDataChanged (const QModelIndex&, const QModelIndex&))); + connect (mCellsModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), + this, SLOT (cellRowsAboutToBeRemoved (const QModelIndex&, int, int))); + + update(); +} + +void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft, + const QModelIndex& bottomRight) +{ + QModelIndex cellIndex = mCellsModel->getModelIndex (mCellId, 0); + + if (cellIndex.row()>=topLeft.row() && cellIndex.row()getModelIndex (mCellId, 0); + + if (cellIndex.row()>=start && cellIndex.row()<=end) + { + + } +} \ No newline at end of file diff --git a/apps/opencs/view/render/unpagedworldspacewidget.hpp b/apps/opencs/view/render/unpagedworldspacewidget.hpp index 7f9c895bc..17dc46918 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.hpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.hpp @@ -1,17 +1,43 @@ #ifndef OPENCS_VIEW_UNPAGEDWORLDSPACEWIDGET_H #define OPENCS_VIEW_UNPAGEDWORLDSPACEWIDGET_H +#include + #include "worldspacewidget.hpp" +class QModelIndex; + +namespace CSMDoc +{ + class Document; +} + +namespace CSMWorld +{ + class IdTable; +} + namespace CSVRender { class UnpagedWorldspaceWidget : public WorldspaceWidget { Q_OBJECT + std::string mCellId; + CSMWorld::IdTable *mCellsModel; + + void update(); + public: - UnpagedWorldspaceWidget (QWidget *parent); + UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, + QWidget *parent); + + private slots: + + void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); + + void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end); }; } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 091e78ec4..d04cc4c15 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -37,7 +37,7 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D if (id.getId()[0]=='#') mScene = new CSVRender::PagedWorldspaceWidget (this); else - mScene = new CSVRender::UnpagedWorldspaceWidget (this); + mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); SceneToolMode *tool = mScene->makeNavigationSelector (toolbar); toolbar->addTool (tool);