public static Vector2 RayConeDistance(GHeightCone _cone, GRay _ray) { Vector2 distances = RayConeCalculate(_cone, _ray); GPlane bottomPlane = new GPlane(_cone.normal, _cone.origin + _cone.normal * _cone.height); float rayPlaneDistance = RayPlaneDistance(bottomPlane, _ray); float sqrRadius = _cone.Radius; sqrRadius *= sqrRadius; if ((_cone.Bottom - _ray.GetPoint(rayPlaneDistance)).sqrMagnitude > sqrRadius) { rayPlaneDistance = -1; } float surfaceDst = Vector3.Dot(_cone.normal, _ray.GetPoint(distances.x) - _cone.origin); if (surfaceDst < 0 || surfaceDst > _cone.height) { distances.x = rayPlaneDistance; } surfaceDst = Vector3.Dot(_cone.normal, _ray.GetPoint(distances.y) - _cone.origin); if (surfaceDst < 0 || surfaceDst > _cone.height) { distances.y = rayPlaneDistance; } return(distances); }
public static void DrawCone(GHeightCone _heightCone) { using (new Handles.DrawingScope(Handles.color, Handles.matrix * Matrix4x4.TRS(_heightCone.origin, Quaternion.LookRotation(_heightCone.normal), Vector3.one))) { float radius = _heightCone.Radius; Vector3 bottom = Vector3.forward * _heightCone.height; Vector3 bottomForwardDir = Vector3.up * radius; Vector3 bottomForward = bottom + bottomForwardDir; Vector3 bottomBack = bottom - bottomForwardDir; Vector3 bottomRightDir = Vector3.right * radius; Vector3 bottomRight = bottom + bottomRightDir; Vector3 bottomLeft = bottom - bottomRightDir; Handles.DrawWireArc(bottom, -Vector3.forward, Vector3.right, 360, radius); Handles.DrawLine(Vector3.zero, bottomForward); Handles.DrawLine(Vector3.zero, bottomBack); Handles.DrawLine(Vector3.zero, bottomRight); Handles.DrawLine(Vector3.zero, bottomLeft); } }
public static void DrawCone(GHeightCone _cone) { Handles.color = Gizmos.color; Handles.matrix = Gizmos.matrix; Handles_Extend.DrawCone(_cone); }