예제 #1
0
    //Runs once at start of program
    void Start()
    {
        colorPicked = false;
        runSetup    = true;
        tr          = new TetraRenderer(this.gameObject);
        sw          = new SimpleWalkController(this.gameObject);

        vertexList.Add(new int[5] {
            0, 1, 2, 3, 0
        });
        //vertexList.Add(new int[4] { 2, 1, 0, 4 });
        //vertexList.Add(new int[4] { 1, 2, 3, 5 });
        newTetraVtx[0] = 2;
        newTetraVtx[1] = 1;
        newTetraVtx[2] = 0;
        newTetraVtx[3] = 0;
    }
예제 #2
0
    //Physics update, runs repeatedly
    void FixedUpdate()
    {
        //Sets center of mass
        centerMass = TetraUtil.averageVertices(vertices, this.transform);

        if (tr == null)
        {
            Start();
        }

        //Tells tetraRenderer to pick color
        if (!colorPicked)
        {
            colorPicked = true;
            tr.pickRandomColor();
        }

        //Runs setup of tetrahedrons
        if (runSetup)
        {
            runSetup = false;
            setupTetras();
        }

        //Sets side lengths in tetrahedrons
        int p = 0;

        bool          quickSetReset = false;
        HashSet <int> alreadySetIDs = new HashSet <int>();

        foreach (Tetrahedron tetrahedron in tetrahedrons)
        {
            if (tetrahedron.type != 2)
            {
                foreach (Side side in tetrahedron.sides)
                {
                    if (sideSetList.Count < p + 1)
                    {
                        sideSetList.Add(2.0f);
                    }

                    if (disphenoidMode)
                    {
                        foreach (Side tempSide in oppositeSide(tetrahedron, side))
                        {
                            if (!alreadySetIDs.Contains(tempSide.ID))
                            {
                                sideSetList[tempSide.ID] = sideSetList[side.ID];
                            }
                        }

                        alreadySetIDs.Add(side.ID);
                    }

                    if (quickSideSet)
                    {
                        quickSetReset = true;
                        side.length   = sideSetList[p];
                    }
                    else
                    {
                        side.length = Mathf.SmoothStep(side.length, sideSetList[p], 0.10f);
                    }

                    side.ID = p;

                    if (runOppositeSide && p == sideVal)
                    {
                        runOppositeSide = false;
                        Debug.Log("----------");
                        int oppositeID = oppositeSide(tetrahedron, side)[0].ID;
                        Debug.Log("Opposite side is: " + oppositeID);
                    }

                    p++;
                }
            }
        }

        if (quickSetReset)
        {
            quickSideSet = false;
        }

        //Runs loop of tetrahedrons
        foreach (Tetrahedron tetra in tetrahedrons)
        {
            tetra.loop();
        }

        //Catches if tetraRenderer does not exist
        if (tr == null)
        {
            tr = new TetraRenderer(this.gameObject);
        }

        //Loops tetraRenderer
        tr.loop();

        if (tetrahedrons.Count == 1 && walkControl)
        {
            sw.loop();
        }
    }