added day lighting mode

This commit is contained in:
Marc Zinnschlag 2014-03-26 17:47:56 +01:00
parent d5506172e8
commit fa29942b27
5 changed files with 80 additions and 11 deletions

View file

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

View file

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

View file

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

View file

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

View file

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