public static void LineCast(RaycastHit hit, Ray ray, float radius, float distance, DebugStyle setup) { if (hit.transform == null) { LineCast(ray, radius, distance, setup); return; } { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Point, setup); prim.pos = hit.point; prim.rot = Quaternion.LookRotation(hit.normal); prim.extents = vec3(radius * 2); DebugDisplayRegistry.Add(prim); } var place0 = DebugPlace.AToB(ray.origin, ray.origin + ray.direction * hit.distance); { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.LineCast, setup); prim.pos = place0.Position; prim.rot = place0.Rotation; prim.extents = vec3(radius, radius, place0.Extents.z); DebugDisplayRegistry.Add(prim); } var place1 = DebugPlace.AToB(place0.End, ray.origin + ray.direction * distance); { setup.Color = Color.grey; var prim = new DebugPrimitiveSetup(DebugPrimitiveType.LineCast, setup); prim.pos = place1.Position; prim.rot = place1.Rotation; prim.extents = vec3(radius * 0.9f, radius * 0.9f, place1.Extents.z); DebugDisplayRegistry.Add(prim); } }
public static void SphereCast(RaycastHit hit, Ray ray, float radius, float distance, DebugStyle setup) { { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Point, setup); prim.pos = hit.point; prim.rot = Quaternion.LookRotation(hit.normal); prim.extents = vec3(radius * 0.4f); DebugDisplayRegistry.Add(prim); } var place0 = DebugPlace.AToB(ray.origin, ray.origin + ray.direction * (hit.distance + radius)); { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.SphereCast, setup); prim.pos = place0.Position; prim.rot = place0.Rotation; prim.extents = vec3(radius, radius, place0.Extents.z); DebugDisplayRegistry.Add(prim); } var place1 = DebugPlace.AToB(place0.End - ray.direction * radius * 1.9f, ray.origin + ray.direction * distance); { setup.Color = Color.grey; var prim = new DebugPrimitiveSetup(DebugPrimitiveType.SphereCast, setup); prim.pos = place1.Position; prim.rot = place1.Rotation; prim.extents = vec3(radius * 0.9f, radius * 0.9f, place1.Extents.z); DebugDisplayRegistry.Add(prim); } }
public static void Box(DebugPlace place, DebugStyle setup) { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Box, setup); prim.pos = place.Position; prim.rot = place.Rotation; prim.extents = place.Extents; DebugDisplayRegistry.Add(prim); }
public static void Point(DebugPlace place, DebugStyle setup) { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Point, setup); prim.pos = place.Position; prim.rot = Quaternion.identity; prim.extents = place.Extents; DebugDisplayRegistry.Add(prim); }
public static void Line(DebugPlace place, DebugStyle setup) { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Line, setup); prim.pos = place.Start; prim.rot = place.Rotation; prim.extents = place.Size; DebugDisplayRegistry.Add(prim); }
public static void Arrow(DebugPlace place, DebugStyle setup) { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Arrow, setup); prim.pos = place.Start; prim.rot = place.Rotation; prim.extents = vec3(place.Extents.x, place.Extents.y, place.Size.z); DebugDisplayRegistry.Add(prim); }
///--------------------------------------------------------------------- //Point: Three line to mark each axis private static void Line(Vector3 start, Vector3 end, DebugStyle setup) { var dir = end - start; var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Line, setup); prim.pos = start; prim.rot = Quaternion.LookRotation(dir.normalized); prim.extents = vec3(0, 0, dir.magnitude); DebugDisplayRegistry.Add(prim); }
public static void SphereCast(Ray ray, float radius, float distance, DebugStyle setup) { var place = DebugPlace.AToB(ray.origin, ray.origin + ray.direction * distance); var prim = new DebugPrimitiveSetup(DebugPrimitiveType.SphereCast, setup); prim.pos = place.Position; prim.rot = place.Rotation; prim.extents = vec3(radius, radius, place.Extents.z); DebugDisplayRegistry.Add(prim); }
public static void Pie(DebugPlace place, Vector2 degrees, DebugStyle setup) { var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Pie, setup); prim.pos = place.Position; prim.rot = place.Rotation; prim.extents = place.Extents; prim.range = degrees; DebugDisplayRegistry.Add(prim); }
///--------------------------------------------------------------------- #region Recording datas public static void Add(DebugPrimitiveSetup debugPrimitive) { return; //var instance = TickableRegistry.GetManager<DebugDisplayManager>(); //if (instance == null) // return; //if (instance.IsAppPaused) // return; //if (primitive.setup.Duration < 0) // instance.recordings.FramePrimitives.Add(primitive); //else // instance.TimedPrimitives.Add(primitive); }
public static void Plane(Plane plane, DebugPlace place, DebugStyle setup) { var q = place.Rotation; var x = place.Right; var y = place.Up; var p = (plane.normal * -plane.distance) + (x * place.Position.x) + (y * place.Position.y); var prim = new DebugPrimitiveSetup(DebugPrimitiveType.Plane, setup); prim.pos = p; prim.rot = q; prim.extents = place.Size; DebugDisplayRegistry.Add(prim); Arrow(place, setup); }
///--------------------------------------------------------------------- #region Primitives render internal static void Render(DebugLineDisplayer d, DebugPrimitiveSetup prim) { var pos = prim.pos; var wRt = prim.rot * Vector3.right; var wUp = prim.rot * Vector3.up; var wFw = prim.rot * Vector3.forward; pos = prim.setup.Matrix.MultiplyPoint(pos); wFw = prim.setup.Matrix.MultiplyPoint(prim.pos + wFw) - pos; wRt = prim.setup.Matrix.MultiplyPoint(prim.pos + wRt) - pos; wUp = prim.setup.Matrix.MultiplyPoint(prim.pos + wUp) - pos; prim.setup.Matrix = Matrix4x4.identity; //Adjust axis size if required switch (prim.type) { case DebugPrimitiveType.Point: case DebugPrimitiveType.Box: case DebugPrimitiveType.Plane: case DebugPrimitiveType.Arc: case DebugPrimitiveType.Cone: { wRt *= prim.extents.x; wUp *= prim.extents.y; wFw *= prim.extents.z; break; } } //Draw the actual primitive switch (prim.type) { case DebugPrimitiveType.Line: { d.RenderLine(prim.setup, pos, pos + wFw * prim.extents.z); break; } case DebugPrimitiveType.Point: { d.RenderLine(prim.setup, pos - wFw, pos + wFw); d.RenderLine(prim.setup, pos - wUp, pos + wUp); d.RenderLine(prim.setup, pos - wRt, pos + wRt); prim.setup.Color = Color.red; d.RenderLine(prim.setup, pos + wRt, pos + wRt * 0.75f + wUp * 0.25f); d.RenderLine(prim.setup, pos + wRt * 0.9f, pos + wRt * 0.75f + wUp * 0.25f); d.RenderLine(prim.setup, pos + wRt, pos + wRt * 0.75f + wFw * 0.25f); d.RenderLine(prim.setup, pos + wRt * 0.9f, pos + wRt * 0.75f + wFw * 0.25f); prim.setup.Color = Color.green; d.RenderLine(prim.setup, pos + wUp, pos + wUp * 0.75f + wFw * 0.25f); d.RenderLine(prim.setup, pos + wUp * 0.9f, pos + wUp * 0.75f + wFw * 0.25f); d.RenderLine(prim.setup, pos + wUp, pos + wUp * 0.75f + wRt * 0.25f); d.RenderLine(prim.setup, pos + wUp * 0.9f, pos + wUp * 0.75f + wRt * 0.25f); prim.setup.Color = Color.blue; d.RenderLine(prim.setup, pos + wFw, pos + wFw * 0.75f + wUp * 0.25f); d.RenderLine(prim.setup, pos + wFw * 0.9f, pos + wFw * 0.75f + wUp * 0.25f); d.RenderLine(prim.setup, pos + wFw, pos + wFw * 0.75f + wRt * 0.25f); d.RenderLine(prim.setup, pos + wFw * 0.9f, pos + wFw * 0.75f + wRt * 0.25f); break; } case DebugPrimitiveType.Box: { var posUp = pos + wUp; var posDn = pos - wUp; d.RenderLine(prim.setup, posUp - wRt + wFw, posUp + wRt + wFw); d.RenderLine(prim.setup, posUp - wRt - wFw, posUp + wRt - wFw); d.RenderLine(prim.setup, posUp - wRt - wFw, posUp - wRt + wFw); d.RenderLine(prim.setup, posUp + wRt - wFw, posUp + wRt + wFw); d.RenderLine(prim.setup, posDn - wRt + wFw, posDn + wRt + wFw); d.RenderLine(prim.setup, posDn - wRt - wFw, posDn + wRt - wFw); d.RenderLine(prim.setup, posDn - wRt - wFw, posDn - wRt + wFw); d.RenderLine(prim.setup, posDn + wRt - wFw, posDn + wRt + wFw); d.RenderLine(prim.setup, posUp + wRt + wFw, posDn + wRt + wFw); d.RenderLine(prim.setup, posUp - wRt - wFw, posDn - wRt - wFw); d.RenderLine(prim.setup, posUp - wRt + wFw, posDn - wRt + wFw); d.RenderLine(prim.setup, posUp + wRt - wFw, posDn + wRt - wFw); break; } case DebugPrimitiveType.Arc: { var segments = prim.setup.Precision; var step = (prim.range.y - prim.range.x) / segments; for (var i = 0; i < segments; i++) { var j = i + 1; var angle0 = prim.range.x + i * step; var angle1 = prim.range.x + j * step; var p0 = wRt * Mathf.Cos(angle0 * Mathf.Deg2Rad) + wUp * Mathf.Sin(angle0 * Mathf.Deg2Rad); var p1 = wRt * Mathf.Cos(angle1 * Mathf.Deg2Rad) + wUp * Mathf.Sin(angle1 * Mathf.Deg2Rad); d.RenderLine(prim.setup, pos + p0, pos + p1); } break; } case DebugPrimitiveType.Circle: { var other = prim; other.type = DebugPrimitiveType.Arc; other.range = vec2(0, 360); Render(d, other); break; } case DebugPrimitiveType.Sphere: { var other = prim; other.type = DebugPrimitiveType.Arc; other.range = vec2(0, 360); Render(d, other); other.rot = Quaternion.LookRotation(wUp, wFw); other.extents = prim.extents.xzy(); Render(d, other); other.rot = Quaternion.LookRotation(wRt, wFw); other.extents = prim.extents.zxy(); Render(d, other); break; } case DebugPrimitiveType.Capsule: { var z = min(min(prim.extents.x, prim.extents.y), abs(prim.extents.z)); var h = max(0, prim.extents.z - z); var other0 = prim; other0.type = DebugPrimitiveType.Arc; other0.range = vec2(0, 360); var other1 = other0; other0.pos -= other0.rot * vec3(0, 0, h); Render(d, other0); other0.rot = Quaternion.LookRotation(wUp, wFw); other0.extents = prim.extents.xny(z); other0.range = vec2(180, 360); Render(d, other0); other0.rot = Quaternion.LookRotation(wRt, wFw); Render(d, other0); other1.pos += other1.rot * vec3(0, 0, h); Render(d, other1); other1.rot = Quaternion.LookRotation(wUp, wFw); other1.extents = prim.extents.xny(z); other1.range = vec2(0, 180); Render(d, other1); other1.rot = Quaternion.LookRotation(wRt, wFw); Render(d, other1); wUp = wUp * prim.extents.y; wRt = wRt * prim.extents.x; d.RenderLine(prim.setup, other0.pos + wUp, other1.pos + wUp); d.RenderLine(prim.setup, other0.pos - wUp, other1.pos - wUp); d.RenderLine(prim.setup, other0.pos + wRt, other1.pos + wRt); d.RenderLine(prim.setup, other0.pos - wRt, other1.pos - wRt); break; } case DebugPrimitiveType.Cone: { var start = pos - wFw; for (int i = 0; i < prim.setup.Precision; ++i) { var a = ((float)i / (float)prim.setup.Precision) * Mathf.PI * 2.0f; var x = Mathf.Sin(a) * wRt; var y = Mathf.Cos(a) * wUp; d.RenderLine(prim.setup, start, pos + wFw + x + y); } var other = prim; other.type = DebugPrimitiveType.Arc; other.range = vec2(0, 360); other.pos = pos + wFw; Render(d, other); break; } case DebugPrimitiveType.Pie: { var pieDiff = abs(prim.range.y - prim.range.x); if (pieDiff >= 360 && prim.extents.z == 0) { var other = prim; other.type = DebugPrimitiveType.Arc; other.range = vec2(0, 360); Render(d, other); break; } //Draw pie arcs { var other = prim; other.type = DebugPrimitiveType.Arc; other.pos -= wFw * prim.extents.z; Render(d, other); other.pos += wFw * prim.extents.z * 2f; Render(d, other); } //Center line d.RenderLine(prim.setup, pos - wFw * prim.extents.z, pos + wFw * prim.extents.z); //Draw sides and inner lines var segments = prim.setup.Precision; var step = (prim.range.y - prim.range.x) / segments; for (var i = 0; i <= segments; i++) { var j = i + 1; var angle = prim.range.x + i * step; var p = wRt * prim.extents.x * Mathf.Cos(angle * Mathf.Deg2Rad) + wUp * prim.extents.y * Mathf.Sin(angle * Mathf.Deg2Rad); d.RenderLine(prim.setup, pos + p - wFw * prim.extents.z, pos + p + wFw * prim.extents.z); if (i == 0 || i == segments) { d.RenderLine(prim.setup, pos - wFw * prim.extents.z, pos + p - wFw * prim.extents.z); d.RenderLine(prim.setup, pos + wFw * prim.extents.z, pos + p + wFw * prim.extents.z); } } break; } case DebugPrimitiveType.Arrow: { var end = pos + wFw * prim.extents.z; d.RenderLine(prim.setup, end, pos); d.RenderLine(prim.setup, end, end - wFw * prim.extents.y - wRt * prim.extents.x); d.RenderLine(prim.setup, end, end - wFw * prim.extents.y + wRt * prim.extents.x); d.RenderLine(prim.setup, end, end - wFw * prim.extents.y - wUp * prim.extents.x); d.RenderLine(prim.setup, end, end - wFw * prim.extents.y + wUp * prim.extents.x); var end0 = end - wFw * prim.extents.y * 0.25f; d.RenderLine(prim.setup, end0, end - wFw * prim.extents.y - wRt * prim.extents.x); d.RenderLine(prim.setup, end0, end - wFw * prim.extents.y + wRt * prim.extents.x); d.RenderLine(prim.setup, end0, end - wFw * prim.extents.y - wUp * prim.extents.x); d.RenderLine(prim.setup, end0, end - wFw * prim.extents.y + wUp * prim.extents.x); break; } case DebugPrimitiveType.Plane: { d.RenderLine(prim.setup, pos - wRt - wUp, pos + wRt - wUp); d.RenderLine(prim.setup, pos - wRt + wUp, pos + wRt + wUp); d.RenderLine(prim.setup, pos - wRt - wUp, pos - wRt + wUp); d.RenderLine(prim.setup, pos + wRt - wUp, pos + wRt + wUp); break; } case DebugPrimitiveType.LineCast: { var a = pos - wFw * prim.extents.z; var b = pos + wFw * prim.extents.z; d.RenderLine(prim.setup, a, b); var other = prim; other.type = DebugPrimitiveType.Sphere; other.extents = vec3(prim.extents.x); other.pos = a; Render(d, other); other.pos = b; Render(d, other); break; } case DebugPrimitiveType.SphereCast: { var pos_ = pos; var pos0 = pos_ - wFw * (prim.extents.z - prim.extents.x); var pos1 = pos_ + wFw * (prim.extents.z - prim.extents.x); var other = prim; other.type = DebugPrimitiveType.Sphere; other.extents = vec3(prim.extents.x); other.pos = pos0; Render(d, other); other.pos = pos1; Render(d, other); d.RenderLine(prim.setup, pos0 - wRt * prim.extents.x, pos1 - wRt * prim.extents.x); d.RenderLine(prim.setup, pos0 + wRt * prim.extents.x, pos1 + wRt * prim.extents.x); d.RenderLine(prim.setup, pos0 + wUp * prim.extents.y, pos1 + wUp * prim.extents.y); d.RenderLine(prim.setup, pos0 - wUp * prim.extents.y, pos1 - wUp * prim.extents.y); d.RenderLine(prim.setup, pos0 + wFw * prim.extents.x, pos1 - wFw * prim.extents.x); break; } } }
///--------------------------------------------------------------------- protected static void Add(DebugPrimitiveSetup debugPrimitive) { DebugDisplayRegistry.Add(debugPrimitive); }