diff --git a/Assets/RuntimeDebugDraw.cs b/Assets/RuntimeDebugDraw.cs index 4fac8b8..88a4ffa 100644 --- a/Assets/RuntimeDebugDraw.cs +++ b/Assets/RuntimeDebugDraw.cs @@ -71,15 +71,59 @@ public static void DrawLine(Vector3 start, Vector3 end, Color color, float durat return; } - /// - /// Draws a line from start to start + dir in world coordinates. - /// - /// Point in world space where the ray should start. - /// Direction and length of the ray. - /// Color of the drawn line. - /// How long the line will be visible for (in seconds). - /// Should the line be obscured by other objects closer to the camera? - [Conditional("_DEBUG")] + /// + /// Draws a top-down circle of a given radius at the world coordinates. + /// + /// The world coordinates for the center of the circle. + /// The radius (in units) of the circle. + /// The color of the circle. + /// The angle of the circle. + /// The forward direction of the circle. Necessary if the angle is less than 360 for showing FOV cone type information. + /// How long the line will be visible for (in seconds). + /// Should the line be obscured by other objects closer to the camera? + [Conditional("_DEBUG")] + public static void DrawCircle(Vector3 center, float radius, Color color, float duration, bool depthTest, Vector3 forwardDir, float angleFov) + { + CheckAndBuildHiddenRTDrawObject(); + + const int numSegments = 32; + + float fwdDir = Mathf.Atan2(forwardDir.z, forwardDir.x); + float startRad = fwdDir - angleFov / 2 * Mathf.Deg2Rad; + float endRad = fwdDir + angleFov / 2 * Mathf.Deg2Rad; + float thetaRad = (endRad - startRad) / numSegments; + + List nodes = new List { center }; + + int i = 0; + for (float curRadians = startRad; i < numSegments + 1; curRadians += thetaRad) + { + Vector3 coordinate = new Vector3( + Mathf.Cos(curRadians) * radius + center.x, + Mathf.Sin(curRadians) * radius + center.z, + center.y); + + nodes.Add(new Vector3(coordinate.x, coordinate.z, coordinate.y)); + i++; + } + + nodes.Add(center); + + for (i = 1; i < nodes.Count; i++) + { + _rtDraw.RegisterLine(nodes[i - 1], nodes[i], color, duration, !depthTest); + } + } + + /// + /// Draws a line from start to start + dir in world coordinates. + /// + /// Point in world space where the ray should start. + /// Direction and length of the ray. + /// Color of the drawn line. + /// How long the line will be visible for (in seconds). + /// Should the line be obscured by other objects closer to the camera? + [Conditional("_DEBUG")] public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration, bool depthTest) { CheckAndBuildHiddenRTDrawObject(); @@ -166,12 +210,25 @@ public static void DrawLine(Vector3 start, Vector3 end, Color color, float durat return; } - /// - /// Draws a line from start to start + dir in world coordinates. - /// - /// Point in world space where the ray should start. - /// Direction and length of the ray. - [Conditional("_DEBUG")] + /// + /// Draws a top-down circle of a given radius at the world coordinates. + /// + /// The world coordinates for the center of the circle. + /// The radius (in units) of the circle. + /// The color of the circle. + /// How long the line will be visible for (in seconds). + [Conditional("_DEBUG")] + public static void DrawCircle(Vector3 center, float radius, Color color, float duration) + { + DrawCircle(center, radius, color, duration, false, Vector3.forward, 360); + } + + /// + /// Draws a line from start to start + dir in world coordinates. + /// + /// Point in world space where the ray should start. + /// Direction and length of the ray. + [Conditional("_DEBUG")] public static void DrawRay(Vector3 start, Vector3 dir) { DrawRay(start, dir, DrawDefaultColor, 0f, true);