コード例 #1
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
            }
        }
コード例 #2
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
            }
        }
コード例 #3
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
        }
コード例 #4
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
                }
            }
        }
コード例 #5
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
            }
        }
コード例 #6
0
ファイル: DebugDraw.cs プロジェクト: touky/Prateek
        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);
                    }
                }
            }
        }