Merge branch 'light'

actorid
Marc Zinnschlag 11 years ago
commit ce792cf182

@ -69,7 +69,8 @@ opencs_units (view/render
)
opencs_units_noqt (view/render
navigation navigation1st navigationfree navigationorbit
navigation navigation1st navigationfree navigationorbit lighting lightingday lightingnight
lightingbright
)
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

@ -0,0 +1,30 @@
#include "lightingbright.hpp"
#include <OgreSceneManager.h>
CSVRender::LightingBright::LightingBright() : mSceneManager (0), mLight (0) {}
void CSVRender::LightingBright::activate (Ogre::SceneManager *sceneManager,
const Ogre::ColourValue *defaultAmbient)
{
mSceneManager = sceneManager;
mSceneManager->setAmbientLight (Ogre::ColourValue (1.0, 1.0, 1.0, 1));
mLight = mSceneManager->createLight();
mLight->setType (Ogre::Light::LT_DIRECTIONAL);
mLight->setDirection (Ogre::Vector3 (0, 0, -1));
mLight->setDiffuseColour (Ogre::ColourValue (1.0, 1.0, 1.0));
}
void CSVRender::LightingBright::deactivate()
{
if (mLight)
{
mSceneManager->destroyLight (mLight);
mLight = 0;
}
}
void CSVRender::LightingBright::setDefaultAmbient (const Ogre::ColourValue& colour) {}

@ -0,0 +1,31 @@
#ifndef OPENCS_VIEW_LIGHTING_BRIGHT_H
#define OPENCS_VIEW_LIGHTING_BRIGHT_H
#include "lighting.hpp"
namespace Ogre
{
class Light;
}
namespace CSVRender
{
class LightingBright : public Lighting
{
Ogre::SceneManager *mSceneManager;
Ogre::Light *mLight;
public:
LightingBright();
virtual void activate (Ogre::SceneManager *sceneManager,
const Ogre::ColourValue *defaultAmbient = 0);
virtual void deactivate();
virtual void setDefaultAmbient (const Ogre::ColourValue& colour);
};
}
#endif

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

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

@ -0,0 +1,36 @@
#include "lightingnight.hpp"
#include <OgreSceneManager.h>
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);
}

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

@ -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);
@ -32,34 +36,45 @@ namespace CSVRender
mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
// Throw in a random color just to make sure multiple scenes work
Ogre::Real r = Ogre::Math::RangeRandom(0, 1);
Ogre::Real g = Ogre::Math::RangeRandom(0, 1);
Ogre::Real b = Ogre::Math::RangeRandom(0, 1);
mSceneMgr->setAmbientLight(Ogre::ColourValue(r,g,b,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));
mSceneMgr->setAmbientLight (Ogre::ColourValue (0,0,0,1));
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()));
timer->start (20); /// \todo make this configurable
}
void SceneWidget::setAmbient (const Ogre::ColourValue& colour)
CSVWorld::SceneToolMode *SceneWidget::makeLightingSelector (CSVWorld::SceneToolbar *parent)
{
mSceneMgr->setAmbientLight (colour);
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)
{
mDefaultAmbient = colour;
mHasDefaultAmbient = true;
if (mLighting)
mLighting->setDefaultAmbient (colour);
}
void SceneWidget::updateOgreWindow()
@ -316,4 +331,23 @@ namespace CSVRender
{
return mFast ? mFastFactor : 1;
}
void SceneWidget::setLighting (Lighting *lighting)
{
if (mLighting)
mLighting->deactivate();
mLighting = lighting;
mLighting->activate (mSceneMgr, mHasDefaultAmbient ? &mDefaultAmbient : 0);
}
void SceneWidget::selectLightingMode (const std::string& mode)
{
if (mode=="day")
setLighting (&mLightingDay);
else if (mode=="night")
setLighting (&mLightingNight);
else if (mode=="bright")
setLighting (&mLightingBright);
}
}

@ -3,17 +3,29 @@
#include <QWidget>
#include <OgreColourValue.h>
#include "lightingday.hpp"
#include "lightingnight.hpp"
#include "lightingbright.hpp"
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,8 +38,9 @@ namespace CSVRender
QPaintEngine* paintEngine() const;
void setAmbient (const Ogre::ColourValue& colour);
///< \note The actual ambient colour may differ based on lighting settings.
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:
@ -38,6 +51,9 @@ namespace CSVRender
void flagAsModified();
void setDefaultAmbient (const Ogre::ColourValue& colour);
///< \note The actual ambient colour may differ based on lighting settings.
private:
void paintEvent(QPaintEvent* e);
void resizeEvent(QResizeEvent* e);
@ -61,11 +77,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 +98,17 @@ namespace CSVRender
bool mMod1;
QPoint mOldPos;
int mFastFactor;
Ogre::ColourValue mDefaultAmbient;
bool mHasDefaultAmbient;
LightingDay mLightingDay;
LightingNight mLightingNight;
LightingBright mLightingBright;
private slots:
void update();
void selectLightingMode (const std::string& mode);
};
}

@ -15,7 +15,7 @@ void CSVRender::UnpagedWorldspaceWidget::update()
Ogre::ColourValue colour;
colour.setAsABGR (record.get().mAmbi.mAmbient);
setAmbient (colour);
setDefaultAmbient (colour);
/// \todo deal with mSunlight and mFog/mForDensity
}

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