Light magic effect

Notable change compared to the old (Ogre) effect: uses the ambient instead of diffuse term (Fixes #2364)
c++11
scrawl 10 years ago
parent 631cec7304
commit 6724585777

@ -267,6 +267,8 @@ namespace MWRender
Animation::~Animation()
{
setLightEffect(0.f);
if (mObjectRoot)
mInsert->removeChild(mObjectRoot);
}
@ -1224,6 +1226,36 @@ namespace MWRender
return found->second;
}
void Animation::setLightEffect(float effect)
{
if (effect == 0)
{
if (mGlowLight)
{
mInsert->removeChild(mGlowLight);
mGlowLight = NULL;
}
}
else
{
if (!mGlowLight)
{
mGlowLight = new SceneUtil::LightSource;
mGlowLight->setLight(new osg::Light);
osg::Light* light = mGlowLight->getLight();
light->setDiffuse(osg::Vec4f(0,0,0,0));
light->setSpecular(osg::Vec4f(0,0,0,0));
light->setAmbient(osg::Vec4f(1.5f,1.5f,1.5f,1.f));
mInsert->addChild(mGlowLight);
}
effect += 3;
osg::Light* light = mGlowLight->getLight();
mGlowLight->setRadius(effect * 66.f);
light->setLinearAttenuation(0.5f/effect);
}
}
void Animation::addControllers()
{
mHeadController = NULL;

@ -21,6 +21,11 @@ namespace NifOsg
class KeyframeController;
}
namespace SceneUtil
{
class LightSource;
}
namespace MWRender
{
@ -202,6 +207,8 @@ protected:
float mHeadYawRadians;
float mHeadPitchRadians;
osg::ref_ptr<SceneUtil::LightSource> mGlowLight;
/* Sets the appropriate animations on the bone groups based on priority.
*/
void resetActiveGroups();
@ -377,7 +384,7 @@ public:
// TODO: move outside of this class
/// Makes this object glow, by placing a Light in its center.
/// @param effect Controls the radius and intensity of the light.
virtual void setLightEffect(float effect) {}
virtual void setLightEffect(float effect);
virtual void setHeadPitch(float pitchRadians);
virtual void setHeadYaw(float yawRadians);

Loading…
Cancel
Save