Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        public static void LineCastList(Ray[] rays, float radius, float distance, DebugStyle setup, bool doLoop = false)
        {
            for (int h = 0; h < rays.Length; h++)
            {
                LineCast(rays[h], radius, distance, setup);

                if (doLoop || h < rays.Length - 1)
                {
                    var h1 = (h + 1) % rays.Length;
                    Line(DebugPlace.AToB(rays[h].origin + rays[h].direction * distance, rays[h1].origin + rays[h1].direction * distance), setup);
                }
            }
        }
Beispiel #10
0
        public static void Light(Light light, DebugStyle setup)
        {
            var tr = light.transform;

            if (light.type == LightType.Point)
            {
                Sphere(DebugPlace.At(tr.position, tr.rotation, light.range), setup);
            }
            else if (light.type == LightType.Spot)
            {
                var t = Mathf.Tan(light.spotAngle) * light.range;
                Cone(DebugPlace.AToB(tr.position, tr.rotation * vec3(0, 0, light.range), vec3(t, t, 0), tr.rotation * Vector3.up), setup);
            }
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public static void LineCastList(RaycastHit[] hits, Ray[] rays, float radius, float distance, DebugStyle setup, bool doLoop = false)
        {
            bool hasHit = false;

            for (int h = 0; h < hits.Length; h++)
            {
                if (hits[h].transform != null)
                {
                    hasHit = true;
                    break;
                }
            }

            if (!hasHit)
            {
                LineCastList(rays, radius, distance, setup, doLoop);
                return;
            }

            var greySetup = setup;

            greySetup.Color = Color.grey;
            for (int h = 0; h < hits.Length; h++)
            {
                LineCast(hits[h], rays[h], radius, distance, setup);

                if (doLoop || h < hits.Length - 1)
                {
                    var h1 = (h + 1) % hits.Length;

                    var d0 = hits[h].transform != null ? hits[h].distance : distance;
                    var d1 = hits[h1].transform != null ? hits[h1].distance : distance;
                    Line(DebugPlace.AToB(rays[h].origin + rays[h].direction * d0, rays[h1].origin + rays[h1].direction * d1), setup);

                    if (hits[h].transform != null || hits[h1].transform != null)
                    {
                        Line(DebugPlace.AToB(rays[h].origin + rays[h].direction * distance, rays[h1].origin + rays[h1].direction * distance), greySetup);
                    }
                }
            }
        }
Beispiel #13
0
 ///---------------------------------------------------------------------
 public static void Sphere(DebugPlace place)
 {
     Sphere(place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #14
0
 ///---------------------------------------------------------------------
 //Box: A box, several flavors available
 public static void Box(DebugPlace place)
 {
     Box(place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #15
0
 ///---------------------------------------------------------------------
 public static void Pie(DebugPlace place, Vector2 degrees)
 {
     Pie(place, degrees, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #16
0
 ///---------------------------------------------------------------------
 //Point: Three line to mark each axis
 public static void Point(DebugPlace place)
 {
     Point(place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #17
0
 ///---------------------------------------------------------------------
 public static void Arrow(DebugPlace place)
 {
     Arrow(place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #18
0
 ///---------------------------------------------------------------------
 #region Standard Primitives
 //Point: Three line to mark each axis
 public static void Line(DebugPlace place)
 {
     Line(place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #19
0
 ///---------------------------------------------------------------------
 public static void Plane(Plane plane, DebugPlace place)
 {
     Plane(plane, place, DebugDisplayRegistry.ActiveSetup);
 }
Beispiel #20
0
 ///---------------------------------------------------------------------
 public static void Capsule(DebugPlace place)
 {
     Capsule(place, DebugDisplayRegistry.ActiveSetup);
 }