コード例 #1
0
ファイル: TextureE.cs プロジェクト: BasmanovDaniil/Whoosh
        public static void DrawCircle(this Texture2D texture, IntVertex2 v0, int radius, Color color)
        {
            Action <int, int> draw = (x, y) => texture.SetPixel(x, y, color);

            BresenhamCircle(v0.x, v0.y, radius, draw);
            texture.Apply();
        }
コード例 #2
0
ファイル: Intersection.cs プロジェクト: BasmanovDaniil/Whoosh
        public static IntersectionType IntSegmentToIntSegmentE(IntVertex2 start0, IntVertex2 end0, IntVertex2 start1,
                                                               IntVertex2 end1, bool testBoundingBox = false)
        {
            IntSegment2 intersection;

            return(IntSegmentToIntSegmentE(start0.x, start0.y, end0.x, end0.y, start1.x, start1.y, end1.x, end1.y,
                                           out intersection, testBoundingBox));
        }
コード例 #3
0
ファイル: Intersection.cs プロジェクト: BasmanovDaniil/Whoosh
        public static bool IntSegmentToRay(IntVertex2 segmentStart, IntVertex2 segmentEnd, Vertex2 rayStart,
                                           Vertex2 rayEnd, out IntVertex2 intersection)
        {
            intersection = IntVertex2.zero;
            float r, s;

            if (LineToLine(rayStart, rayEnd, (Vertex2)segmentStart, (Vertex2)segmentEnd, out r, out s))
            {
                if (r >= 0)
                {
                    if (s >= 0 && s <= 1)
                    {
                        var inter = rayStart + (rayEnd - rayStart) * r;
                        intersection = new IntVertex2(inter.x, inter.y);
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #4
0
ファイル: PGUtils.cs プロジェクト: BasmanovDaniil/Whoosh
 public static IntVertex2 Perp(IntVertex2 vector)
 {
     return(new IntVertex2(-vector.y, vector.x));
 }
コード例 #5
0
ファイル: TextureE.cs プロジェクト: BasmanovDaniil/Whoosh
 public static void DrawGradientLine(this Texture2D texture, IntVertex2 v0, IntVertex2 v1, Color color0,
                                     Color color1)
 {
     DrawGradientLine(texture, v0.x, v0.y, v1.x, v1.y, color0, color1);
 }
コード例 #6
0
ファイル: TextureE.cs プロジェクト: BasmanovDaniil/Whoosh
 public static void DrawLine(this Texture2D texture, IntVertex2 v0, IntVertex2 v1, Color color, bool AA = false)
 {
     DrawLine(texture, v0.x, v0.y, v1.x, v1.y, color, AA);
 }
コード例 #7
0
ファイル: TextureE.cs プロジェクト: BasmanovDaniil/Whoosh
 private static void WuLine(IntVertex2 v0, IntVertex2 v1, Action <int, int, float> draw)
 {
     WuLine(v0.x, v0.y, v1.x, v1.y, draw);
 }
コード例 #8
0
ファイル: TextureE.cs プロジェクト: BasmanovDaniil/Whoosh
 public static void BresenhamLine(IntVertex2 v0, IntVertex2 v1, Action <int, int> draw)
 {
     BresenhamLine(v0.x, v0.y, v1.x, v1.y, draw);
 }
コード例 #9
0
ファイル: Intersection.cs プロジェクト: BasmanovDaniil/Whoosh
 public static bool IntSegmentToIntSegment(IntVertex2 start0, IntVertex2 end0, IntVertex2 start1, IntVertex2 end1,
                                           out IntSegment2 intersection, bool testBoundingBox = false)
 {
     return(IntSegmentToIntSegmentE(start0.x, start0.y, end0.x, end0.y, start1.x, start1.y, end1.x, end1.y,
                                    out intersection, testBoundingBox) != IntersectionType.None);
 }
コード例 #10
0
 public IntSegment2(IntVertex2 b)
 {
     a      = IntVertex2.zero;
     this.b = b;
 }
コード例 #11
0
 public IntSegment2(IntVertex2 a, IntVertex2 b)
 {
     this.a = a;
     this.b = b;
 }
コード例 #12
0
 public IntSegment2(IntSegment2 segment)
 {
     a = segment.a;
     b = segment.b;
 }
コード例 #13
0
ファイル: Intersection.cs プロジェクト: BasmanovDaniil/Whoosh
 public static bool IntSegmentToRay(IntVertex2 v0, IntVertex2 v1, Ray2D ray, out IntVertex2 intersection)
 {
     return(IntSegmentToRay(v0, v1, ray.origin, ray.origin + ray.direction, out intersection));
 }
コード例 #14
0
ファイル: Intersection.cs プロジェクト: BasmanovDaniil/Whoosh
 public static bool IntSegmentToRay(IntSegment2 segment, Ray2D ray, out IntVertex2 intersection)
 {
     return(IntSegmentToRay(segment.a, segment.b, ray, out intersection));
 }
コード例 #15
0
ファイル: PGUtils.cs プロジェクト: BasmanovDaniil/Whoosh
 public static int PerpDot(IntVertex2 a, IntVertex2 b)
 {
     return(a.x * b.y - a.y * b.x);
 }
コード例 #16
0
 public IntSegment2(int x0, int y0, int x1, int y1)
 {
     a = new IntVertex2(x0, y0);
     b = new IntVertex2(x1, y1);
 }
コード例 #17
0
ファイル: PGUtils.cs プロジェクト: BasmanovDaniil/Whoosh
 /// <summary>
 /// More than 0 - left, less than 0 - right, equals 0 - on line
 /// </summary>
 public static int LocatePointOnLine(IntVertex2 line1, IntVertex2 line2, IntVertex2 point)
 {
     return((line2.x - line1.x) * (point.y - line1.y) - (point.x - line1.x) * (line2.y - line1.y));
 }
コード例 #18
0
        public static float IntLineSegmentToIntLineSegment(IntSegment2 S1, IntSegment2 S2)
        {
            IntVertex2 u = S1.b - S1.a;
            IntVertex2 v = S2.b - S2.a;
            IntVertex2 w = S1.a - S2.a;
            float      a = IntVertex2.Dot(u, u); // always >= 0
            float      b = IntVertex2.Dot(u, v);
            float      c = IntVertex2.Dot(v, v); // always >= 0
            float      d = IntVertex2.Dot(u, w);
            float      e = IntVertex2.Dot(v, w);
            float      D = a * c - b * b; // always >= 0
            float      sN, sD = D;        // sc = sN / sD, default sD = D >= 0
            float      tN, tD = D;        // tc = tN / tD, default tD = D >= 0

            // compute the line parameters of the two closest points
            if (D < Mathf.Epsilon)
            {
                // the lines are almost parallel
                sN = 0; // force using point P0 on segment S1
                sD = 1; // to prevent possible division by 0.0 later
                tN = e;
                tD = c;
            }
            else
            {
                // get the closest points on the infinite lines
                sN = (b * e - c * d);
                tN = (a * e - b * d);
                if (sN < 0)
                {
                    // sc < 0 => the s=0 edge is visible
                    sN = 0;
                    tN = e;
                    tD = c;
                }
                else if (sN > sD)
                {
                    // sc > 1  => the s=1 edge is visible
                    sN = sD;
                    tN = e + b;
                    tD = c;
                }
            }

            if (tN < 0)
            {
                // tc < 0 => the t=0 edge is visible
                tN = 0;
                // recompute sc for this edge
                if (-d < 0)
                {
                    sN = 0;
                }
                else if (-d > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = -d;
                    sD = a;
                }
            }
            else if (tN > tD)
            {
                // tc > 1  => the t=1 edge is visible
                tN = tD;
                // recompute sc for this edge
                if ((-d + b) < 0)
                {
                    sN = 0;
                }
                else if ((-d + b) > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = (-d + b);
                    sD = a;
                }
            }
            // finally do the division to get sc and tc
            float sc = (Mathf.Abs(sN) < Mathf.Epsilon ? 0 : sN / sD);
            float tc = (Mathf.Abs(tN) < Mathf.Epsilon ? 0 : tN / tD);

            // get the difference of the two closest points
            IntVertex2 dP = w + (sc * u) - (tc * v); // =  S1(sc) - S2(tc)

            return(dP.magnitude);                    // return the closest distance
        }