I've been playing around with animable numeric values for lights in Ogre 1.8.1 and I was having problems getting attenuation to work (I can get other animable values to work just fine, so I don't think there is anything fundamentally wrong with my code).
I dug into the Ogre source code a bit and think I've spotted the problem in the nested class Ogre::Light::LightAttenuationValue. The method applyDeltaValue adds the delta for the keyframe to mLight->getAs4DVector(), which seems wrong to me. A quick look at the implementation of getAs4DVector() shows this vector is solely position and orientation, and doesn't seem to relate to attenuation at all.
The original code in Ogre 1.8.1 is as follows:
Code: Select all
class LightAttenuationValue : public AnimableValue
{
protected:
Light* mLight;
public:
LightAttenuationValue(Light* l) :AnimableValue(VECTOR4)
{ mLight = l; }
void setValue(const Vector4& val)
{
mLight->setAttenuation(val.x, val.y, val.z, val.w);
}
void applyDeltaValue(const Vector4& val)
{
[b] setValue(mLight->getAs4DVector() + val);[/b]
}
void setCurrentStateAsBaseValue(void)
{
[b]setAsBaseValue(mLight->getAs4DVector());[/b]
}
};
Code: Select all
class LightAttenuationValue : public AnimableValue
{
protected:
Light* mLight;
public:
LightAttenuationValue(Light* l) :AnimableValue(VECTOR4)
{ mLight = l; }
void setValue(const Vector4& val)
{
mLight->setAttenuation(val.x, val.y, val.z, val.w);
}
void applyDeltaValue(const Vector4& val)
{
[b]Vector4 current(mLight->getAttenuationRange(),
mLight->getAttenuationConstant(),
mLight->getAttenuationLinear(),
mLight->getAttenuationQuadric());
setValue(current + val);[/b]
}
void setCurrentStateAsBaseValue(void)
{
[b]Vector4 current(mLight->getAttenuationRange(),
mLight->getAttenuationConstant(),
mLight->getAttenuationLinear(),
mLight->getAttenuationQuadric());
setAsBaseValue(current);[/b]
}
};