From c53ef04da896b01e71840c0f511514975d1289fa Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 6 Dec 2022 13:28:49 +0000 Subject: [PATCH] 0 axis and +inf angle if resulting axis is NaN --- .../Entities/VirtualParadiseObjectBuilder.cs | 6 +++ VpSharp/src/Vector3d.cs | 42 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs b/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs index d5352ec..9e9ba8a 100644 --- a/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs +++ b/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs @@ -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); diff --git a/VpSharp/src/Vector3d.cs b/VpSharp/src/Vector3d.cs index 64043f1..e6db721 100644 --- a/VpSharp/src/Vector3d.cs +++ b/VpSharp/src/Vector3d.cs @@ -394,6 +394,46 @@ public struct Vector3d : IEquatable, IFormattable return new Vector3d(vector.X, vector.Y, vector.Z); } + /// + /// Returns a value that indicates whether the components in the specified vector are not a number + /// (). + /// + /// A double-precision vector. + /// + /// if the components in evaluate to ; + /// otherwise, . + /// + public static bool IsNan(in Vector3d vector) + { + return double.IsNaN(vector.X) && double.IsNaN(vector.Y) && double.IsNaN(vector.Z); + } + + /// + /// Returns a value that indicates whether the components in the specified vector evaluate to positive infinity. + /// + /// A double-precision vector. + /// + /// if the components in evaluate to + /// ; otherwise, . + /// + public static bool IsPositiveInfinity(in Vector3d vector) + { + return double.IsPositiveInfinity(vector.X) && double.IsPositiveInfinity(vector.Y) && double.IsPositiveInfinity(vector.Z); + } + + /// + /// Returns a value that indicates whether the components in the specified vector evaluate to negative infinity. + /// + /// A double-precision vector. + /// + /// if the components in evaluate to + /// ; otherwise, . + /// + public static bool IsNegativeInfinity(in Vector3d vector) + { + return double.IsNegativeInfinity(vector.X) && double.IsNegativeInfinity(vector.Y) && double.IsNegativeInfinity(vector.Z); + } + /// /// Linearly interpolates between two vectors based on the given weighting. /// @@ -401,7 +441,7 @@ public struct Vector3d : IEquatable, IFormattable /// The second source vector. /// A value between 0 and 1 indicating the weight of . /// The interpolate vector. - 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;