Beispiel #1
0
        public void initial()
        {
            //int m = 0;
            a[1] = new Point(cuxi, this.Height * 15 / 16);
            a[2] = new Point(this.Width * 3 / 16, this.Height * 15 / 16);
            a[3] = new Point(this.Width * 13 / 32, this.Height * 15 / 16);
            a[4] = new Point(this.Width * 10 / 16, this.Height * 15 / 16);
            a[5] = new Point(this.Width * 4 / 16, this.Height * 13 / 16);
            a[6] = new Point(this.Width * 10 / 16, this.Height * 1 / 16);
            a[7] = new Point(this.Width * 16 / 16, this.Height * 1 / 16);
            line.Clear();
            //myLine myline = new myLine(a[1], a[2], 1);
            //line.Add(myline);
            myLine myline = new myLine(a[2], a[3], 2);

            line.Add(myline);
            myline = new myLine(a[3], a[4], 3);
            line.Add(myline);
            myline = new myLine(a[2], a[5], 4);
            line.Add(myline);
            myline = new myLine(a[5], a[6], 5);
            line.Add(myline);
            myline = new myLine(a[6], a[7], 6);
            line.Add(myline);
            pictureBox1.Width  = this.Width;
            pictureBox1.Height = this.Height;
        }
    /* End line collision detection */
    private bool isPoylogonCollide()
    {
        if (pointsList.Count < 2)
        {
            return(false);
        }
        int TotalLines = pointsList.Count - 1;

        myLine[] lines = new myLine[TotalLines];

        if (TotalLines > 1)
        {
            for (int i = 0; i < TotalLines; i++)
            {
                lines [i].StartPoint = (Vector3)pointsList [i];
                lines [i].EndPoint   = (Vector3)pointsList [i + 1];
            }
        }
        for (int i = 0; i < TotalLines; i++)
        {
            for (int j = 0; j < AllLines.Count; j++)
            {
                if (doIntersect(lines [i].StartPoint, lines [i].EndPoint, AllLines [j].StartPoint, AllLines [j].EndPoint))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Beispiel #3
0
        private void LoadCanvas_Click(object sender, RoutedEventArgs e)
        {
            List <JsonObject> objects        = new List <JsonObject>();
            OpenFileDialog    openFileDialog = new OpenFileDialog();

            openFileDialog.CheckFileExists = true;
            openFileDialog.ShowDialog();

            if (openFileDialog.FileName.Trim() != string.Empty)
            {
                using (StreamReader r = new StreamReader(openFileDialog.FileName))
                {
                    string jsonString = r.ReadToEnd();
                    objects = JsonConvert.DeserializeObject <List <JsonObject> >(jsonString);
                }
            }
            foreach (var obj in objects)
            {
                if (obj.shapeType.Equals("Line"))
                {
                    var newLine = new myLine(new Point((double)obj.x1, (double)obj.y1), new Point((double)obj.x2, (double)obj.y2));
                    _pen.Down(newLine);
                }
                else if (obj.shapeType.Equals("Rectangle"))
                {
                    var newRectangle = new myRectangle(new Point((double)obj.x1, (double)obj.y1), new Point((double)obj.x1 + (double)obj.width, (double)obj.y1 + (double)obj.height));
                    _pen.Down(newRectangle);
                }
                else if (obj.shapeType.Equals("Ellipse"))
                {
                    var newCricle = new myCircle(new Point((double)obj.x1 + (double)obj.r, (double)obj.y1 + (double)obj.r), (double)obj.r);
                    _pen.Down(newCricle);
                }
            }
        }
Beispiel #4
0
    //  -----------------------------------
    //  Following method checks is currentLine(line drawn by last two points) collided with line
    //  -----------------------------------
    private bool isLineCollide()
    {
        if (pointsList.Count < 2)
        {
            return(false);
        }
        int TotalLines = pointsList.Count - 1;

        myLine[] lines = new myLine[TotalLines];
        if (TotalLines > 1)
        {
            for (int i = 0; i < TotalLines; i++)
            {
                lines[i].StartPoint = (Vector3)pointsList[i];
                lines[i].EndPoint   = (Vector3)pointsList[i + 1];
            }
        }
        for (int i = 0; i < TotalLines - 1; i++)
        {
            myLine currentLine;
            currentLine.StartPoint = (Vector3)pointsList[pointsList.Count - 2];
            currentLine.EndPoint   = (Vector3)pointsList[pointsList.Count - 1];
            if (isLinesIntersect(lines[i], currentLine))
            {
                return(true);
            }
        }
        return(false);
    }
    //private void OnDrawGizmos()
    //{
    //    foreach (var v in tomark)
    //    {
    //        Gizmos.DrawSphere(v, 0.1f);
    //    }
    //}
    private bool isLineCollide()
    {
        if (rend.positionCount < 2)
        {
            return(false);
        }
        int TotalLines = rend.positionCount - 1;

        myLine[] lines = new myLine[TotalLines];
        if (TotalLines > 1)
        {
            for (int i = 0; i < TotalLines; i++)
            {
                lines[i].StartPoint = rend.GetPosition(i);
                lines[i].EndPoint   = rend.GetPosition(i + 1);
            }
        }
        for (int i = 0; i < TotalLines - 1; i++)
        {
            myLine currentLine;
            currentLine.StartPoint = rend.GetPosition(rend.positionCount - 2);
            currentLine.EndPoint   = rend.GetPosition(rend.positionCount - 1);
            if (isLinesIntersect(lines[i], currentLine))
            {
                lastIntersection1 = lines[i].StartPoint;
                lastIntersection2 = currentLine.StartPoint;
                intersectIndex    = i;
                return(true);
            }
        }
        return(false);
    }
    Orientation isEnemyZoneCollide()
    {
        List <Vector2> pointsList = GameController.Inst.GetEnemyZone();

        for (int i = 0; i < pointsList.Count; i++)
        {
            int    nextIndex = (i < pointsList.Count - 1) ? i + 1 : 0;
            myLine line      = new myLine()
            {
                StartPoint = pointsList[i], EndPoint = pointsList[nextIndex]
            };
            if (LineHelper.isVectorIntersect(transform.position, line, 0.02f))
            {
                if ((line.StartPoint.x - line.EndPoint.x) < 0.2f && (line.StartPoint.x - line.EndPoint.x) > -0.2f)
                {
                    return(Orientation.Vertical);
                }
                else if ((line.StartPoint.y - line.EndPoint.y) < 0.2f && (line.StartPoint.y - line.EndPoint.y) > -0.2f)
                {
                    return(Orientation.Horizontal);
                }
            }
        }
        if (!LineHelper.IsPointInPolygon(pointsList, transform.position))
        {
            return(Orientation.Vertical);
        }
        return(Orientation.NONE);
    }
Beispiel #7
0
    //    -----------------------------------
    //    Following method checks whether given two line intersect or not
    //    -----------------------------------
    private bool isLinesIntersect(myLine L1, myLine L2)
    {
        if (checkPoints (L1.StartPoint, L2.StartPoint) ||
            checkPoints (L1.StartPoint, L2.EndPoint) ||
            checkPoints (L1.EndPoint, L2.StartPoint) ||
            checkPoints (L1.EndPoint, L2.EndPoint))
            return false;

        return((Mathf.Max (L1.StartPoint.x, L1.EndPoint.x) >= Mathf.Min (L2.StartPoint.x, L2.EndPoint.x)) &&
               (Mathf.Max (L2.StartPoint.x, L2.EndPoint.x) >= Mathf.Min (L1.StartPoint.x, L1.EndPoint.x)) &&
               (Mathf.Max (L1.StartPoint.y, L1.EndPoint.y) >= Mathf.Min (L2.StartPoint.y, L2.EndPoint.y)) &&
               (Mathf.Max (L2.StartPoint.y, L2.EndPoint.y) >= Mathf.Min (L1.StartPoint.y, L1.EndPoint.y))
               );
    }
Beispiel #8
0
    private bool isLinesIntersect(myLine L1, myLine L2)
    {
        if (checkPoints(L1.StartPoint, L2.StartPoint) ||
            checkPoints(L1.StartPoint, L2.EndPoint) ||
            checkPoints(L1.EndPoint, L2.StartPoint) ||
            checkPoints(L1.EndPoint, L2.EndPoint))
        {
            return(false);
        }

        return((Mathf.Max(L1.StartPoint.x, L1.EndPoint.x) >= Mathf.Min(L2.StartPoint.x, L2.EndPoint.x)) &&
               (Mathf.Max(L2.StartPoint.x, L2.EndPoint.x) >= Mathf.Min(L1.StartPoint.x, L1.EndPoint.x)) &&
               (Mathf.Max(L1.StartPoint.y, L1.EndPoint.y) >= Mathf.Min(L2.StartPoint.y, L2.EndPoint.y)) &&
               (Mathf.Max(L2.StartPoint.y, L2.EndPoint.y) >= Mathf.Min(L1.StartPoint.y, L1.EndPoint.y)));
    }
    //	-----------------------------------
    //	Following method checks whether given two line intersect or not
    //	-----------------------------------
    public static bool isLinesIntersect(myLine L1, myLine L2, float zone = 0f)
    {
        if (checkPoints(L1.StartPoint, L2.StartPoint) ||
            checkPoints(L1.StartPoint, L2.EndPoint) ||
            checkPoints(L1.EndPoint, L2.StartPoint) ||
            checkPoints(L1.EndPoint, L2.EndPoint))
        {
            return(false);
        }

        return((Mathf.Max(L1.StartPoint.x, L1.EndPoint.x) + zone >= Mathf.Min(L2.StartPoint.x, L2.EndPoint.x) - zone) &&
               (Mathf.Max(L2.StartPoint.x, L2.EndPoint.x) + zone >= Mathf.Min(L1.StartPoint.x, L1.EndPoint.x) - zone) &&
               (Mathf.Max(L1.StartPoint.y, L1.EndPoint.y) + zone >= Mathf.Min(L2.StartPoint.y, L2.EndPoint.y) - zone) &&
               (Mathf.Max(L2.StartPoint.y, L2.EndPoint.y) + zone >= Mathf.Min(L1.StartPoint.y, L1.EndPoint.y) - zone)
               );
    }
        public void initial()
        {
            int m = 0;

            a[1] = new Point(0, m / 2 + (this.Height - m) * 15 / 16);
            a[2] = new Point(this.Width * 4 / 16, m / 2 + (this.Height - m) * 15 / 16);
            a[3] = new Point(this.Width * 5 / 16, m / 2 + (this.Height - m) * 15 / 16);
            a[4] = new Point(this.Width * 16 / 16, m / 2 + (this.Height - m) * 15 / 16);
            a[5] = new Point(this.Width * 5 / 16, m / 2 + (this.Height - m) * 13 / 16);
            a[6] = new Point(this.Width * 8 / 16, m / 2 + (this.Height - m) * 8 / 16);
            b[1] = new Point(this.Width * 16 / 16, m / 2 + (this.Height - m) * 1 / 16);
            b[2] = new Point(this.Width * 12 / 16, m / 2 + (this.Height - m) * 1 / 16);
            b[3] = new Point(this.Width * 11 / 16, m / 2 + (this.Height - m) * 1 / 16);
            b[4] = new Point(this.Width * 0 / 16, m / 2 + (this.Height - m) * 1 / 16);
            b[5] = new Point(this.Width * 11 / 16, m / 2 + (this.Height - m) * 3 / 16);
            b[6] = new Point(this.Width * 8 / 16, m / 2 + (this.Height - m) * 8 / 16);
            linea.Clear();
            lineb.Clear();
            myLine myline = new myLine(a[1], a[2], 1);

            linea.Add(myline);
            myline = new myLine(a[2], a[3], 2);
            linea.Add(myline);
            myline = new myLine(a[3], a[4], 3);
            linea.Add(myline);
            myline = new myLine(a[2], a[5], 4);
            linea.Add(myline);
            myline = new myLine(a[5], a[6], 5);
            linea.Add(myline);

            myline = new myLine(b[1], b[2], 1);
            lineb.Add(myline);
            myline = new myLine(b[2], b[3], 2);
            lineb.Add(myline);
            myline = new myLine(b[3], b[4], 3);
            lineb.Add(myline);
            myline = new myLine(b[2], b[5], 4);
            lineb.Add(myline);
            myline = new myLine(b[5], b[6], 5);
            lineb.Add(myline);

            pictureBox1.Width  = this.Width;
            pictureBox1.Height = this.Height;
        }
    //	-----------------------------------
    //  Following method checks are two Arrays of point Collided
    //	-----------------------------------
    public static bool areLinesCollide(List <Vector2> pointsList1, List <Vector2> pointsList2)
    {
        if (pointsList1.Count < 2 || pointsList2.Count < 2)
        {
            return(false);
        }

        int TotalLines1 = pointsList1.Count - 1;

        myLine[] lines1 = new myLine[TotalLines1];
        if (TotalLines1 > 1)
        {
            for (int i = 0; i < TotalLines1; i++)
            {
                lines1[i].StartPoint = (Vector3)pointsList1[i];
                lines1[i].EndPoint   = (Vector3)pointsList1[i + 1];
            }
        }

        int TotalLines2 = pointsList2.Count - 1;

        myLine[] lines2 = new myLine[TotalLines2];
        if (TotalLines2 > 1)
        {
            for (int i = 0; i < TotalLines2; i++)
            {
                lines2[i].StartPoint = (Vector3)pointsList2[i];
                lines2[i].EndPoint   = (Vector3)pointsList2[i + 1];
            }
        }

        for (int i = 0; i < TotalLines1; i++)
        {
            for (int j = 0; j < TotalLines2; j++)
            {
                if (isLinesIntersect(lines1[i], lines2[j]))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Beispiel #12
0
 private bool isLineCollide()
 {
     if (pointsList.Count < 2) return false;
     int TotalLines = (pointsList.Count - 1)/2;
     myLine[] lines = new myLine[TotalLines];
     if (TotalLines > 1) {
         for (int i=0; i<TotalLines; i++) {
             lines [i].StartPoint = (Vector3)pointsList [i];
             lines [i].EndPoint = (Vector3)pointsList [i + 1];
         }
     }
     for (int i=0; i<TotalLines-1; i++) {
         myLine currentLine;
         currentLine.StartPoint = (Vector3)pointsList [pointsList.Count - 2];
         currentLine.EndPoint = (Vector3)pointsList [pointsList.Count - 1];
         if (isLinesIntersect (lines [i], currentLine))
             return true;
     }
     return false;
 }
    //	-----------------------------------
    //	Following method checks whether given point intersect with line
    //	-----------------------------------
    public static bool isVectorIntersect(Vector2 V1, myLine L2, float zone = 0.04f)
    {
        if (checkPoints(V1, L2.StartPoint) || checkPoints(V1, L2.EndPoint))
        {
            return(true);
        }
        float xMin = Mathf.Min(L2.StartPoint.x, L2.EndPoint.x);

        xMin -= zone;
        float xMax = Mathf.Max(L2.StartPoint.x, L2.EndPoint.x);

        xMax += zone;
        float yMin = Mathf.Min(L2.StartPoint.y, L2.EndPoint.y);

        yMin -= zone;
        float yMax = Mathf.Max(L2.StartPoint.y, L2.EndPoint.y);

        yMax += zone;

        return((V1.x >= xMin) && (xMax >= V1.x) &&
               (V1.y >= yMin) && (yMax >= V1.y));
    }
Beispiel #14
0
        public void rysujButton_Click(object sender, RoutedEventArgs e)
        {
            switch (currentShape)
            {
            case Shapes.Line:
                if (!checkInputs(Shapes.Line))
                {
                    var newLine = new myLine(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                             new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x2")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y2")).Text)));

                    _pen.Down(newLine);
                }
                break;

            case Shapes.Rectangle:
                if (!checkInputs(Shapes.Rectangle))
                {
                    var newRectangle = new myRectangle(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                                       new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x2")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y2")).Text)));

                    _pen.Down(newRectangle);
                }
                break;

            case Shapes.Circle:
                if (!checkInputs(Shapes.Circle))
                {
                    var newCricle = new myCircle(new Point(Convert.ToDouble(((TextBox)this.inputs.FindName("x1")).Text), Convert.ToDouble(((TextBox)this.inputs.FindName("y1")).Text)),
                                                 Convert.ToDouble(((TextBox)this.inputs.FindName("r")).Text));

                    _pen.Down(newCricle);
                }
                break;

            default:
                break;
            }
        }
Beispiel #15
0
    public bool isLineCollide(Vector3 start, Vector3 end, ref Vector2 intersect)
    {
        Vector2 p3 = new Vector2(start.x, start.y);
        Vector2 p4 = new Vector2(end.x, end.y);

        if (pointsList.Count < 2)
        {
            return(false);
        }
        int TotalLines = pointsList.Count - 1;

        myLine[] lines = new myLine[TotalLines];
        if (TotalLines > 1)
        {
            for (int i = 0; i < TotalLines; i++)
            {
                lines [i].StartPoint = (Vector3)pointsList [i];
                lines [i].EndPoint   = (Vector3)pointsList [i + 1];
            }
        }
        for (int i = 0; i < TotalLines - 1; i++)
        {
//			myLine currentLine;
//			currentLine.StartPoint = start;
//			currentLine.EndPoint = end;
//			if (isLinesIntersect (lines [i], currentLine))
//				return true;
            Vector2 p1 = new Vector2(lines [i].StartPoint.x, lines [i].StartPoint.y);
            Vector2 p2 = new Vector2(lines [i].EndPoint.x, lines [i].EndPoint.y);
            if (LineIntersection(p1, p2, p3, p4, ref intersect))
            {
                Debug.Log(intersect);
                return(true);
            }
        }
        return(false);
    }
Beispiel #16
0
    void Start()
    {
        gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();

        generateNewLine = true;
        currentLine     = 0;

        linesFromfile = GameObject.FindGameObjectWithTag("DataTraveler").GetComponent <Data>().storyContent.Split('\n');

        ribbon = Instantiate(Resources.Load("RibbonVibrator"), new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject;

        for (int i = 0; i < (linesFromfile.Length / 17) + 1; i++)
        {
            GameObject paperAux = Instantiate(Resources.Load("paperBackround"), new Vector3(0.0f, (i * (-38)) - 17, 0.0f), Quaternion.identity) as GameObject;
            allPapers.Add(paperAux);
        }

        for (int lineNumber = 0; lineNumber < linesFromfile.Length; lineNumber++)
        {
            myLine line = new myLine();
            line.letterToCheckPos = 0;
            line.letterCount      = linesFromfile[lineNumber].Length;

            int halfSize = linesFromfile[lineNumber].Length / 2;

            for (int i = 0; i < linesFromfile[lineNumber].Length; i++)
            {
                GameObject letterAux = Instantiate(Resources.Load("Letter"), new Vector3(-(halfSize / 2) + i * 0.5f, -lineNumber * 2 - ((lineNumber / 17) * 4.0f), 0.0f), Quaternion.identity) as GameObject;
                letterAux.GetComponent <TextMesh>().text = linesFromfile[lineNumber][i].ToString();
                line.letters.Add(letterAux);
                allLetters.Add(letterAux);
            }
            allLines.Add(line);
        }

        ribbon.transform.position = allLines[0].letters[0].transform.position;
    }
    }//end update

    private bool lineCollider()
    {
        if (pointsList.Count < 2) { return false; }

        int TotalLines = pointsList.Count - 1;
        myLine[] lines = new myLine[TotalLines];

        if (TotalLines > 1)
        {
            for (int i = 0; i < TotalLines; i++)
            {
                lines[i].startPoint = (Vector3)pointsList[i];
                lines[i].endPoint = (Vector3)pointsList[i + 1];
            }
        }

        for (int i = 0; i < TotalLines - 1; i++)
        {
            myLine currentLine;
            currentLine.startPoint = (Vector3)pointsList[pointsList.Count - 2];
            currentLine.endPoint = (Vector3)pointsList[pointsList.Count - 1];

            if (intersection(lines[i], currentLine)) { return true; }
        }

        return false;
    }//end line collider
Beispiel #18
0
    bool isLinesIntersect(myLine L1, myLine L2)
    {
        dot  = Vector3.Dot(L1.S - L1.E, L2.S - L2.E);
        l    = (L1.S - L1.E).magnitude * (L2.S - L2.E).magnitude;
        minX = maxX = TrailRecord[CircleStart + 1].x;
        minZ = maxZ = TrailRecord[CircleStart + 1].z;


        if (checkPoints(L1.S, L2.S) ||
            checkPoints(L1.S, L2.E) ||
            checkPoints(L1.E, L2.S) ||
            checkPoints(L1.E, L2.E))
        {
            return(false);
        }

        if (dot == l)
        {
            return(false);
        }
        if (dot * (-1) == l)
        {
            return(false);
        }

        if ((Mathf.Max(L1.S.x, L1.E.x) >= Mathf.Min(L2.S.x, L2.E.x)) &&
            (Mathf.Max(L2.S.x, L2.E.x) >= Mathf.Min(L1.S.x, L1.E.x)) &&
            (Mathf.Max(L1.S.z, L1.E.z) >= Mathf.Min(L2.S.z, L2.E.z)) &&
            (Mathf.Max(L2.S.z, L2.E.z) >= Mathf.Min(L1.S.z, L1.E.z)))
        {
            for (int i = CircleStart + 1; i < numPositions - 1; i++)
            {
                if (TrailRecord[i].x < minX)
                {
                    minX = TrailRecord[i].x;
                }
                if (TrailRecord[i].x > maxX)
                {
                    maxX = TrailRecord[i].x;
                }
                if (TrailRecord[i].z < minZ)
                {
                    minZ = TrailRecord[i].z;
                }
                if (TrailRecord[i].z > maxZ)
                {
                    maxZ = TrailRecord[i].z;
                }
            }
            area = (maxX - minX) * (maxZ - minZ);
            if ((maxX - minX) < 1.0f)
            {
                area /= 10.0f;
            }
            if ((maxZ - minZ) < 1.0f)
            {
                area /= 10.0f;
            }

            if (area > 10)
            {
                return(true);
            }
        }

        return(false);
    }
    private bool intersection(myLine L1, myLine L2)
    {
        if (checkPoints(L1.startPoint, L2.startPoint) ||
            checkPoints(L1.startPoint, L2.endPoint) ||
            checkPoints(L1.endPoint, L2.startPoint) ||
            checkPoints(L1.endPoint, L2.endPoint))
            return false;

        return ((Mathf.Max(L1.startPoint.x, L1.endPoint.x) >= Mathf.Min(L2.startPoint.x, L2.endPoint.x)) &&
               (Mathf.Max(L2.startPoint.x, L2.endPoint.x) >= Mathf.Min(L1.startPoint.x, L1.endPoint.x)) &&
               (Mathf.Max(L1.startPoint.y, L1.endPoint.y) >= Mathf.Min(L2.startPoint.y, L2.endPoint.y)) &&
               (Mathf.Max(L2.startPoint.y, L2.endPoint.y) >= Mathf.Min(L1.startPoint.y, L1.endPoint.y))
               );
    }