Beispiel #1
0
    public override void deflate()
    {
        // string typeOfTiling = Regex.Match(name, @"([A-Z]\w+)").Groups[0].Value;
        Vector3 C = worldVertex2 * helperFunctionsClass.GOLDENRATIO;
        Vector3 B = worldVertex1 * helperFunctionsClass.GOLDENRATIO;
        Vector3 A = worldVertex3 * helperFunctionsClass.GOLDENRATIO;


        if (typeOfTiling == "Thick" || typeOfTiling == "Thin")
        {
            // // for tests
            // A += new Vector3(1, 0);
            // B += new Vector3(1, 0);
            // C += new Vector3(1, 0);

            Vector3 Q = B + (A - B) / helperFunctionsClass.GOLDENRATIO;
            Vector3 R = B + (C - B) / helperFunctionsClass.GOLDENRATIO;

            float rotate1;
            float rotate2;
            float rotate3;

            int matchingCase1;
            int matchingCase2;
            int matchingCase3;

            thickRhomb newTile1 = new thickRhomb();
            thickRhomb newTile2 = new thickRhomb();
            thinRhomb  newTile3 = new thinRhomb();

            if (mirrored)
            {
                // _deflate(typeof(blueTile), R, B, Q, false, "leftThick", blueTag);
                // blueTag++;
                // _deflate(typeof(redTile), Q, A, R, false, "topThin", redTile.redTag);
                // redTile.redTag++;
                // _deflate(typeof(blueTile), A, C, R, true, "rightThick", blueTag);
                // blueTag++;

                Vector3 ver4 = helperFunctionsClass.fourthVer(Q, B, R);
                Vector3 ver5 = helperFunctionsClass.fourthVer(R, A, Q);
                Vector3 ver6 = helperFunctionsClass.fourthVer(R, A, C);


                // Sort this angle and matching case

                switch (matchingCase)
                {
                case 1:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation - 180;
                    rotate3 = tileRotation;

                    matchingCase1 = 1;
                    matchingCase2 = 5;
                    matchingCase3 = 1;

                    break;

                case 2:

                    rotate1 = tileRotation - 180;
                    rotate2 = tileRotation + 72;
                    rotate3 = tileRotation - 72;

                    matchingCase1 = 2;
                    matchingCase2 = 5;
                    matchingCase3 = 2;

                    break;

                case 3:

                    rotate1 = tileRotation - 180;
                    rotate2 = tileRotation;
                    rotate3 = tileRotation;

                    matchingCase1 = 3;
                    matchingCase2 = 5;
                    matchingCase3 = 3;

                    break;

                case 4:

                    rotate1 = tileRotation - 180;
                    rotate2 = tileRotation - 108;
                    rotate3 = tileRotation - 72;

                    matchingCase1 = 4;
                    matchingCase2 = 5;
                    matchingCase3 = 4;

                    break;

                default:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation;
                    rotate3 = tileRotation + 36;

                    matchingCase1 = 5;
                    matchingCase2 = 2;
                    matchingCase3 = 1;

                    break;
                }

                newTile1.InitUser(B, R, ver4, Q, rotate1, matchingCase1);
                newTile2.InitUser(A, C, R, ver6, rotate2, matchingCase2);
                newTile3.InitUser(A, Q, ver5, R, rotate3, matchingCase3);
            }

            else
            {
                // _deflate(typeof(blueTile), B, R, Q, true, "rightThick", blueTag);
                // blueTag++;
                // _deflate(typeof(redTile), A, Q, R, true, "bottomThin", redTile.redTag);
                // redTile.redTag++;
                // _deflate(typeof(blueTile), C, A, R, false, "leftThick", blueTag);
                // blueTag++;

                Vector3 ver4 = helperFunctionsClass.fourthVer(Q, B, R);
                Vector3 ver5 = helperFunctionsClass.fourthVer(R, A, Q);
                Vector3 ver6 = helperFunctionsClass.fourthVer(R, A, C);

                switch (matchingCase)
                {
                case 1:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation + 108;
                    rotate3 = tileRotation + 72;

                    matchingCase1 = 1;
                    matchingCase2 = 5;
                    matchingCase3 = 1;

                    break;

                case 2:

                    rotate1 = tileRotation - 180;
                    rotate2 = tileRotation;
                    rotate3 = tileRotation;

                    matchingCase1 = 2;
                    matchingCase2 = 5;
                    matchingCase3 = 2;

                    break;

                case 3:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation - 72;
                    rotate3 = tileRotation + 72;

                    matchingCase1 = 3;
                    matchingCase2 = 5;
                    matchingCase3 = 3;

                    break;

                case 4:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation - 180;
                    rotate3 = tileRotation;

                    matchingCase1 = 4;
                    matchingCase2 = 5;
                    matchingCase3 = 4;

                    break;

                default:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation - 180;
                    rotate3 = tileRotation - 72;

                    matchingCase1 = 5;
                    matchingCase2 = 1;
                    matchingCase3 = 3;

                    break;
                }

                newTile1.InitUser(B, R, Q, ver4, rotate1, matchingCase1);
                newTile2.InitUser(A, C, ver6, R, rotate2, matchingCase2);
                newTile3.InitUser(A, Q, R, ver5, rotate3, matchingCase3);
            }
        }

        else if (typeOfTiling == "Dart" || typeOfTiling == "Kite")
        {
            // // for tests
            // A += new Vector3(1, 0);
            // B += new Vector3(1, 0);
            // C += new Vector3(1, 0);

            Vector3 P = B + (C - B) / helperFunctionsClass.GOLDENRATIO;

            if (mirrored)
            {
                _deflate(typeof(redTile), A, P, B, false, "rightKite", redTile.redTag);
                redTile.redTag++;
                _deflate(typeof(blueTile), A, C, P, true, "rightDart", blueTag);
                blueTag++;
            }

            else
            {
                _deflate(typeof(redTile), P, A, B, true, "leftKite", redTile.redTag);
                redTile.redTag++;
                _deflate(typeof(blueTile), C, A, P, false, "leftDart", blueTag);
                blueTag++;
            }
        }
    }
        static void addThickRhomb(string tileType, int closestEdge, Vector3[] closestEdgeVec, float currentRotation, int previousCase, tile closestTile)
        {
            thickRhomb newTile = new thickRhomb();

            Vector3 ver1;
            Vector3 ver2;
            Vector3 ver3;
            Vector3 ver4;

            float rotation;

            // Debug.Log(closestEdge);

            if (tileType == "thinRhomb")
            {
                switch (closestEdge)
                {
                case 1:

                    ver1 = closestEdgeVec[0];
                    ver4 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation + 72;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation + 36;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation - 108;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation - 144;
                    }

                    else
                    {
                        rotation = currentRotation + 72;
                    }

                    ver2 = helperFunctionsClass.thirdVer(ver4, rotation, helperFunctionsClass.redSides);

                    ver3 = helperFunctionsClass.fourthVer(ver4, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, closestEdge);

                    break;

                case 2:

                    ver2 = closestEdgeVec[0];
                    ver3 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation - 72;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation - 108;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation + 108;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation + 72;
                    }

                    else
                    {
                        rotation = currentRotation - 72;
                    }

                    ver1 = helperFunctionsClass.thirdVer(ver3, rotation, helperFunctionsClass.redSides);

                    ver4 = helperFunctionsClass.fourthVer(ver3, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, 3);

                    break;

                case 3:

                    ver4 = closestEdgeVec[0];
                    ver2 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation - 72;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation - 108;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation + 108;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation + 72;
                    }

                    else
                    {
                        rotation = currentRotation - 72;
                    }

                    ver1 = helperFunctionsClass.thirdVer(ver4, rotation, helperFunctionsClass.redSides);

                    ver3 = helperFunctionsClass.fourthVer(ver4, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, 2);

                    break;

                case 4:

                    ver3 = closestEdgeVec[0];
                    ver1 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation + 144;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation + 108;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation - 36;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation - 72;
                    }

                    else
                    {
                        rotation = currentRotation + 144;
                    }

                    ver2 = helperFunctionsClass.thirdVer(ver3, rotation, helperFunctionsClass.redSides);

                    ver4 = helperFunctionsClass.fourthVer(ver3, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, 4);

                    break;
                }
            }

            else if (tileType == "thickRhomb")
            {
                switch (closestEdge)
                {
                case 1:

                    ver1 = closestEdgeVec[0];
                    ver4 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation + 72;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation - 36;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation - 108;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation + 144;
                    }

                    else
                    {
                        rotation = currentRotation + 108;
                    }

                    ver2 = helperFunctionsClass.thirdVer(ver4, rotation, helperFunctionsClass.redSides);

                    ver3 = helperFunctionsClass.fourthVer(ver4, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, closestEdge);

                    break;

                case 2:

                    ver2 = closestEdgeVec[1];
                    ver4 = closestEdgeVec[0];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation + 36;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation - 72;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation - 144;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation + 108;
                    }

                    else
                    {
                        rotation = currentRotation + 72;
                    }

                    ver1 = helperFunctionsClass.thirdVer(ver4, rotation, helperFunctionsClass.redSides);

                    ver3 = helperFunctionsClass.fourthVer(ver4, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, closestEdge);

                    break;

                case 3:

                    ver2 = closestEdgeVec[0];
                    ver3 = closestEdgeVec[1];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation - 108;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation + 144;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation + 72;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation - 36;
                    }

                    else
                    {
                        rotation = currentRotation - 72;
                    }

                    ver1 = helperFunctionsClass.thirdVer(ver3, rotation, helperFunctionsClass.redSides);

                    ver4 = helperFunctionsClass.fourthVer(ver3, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, closestEdge);
                    break;

                case 4:

                    ver1 = closestEdgeVec[1];
                    ver3 = closestEdgeVec[0];

                    if (previousCase == 1)
                    {
                        rotation = currentRotation - 144;
                    }

                    else if (previousCase == 2)
                    {
                        rotation = currentRotation + 108;
                    }

                    else if (previousCase == 3)
                    {
                        rotation = currentRotation + 36;
                    }

                    else if (previousCase == 4)
                    {
                        rotation = currentRotation - 72;
                    }

                    else
                    {
                        rotation = currentRotation - 108;
                    }

                    ver2 = helperFunctionsClass.thirdVer(ver3, rotation, helperFunctionsClass.redSides);

                    ver4 = helperFunctionsClass.fourthVer(ver3, ver2, ver1);

                    newTile.InitUser(ver1, ver2, ver3, ver4, rotation, closestEdge);

                    break;
                }
            }

            closestTile.neighbours[closestEdge - 1] = newTile;
        }
Beispiel #3
0
    public override void deflate()
    {
        Vector3 A = worldVertex3 * helperFunctionsClass.GOLDENRATIO;
        Vector3 B = worldVertex1 * helperFunctionsClass.GOLDENRATIO;
        Vector3 C = worldVertex2 * helperFunctionsClass.GOLDENRATIO;


        if (typeOfTiling == "Thin" || typeOfTiling == "Thick")
        {
            // // for tests
            // A += new Vector3(1, 0);
            // B += new Vector3(1, 0);
            // C += new Vector3(1, 0);

            Vector3 P = A + (B - A) / helperFunctionsClass.GOLDENRATIO;

            float rotate1;
            float rotate2;

            int matchingCase1;
            int matchingCase2;

            thickRhomb newTile1 = new thickRhomb();
            thinRhomb  newTile2 = new thinRhomb();

            if (mirrored)
            {
                // Initalise new tile with the required verticies and give it a matchingCase so the user can add to pattern after deflation

                // _deflate(typeof(redTile), B, P, C, true, "bottomThin", redTag);
                // redTag++;
                // _deflate(typeof(blueTile), A, C, P,true, "rightThick", blueTile.blueTag);
                // blueTile.blueTag++;

                Vector3 ver4 = helperFunctionsClass.fourthVer(C, B, P);
                Vector3 ver5 = helperFunctionsClass.fourthVer(P, C, A);

                switch (matchingCase)
                {
                case 1:

                    rotate1 = tileRotation - 144;
                    rotate2 = tileRotation - 180;

                    matchingCase1 = 1;
                    matchingCase2 = 1;

                    break;

                case 2:

                    rotate1 = tileRotation - 72;
                    rotate2 = tileRotation + 108;

                    matchingCase1 = 2;
                    matchingCase2 = 2;

                    break;

                case 3:

                    rotate1 = tileRotation - 144;
                    rotate2 = tileRotation + 108;

                    matchingCase1 = 3;
                    matchingCase2 = 3;

                    break;

                case 4:

                    rotate1 = tileRotation - 72;
                    rotate2 = tileRotation + 108;

                    matchingCase1 = 4;
                    matchingCase2 = 4;

                    break;

                default:

                    rotate1 = tileRotation + 180;
                    rotate2 = tileRotation + 108;

                    matchingCase1 = 5;
                    matchingCase2 = 1;

                    break;
                }

                newTile1.InitUser(A, C, P, ver5, rotate1, matchingCase1);
                newTile2.InitUser(B, P, C, ver4, rotate2, matchingCase2);
            }

            else
            {
                // _deflate(typeof(redTile), P, B, C, false, "topThin", redTag);
                // redTag++;
                // _deflate(typeof(blueTile), C, A, P, false, "leftThick", blueTile.blueTag);
                // blueTile.blueTag++;

                Vector3 ver4 = helperFunctionsClass.fourthVer(C, P, B);
                Vector3 ver5 = helperFunctionsClass.fourthVer(P, A, C);

                switch (matchingCase)
                {
                case 1:

                    rotate1 = tileRotation + 72;
                    rotate2 = tileRotation - 108;

                    matchingCase1 = 1;
                    matchingCase2 = 1;

                    break;

                case 2:

                    rotate1 = tileRotation + 144;
                    rotate2 = tileRotation - 108;

                    matchingCase1 = 2;
                    matchingCase2 = 2;

                    break;

                case 3:

                    rotate1 = tileRotation + 72;
                    rotate2 = tileRotation - 108;

                    matchingCase1 = 3;
                    matchingCase2 = 3;

                    break;

                case 4:

                    rotate1 = tileRotation + 144;
                    rotate2 = tileRotation - 108;

                    matchingCase1 = 4;
                    matchingCase2 = 4;

                    break;

                default:

                    rotate1 = tileRotation - 36;
                    rotate2 = tileRotation - 36;

                    matchingCase1 = 3;
                    matchingCase2 = 5;

                    break;
                }

                newTile1.InitUser(A, C, ver5, P, rotate1, matchingCase1);
                newTile2.InitUser(B, P, ver4, C, rotate2, matchingCase2);
            }
        }

        else if (typeOfTiling == "Kite" || typeOfTiling == "Dart")
        {
            // // for tests
            // A += new Vector3(1, 0);
            // B += new Vector3(1, 0);
            // C += new Vector3(1, 0);

            Vector3 P = A + (B - A) / helperFunctionsClass.GOLDENRATIO;
            Vector3 Q = C + (A - C) / helperFunctionsClass.GOLDENRATIO;

            if (mirrored)
            {
                _deflate(typeof(redTile), B, P, C, true, "leftKite", redTag);
                redTag++;
                Debug.Log("doing this non-mirror one");
                _deflate(typeof(redTile), P, Q, C, false, "rightKite", redTag);
                redTag++;
                _deflate(typeof(blueTile), P, A, Q, true, "rightDart", blueTile.blueTag);
                blueTile.blueTag++;
            }

            else
            {
                _deflate(typeof(redTile), P, B, C, false, "rightKite", redTag);
                redTag++;
                Debug.Log("doing this mirror one");
                _deflate(typeof(redTile), Q, P, C, true, "leftKite", redTag);
                redTag++;
                _deflate(typeof(blueTile), A, P, Q, false, "leftDart", blueTile.blueTag);
                blueTile.blueTag++;
            }
        }
    }
        void Update()
        {
            if ((manager.allObjects.Count != 0))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Vector3 mouseClickCoor = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    var     closestTile    = getClosestTile(manager.allObjects, mouseClickCoor);

                    if (closestTile.Item2 < 0.9)
                    {
                        updateMethod("left", closestTile.Item1, closestTile.Item3, closestTile.Item4);
                    }

                    else
                    {
                        if (manager.tileType == "P3")
                        {
                            thinRhomb newTile = new thinRhomb();
                            newTile.Init(mouseClickCoor);
                        }

                        else if (manager.tileType == "P2")
                        {
                            kiteTile newTile = new kiteTile();
                            newTile.Init(mouseClickCoor);
                        }
                    }
                }


                else if (Input.GetMouseButtonDown(1))
                {
                    Vector3 mouseClickCoor = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    var     closestTile    = getClosestTile(manager.allObjects, mouseClickCoor);

                    if (closestTile.Item2 < 0.9)
                    {
                        updateMethod("right", closestTile.Item1, closestTile.Item3, closestTile.Item4);
                    }

                    else
                    {
                        if (manager.tileType == "P3")
                        {
                            thickRhomb newTile = new thickRhomb();
                            newTile.Init(mouseClickCoor);
                        }

                        else if (manager.tileType == "P2")
                        {
                            dartTile newTile = new dartTile();
                            newTile.Init(mouseClickCoor);
                        }
                    }
                }
            }

            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Vector3 mouseClickCoor = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                    if (manager.tileType == "P3")
                    {
                        thinRhomb newTile = new thinRhomb();
                        newTile.Init(mouseClickCoor);
                    }

                    else if (manager.tileType == "P2")
                    {
                        kiteTile newTile = new kiteTile();
                        newTile.Init(mouseClickCoor);
                    }
                }

                else if (Input.GetMouseButtonDown(1))
                {
                    Vector3 mouseClickCoor = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                    if (manager.tileType == "P3")
                    {
                        thickRhomb newTile = new thickRhomb();
                        newTile.Init(mouseClickCoor);
                    }

                    else if (manager.tileType == "P2")
                    {
                        dartTile newTile = new dartTile();
                        newTile.Init(mouseClickCoor);
                    }
                }
            }
        }