Page 1 of 1

Bug animating light attenuation via numeric key frames

Posted: Tue Sep 02, 2014 12:19 am
by Jinx
Hi,

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]
		}

	};
but I think it should perhaps be something more like the following:

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]
		}
	};
I haven't tried building Ogre with the above changes to the source code, but I have tested this by creating my own version of LightAttenuationValue class in my own code base and substituting it into the call to createNumericTrack(), and it seems to work fine. I viewed the current 1.9 source code and the code for this nested class is the same as on 1.8.1.

Re: Bug animating light attenuation via numeric key frames

Posted: Tue Sep 02, 2014 8:18 pm
by dark_sylinc
Moved to papercuts. Yes, this looks like a trivial bug to fix in Ogre.

Re: Bug animating light attenuation via numeric key frames

Posted: Tue Sep 02, 2014 8:25 pm
by dark_sylinc
Just fixed in 1.9
Thanks for the report.