我的移动对象中的代码:
ObjectX.Location.Add(Velocity * Utils.GetMoveDir(start, destination));
实用功能:
public static PointF GetMoveDir(PointF start, PointF destination)
{
PointF substraction = destination.SubStract(start);
if (substraction == PointF.Empty) // If-statement is needed because normalizing a zero value results in a NaN value
return PointF.Empty;
else
return substraction.Normalize(); // <<<< I need something for this
}
我无法工作的扩展:
public static PointF Normalize(this PointF A)
{
throw new NotImplementedException(); // How do I solve this to make it like: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2.normalize.aspx
}
请注意,我不使用 XNA 框架。