imprecise normalizing in vector3ds
Posted: Wed Apr 30, 2008 2:02 pm
Hi,
this isn't a bug at all but i think this should be done because it's pretty imprecise.
should be:
this would be much more precise for integer types...
just a suggestion ^^
neoIxen
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;
}
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;
}
just a suggestion ^^
neoIxen