1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-10 02:35:42 +00:00

0 axis and +inf angle if resulting axis is NaN

This commit is contained in:
Oliver Booth 2022-12-06 13:28:49 +00:00
parent c58fe6a2a3
commit c53ef04da8
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 47 additions and 1 deletions

View File

@ -186,6 +186,12 @@ public abstract class VirtualParadiseObjectBuilder
else
{
TargetObject.Location.Rotation.ToAxisAngle(out Vector3d axis, out double angle);
if (Vector3d.IsNan(axis))
{
axis = Vector3d.Zero;
angle = double.PositiveInfinity;
}
_ = vp_double_set(handle, ObjectRotationX, axis.X);
_ = vp_double_set(handle, ObjectRotationY, axis.Y);
_ = vp_double_set(handle, ObjectRotationZ, axis.Z);

View File

@ -394,6 +394,46 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
return new Vector3d(vector.X, vector.Y, vector.Z);
}
/// <summary>
/// Returns a value that indicates whether the components in the specified vector are not a number
/// (<see cref="double.NaN" />).
/// </summary>
/// <param name="vector">A double-precision vector.</param>
/// <returns>
/// <see langword="true" /> if the components in <paramref name="vector" /> evaluate to <see cref="double.NaN" />;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool IsNan(in Vector3d vector)
{
return double.IsNaN(vector.X) && double.IsNaN(vector.Y) && double.IsNaN(vector.Z);
}
/// <summary>
/// Returns a value that indicates whether the components in the specified vector evaluate to positive infinity.
/// </summary>
/// <param name="vector">A double-precision vector.</param>
/// <returns>
/// <see langword="true" /> if the components in <paramref name="vector" /> evaluate to
/// <see cref="double.PositiveInfinity" />; otherwise, <see langword="false" />.
/// </returns>
public static bool IsPositiveInfinity(in Vector3d vector)
{
return double.IsPositiveInfinity(vector.X) && double.IsPositiveInfinity(vector.Y) && double.IsPositiveInfinity(vector.Z);
}
/// <summary>
/// Returns a value that indicates whether the components in the specified vector evaluate to negative infinity.
/// </summary>
/// <param name="vector">A double-precision vector.</param>
/// <returns>
/// <see langword="true" /> if the components in <paramref name="vector" /> evaluate to
/// <see cref="double.NegativeInfinity" />; otherwise, <see langword="false" />.
/// </returns>
public static bool IsNegativeInfinity(in Vector3d vector)
{
return double.IsNegativeInfinity(vector.X) && double.IsNegativeInfinity(vector.Y) && double.IsNegativeInfinity(vector.Z);
}
/// <summary>
/// Linearly interpolates between two vectors based on the given weighting.
/// </summary>
@ -401,7 +441,7 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
/// <param name="b">The second source vector.</param>
/// <param name="t">A value between 0 and 1 indicating the weight of <paramref name="b" />.</param>
/// <returns>The interpolate vector.</returns>
public static Vector3d Lerp(Vector3d a, Vector3d b, double t)
public static Vector3d Lerp(in Vector3d a, in Vector3d b, double t)
{
Vector3d firstInfluence = a * (1.0f - t);
Vector3d secondInfluence = b * t;