Open
Description
public static void Normalize(ref Vector2 value, out Vector2 result)
{
float factor;
DistanceSquared(ref value, ref zeroVector, out factor);
factor = 1f / (float)Math.Sqrt(factor);
result.X = value.X * factor;
result.Y = value.Y * factor;
}
I'm currently using Farseer and had some issues with contact solving. I figured the issue might still be with Velcro.
Normalize return a Vector2(X=NaN, Y=NaN) if you try to normalize a zero vector.
because factor will be zero so 1f / (float)Math.Sqrt(factor)
will result in Infinity
the solver does something like Normalize(Position1 - Position2) so if the two positions is identical we get the NaN vector which crashes the physics.
Hopes this helps :)
I solved it this way
public static void Normalize(ref Vector2 value, out Vector2 result) {
if (value == zeroVector)
result = zeroVector;
else {
float factor;
DistanceSquared(ref value, ref zeroVector, out factor);
factor = 1f / (float)Math.Sqrt(factor);
result.x = value.x * factor;
result.y = value.y * factor;
}
}
Metadata
Metadata
Assignees
Labels
No labels