Vector normalization should not be carried out if vector length is zero, as this
would divide a vector by zero, which is bad. This closes bug #9739. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2654 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
c94ba3829f
commit
d668738714
|
@ -174,7 +174,18 @@ static inline WZ_DECL_CONST float Vector2f_Length(const Vector2f v)
|
|||
static inline WZ_DECL_CONST Vector2f Vector2f_Normalise(const Vector2f v)
|
||||
{
|
||||
float length = Vector2f_Length(v);
|
||||
Vector2f dest = {v.x / length, v.y / length};
|
||||
Vector2f dest;
|
||||
|
||||
if (length == 0.0f)
|
||||
{
|
||||
dest.x = 0.0f;
|
||||
dest.y = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.x = v.x / length;
|
||||
dest.y = v.y / length;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue