Bug animating light attenuation via numeric key frames

Minor issues with the Ogre API that can be trivial to fix
Post Reply
Jinx
Gnoblar
Posts: 5
Joined: Tue Jun 04, 2013 5:17 pm

Bug animating light attenuation via numeric key frames

Post by Jinx » Tue Sep 02, 2014 12:19 am

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.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4151
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 272
Contact:

Re: Bug animating light attenuation via numeric key frames

Post by dark_sylinc » Tue Sep 02, 2014 8:18 pm

Moved to papercuts. Yes, this looks like a trivial bug to fix in Ogre.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4151
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 272
Contact:

Re: Bug animating light attenuation via numeric key frames

Post by dark_sylinc » Tue Sep 02, 2014 8:25 pm

Just fixed in 1.9
Thanks for the report.
0 x

Post Reply