MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / RayCastWire

Method RayCastWire

Source/Editor/Utilities/Utils.cs:756–783  ·  view source on GitHub ↗

Checks if given ray intersects with the oriented bounding wire box. The box. The ray. The result intersection distance. The view position used to scale the wires thickness depending on the wire distance from the view. True ray hits bounds, otherwise fa

(ref OrientedBoundingBox box, ref Ray ray, out Real distance, ref Vector3 viewPosition)

Source from the content-addressed store, hash-verified

754 /// <param name="viewPosition">The view position used to scale the wires thickness depending on the wire distance from the view.</param>
755 /// <returns>True ray hits bounds, otherwise false.</returns>
756 public static unsafe bool RayCastWire(ref OrientedBoundingBox box, ref Ray ray, out Real distance, ref Vector3 viewPosition)
757 {
758 var corners = stackalloc Vector3[8];
759 box.GetCorners(corners);
760
761 var minDistance = Vector3.DistanceSquared(ref viewPosition, ref corners[0]);
762 for (int i = 1; i < 8; i++)
763 minDistance = Mathf.Min(minDistance, Vector3.DistanceSquared(ref viewPosition, ref corners[i]));
764 minDistance = Mathf.Sqrt(minDistance);
765 var margin = Mathf.Clamp(minDistance / 80.0f, 0.1f, 100.0f);
766
767 if (GetWriteBox(ref corners[0], ref corners[1], margin).Intersects(ref ray, out distance) ||
768 GetWriteBox(ref corners[0], ref corners[3], margin).Intersects(ref ray, out distance) ||
769 GetWriteBox(ref corners[0], ref corners[4], margin).Intersects(ref ray, out distance) ||
770 GetWriteBox(ref corners[1], ref corners[2], margin).Intersects(ref ray, out distance) ||
771 GetWriteBox(ref corners[1], ref corners[5], margin).Intersects(ref ray, out distance) ||
772 GetWriteBox(ref corners[2], ref corners[3], margin).Intersects(ref ray, out distance) ||
773 GetWriteBox(ref corners[2], ref corners[6], margin).Intersects(ref ray, out distance) ||
774 GetWriteBox(ref corners[3], ref corners[7], margin).Intersects(ref ray, out distance) ||
775 GetWriteBox(ref corners[4], ref corners[5], margin).Intersects(ref ray, out distance) ||
776 GetWriteBox(ref corners[4], ref corners[7], margin).Intersects(ref ray, out distance) ||
777 GetWriteBox(ref corners[5], ref corners[6], margin).Intersects(ref ray, out distance) ||
778 GetWriteBox(ref corners[6], ref corners[7], margin).Intersects(ref ray, out distance))
779 return true;
780
781 distance = 0;
782 return false;
783 }
784
785 /// <summary>
786 /// Initializes the object fields and properties with their default values based on <see cref="System.ComponentModel.DefaultValueAttribute"/>.

Callers 2

RayCastSelfMethod · 0.80
RayCastSelfMethod · 0.80

Calls 7

GetWriteBoxFunction · 0.85
GetCornersMethod · 0.45
DistanceSquaredMethod · 0.45
MinMethod · 0.45
SqrtMethod · 0.45
ClampMethod · 0.45
IntersectsMethod · 0.45

Tested by

no test coverage detected