imprecise normalizing in vector3ds

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
neoIxen
Posts: 13
Joined: Fri Mar 16, 2007 3:39 pm

imprecise normalizing in vector3ds

Post by neoIxen »

Hi,
this isn't a bug at all but i think this should be done because it's pretty imprecise.

Code: Select all

vector3d<T>& normalize()
{
	T l = X*X + Y*Y + Z*Z;
	if (l == 0)
		return *this;
	l = (T) reciprocal_squareroot ( (f32)l );
	X *= l;
	Y *= l;
	Z *= l;
	return *this;
}
should be:

Code: Select all

vector3d<T>& normalize()
{
	f32 l = X*X + Y*Y + Z*Z;
	if (l == 0)
		return *this;
	l = reciprocal_squareroot ( l );
	X = (T) ((f32)X * l);
	Y = (T) ((f32)Y * l);
	Z = (T) ((f32)Z * l);
	return *this;
}
this would be much more precise for integer types...
just a suggestion ^^

neoIxen
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Can you identify any users who rely on normalised integer vectors?

Also, were you abused by a f64 at one time, that you hate them so much, and want them to suffer?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
neoIxen
Posts: 13
Joined: Fri Mar 16, 2007 3:39 pm

Post by neoIxen »

i don't know what i needed it for but I once came across with this while using integer vectors and had to rewrite it ^^

but ur right it's not necessary to change at all...
and yes i fear f64.. it's bad!
just kidding... that would also do the job ^^

neoIxen
Post Reply