added lighting switching

actorid
Marc Zinnschlag 11 years ago
parent 205354ba30
commit d5506172e8

@ -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

@ -0,0 +1,4 @@
#include "lighting.hpp"
CSVRender::Lighting::~Lighting() {}

@ -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

@ -11,7 +11,10 @@
#include <OgreSceneNode.h>
#include <OgreViewport.h>
#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)
{
}
}

@ -3,17 +3,25 @@
#include <QWidget>
#include <OgreColourValue.h>
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);
};
}

@ -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();

@ -3,11 +3,10 @@
#include <QHBoxLayout>
#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);

@ -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);

Loading…
Cancel
Save