Exemple #1
0
 /// <summary>
 /// update grid, if there is change in From or To Vectors
 /// </summary>
 public virtual void UpdateGrid()
 {
     gridPayload = GenerateVerticies(gridOrigin, From, To, CellSize);
     GenerateCells(gridPayload);
     ColliderConfiguration(gridPayload, gridOrigin);
     gridRenderer.UpdateGridRenderer(gridPayload);
 }
Exemple #2
0
        private GridVerticiesPayload gridPayloadMaker()
        {
            GridVerticiesPayload g = new GridVerticiesPayload();

            g.xDimension = xDimension;
            g.yDimension = yDimension;
            g.zDimension = zDimension;

            g.origin = gridOrigin;

            g.CellSize = CellSize;

            g.xStart = xStart;
            g.xEnd   = xEnd;

            g.yStart = yStart;
            g.yEnd   = yEnd;

            g.zStart = zStart;
            g.zEnd   = zEnd;

            g.gridCellsPositions = gridCellPositions;

            return(g);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gridPayload"></param>
        /// <param name="i"></param>
        private void RenderGridTiles(GridVerticiesPayload gridPayload, Interactable i)
        {
            // use a circular render texture, that
            //Ray cameraRay = Camera.main.ScreenPointToRay(new Vector3(Camera.main.pixelWidth / 2, Camera.main.pixelHeight / 2, 0));
            //RaycastHit hit;

            //if (Physics.Raycast(cameraRay, out hit, 100f) & hit.collider.GetComponent<Floor>())
            //{
            //    Vector3 floorPos = hit.collider.GetComponent<Floor>().transform.position;
            //    circle.SetActive(true);

            //    circle.transform.position = new Vector3(hit.point.x, floorPos.y, hit.point.z);

            //    // You need a way to map the grid shaders w/
            //    // relative to the mouse movement

            //}
            //else
            //{
            //    circle.SetActive(false);


            //}

            //for (int x = 0; x < g.xDimension; x++)
            //{
            //    for (int z = 0; z < g.zDimension; z++)
            //    {

            //    }
            //}
        }
Exemple #4
0
 public void ConfigureGrid()
 {
     calculateGridLengths();
     calculateGridDimensions();
     setUpGridVertices();
     setGridLengthsAbsValue();
     generateGridVerticies();
     generateGridCellPositions();
     g = gridPayloadMaker();
 }
Exemple #5
0
        // initialize grid on Start at Beginning of RunTime.
        private void initalizeGrid()
        {
            // for non AR
            //gridOrigin = transform.position;

            gridPayload = GenerateVerticies(gridOrigin, from, to, CellSize);
            gridRenderer.UpdateGridRenderer(gridPayload);
            ColliderConfiguration(gridPayload, gridOrigin);
            //GenerateCells(gridPayload);
            // for AR
        }
Exemple #6
0
        private void ColliderConfiguration(GridVerticiesPayload g, Vector3 colliderOrigin)
        {
            collider = GetComponent <BoxCollider>();

            // take into account that the scale units (i.e. a cube scale of 20 means a collider width of 1 will mean
            // the actual dimensions will be 20.

            Vector3 scale = transform.localScale;

            Debug.Log(scale);

            // collider.size = new Vector3((g.xDimension * CellSize)/scale.x, g.yDimension*CellSize, (g.zDimension * CellSize)/scale.z);
            collider.center = colliderOrigin;
        }
Exemple #7
0
    public void UpdateGridRenderer(GridVerticiesPayload v)
    {
        xStart = v.xStart;
        xEnd   = v.xEnd;

        yStart = v.yStart;
        yEnd   = v.yEnd;

        zStart = v.zStart;
        zEnd   = v.zEnd;

        xDimension = v.xDimension;
        yDimension = v.yDimension;
        zDimension = v.zDimension;
    }
Exemple #8
0
        /// <summary>
        /// Add cells that are within the Camera boundaries.
        /// </summary>
        private void GenerateCells(GridVerticiesPayload g)
        {
            for (int x = 0; x < g.xDimension - 1; x++)
            {
                for (int y = 0; y < g.yDimension - 1; y++)
                {
                    for (int z = 0; y < g.zDimension - 1; z++)
                    {
                        float shiftedX = x - g.origin.x + g.CellSize / 2;
                        float shiftedY = y - g.origin.y + g.CellSize / 2;
                        float shiftedZ = z - g.origin.z + g.CellSize / 2;

                        Vector3 cellPos = new Vector3(shiftedX, shiftedY, shiftedZ);
                        //cells[i] = new Cell(cellPos, g.CellSize);
                    }
                }
            }
        }
Exemple #9
0
        // inspiration https://www.youtube.com/watch?v=QBO1m-AFntQ
        #region Private rendering / cell calculation methods

        /// <summary>
        /// Generate vertices for the vertex array;
        /// </summary>
        /// <param name="gridOrigin"></param>
        private GridVerticiesPayload GenerateVerticies(Vector3 gridOrigin, Vector3 from, Vector3 to, float cellSize)
        {
            GridVerticiesPayload g = new GridVerticiesPayload();

            // check type sensitivity here
            for (int i = 0; i < 3; i++)
            {
                from[i] = Mathf.Clamp(from[i], -Mathf.Infinity, 0);
                to[i]   = Mathf.Clamp(to[i], 0, Mathf.Infinity);
            }

            // private variables -> call this the
            // changeGridLengths();

            int xStartLength = Mathf.FloorToInt(from.x - gridOrigin.x);
            int yStartLength = Mathf.FloorToInt(from.y - gridOrigin.y);
            int zStartLength = Mathf.FloorToInt(from.z - gridOrigin.z);

            int xEndLength = Mathf.FloorToInt(to.x - gridOrigin.x);
            int yEndLength = Mathf.FloorToInt(to.y - gridOrigin.y);
            int zEndLength = Mathf.FloorToInt(to.z - gridOrigin.z);

            g.xDimension = Mathf.Abs(xEndLength - xStartLength);
            g.yDimension = Mathf.Abs(yEndLength - yStartLength);
            g.zDimension = Mathf.Abs(zEndLength - zStartLength);

            //Debug.Log("Grid Origin: " + gridOrigin);
            //Debug.Log(xStartLength + " , " + yStartLength + " , " + zStartLength);
            //Debug.Log(xEndLength + " , " + yEndLength + " , " + zEndLength);
            //Debug.Log(g.xDimension + " , " + g.yDimension + " , " + g.zDimension);

            g.origin   = gridOrigin;
            g.CellSize = cellSize;

            // x axis end
            g.xStart = new Vector3[g.xDimension, g.zDimension];
            g.xEnd   = new Vector3[g.xDimension, g.zDimension];

            // y axis end
            g.yStart = new Vector3[g.yDimension, g.zDimension];
            g.yEnd   = new Vector3[g.yDimension, g.zDimension];

            // z axis end
            g.zStart = new Vector3[g.xDimension, g.yDimension];
            g.zEnd   = new Vector3[g.xDimension, g.yDimension];


            // for math purposes, convert to abs value
            xStartLength = Mathf.Abs(xStartLength);
            yStartLength = Mathf.Abs(yStartLength);
            zStartLength = Mathf.Abs(zStartLength);

            xEndLength = Mathf.Abs(xEndLength);
            yEndLength = Mathf.Abs(yEndLength);
            zEndLength = Mathf.Abs(zEndLength);


            // x lines
            for (int x = 0; x < g.xDimension; x++)
            {
                for (int z = 0; z < g.zDimension; z++)
                {
                    g.xStart[x, z] = new Vector3(g.CellSize * (x - xStartLength + gridOrigin.x), g.CellSize * (-yStartLength + gridOrigin.y), g.CellSize * (z - zStartLength + gridOrigin.z));
                    g.xEnd[x, z]   = new Vector3(g.CellSize * (x - xStartLength + gridOrigin.x), g.CellSize * (yEndLength + gridOrigin.y), g.CellSize * (z - zStartLength + gridOrigin.z));
                }
            }

            // y lines
            for (int y = 0; y < g.yDimension; y++)
            {
                for (int z = 0; z < g.zDimension; z++)
                {
                    g.yStart[y, z] = new Vector3(g.CellSize * (-xStartLength + gridOrigin.x), g.CellSize * (y - yStartLength + gridOrigin.y), g.CellSize * (z - zStartLength + gridOrigin.z));
                    g.yEnd[y, z]   = new Vector3(g.CellSize * (xEndLength + gridOrigin.x), g.CellSize * (y - yStartLength + gridOrigin.y), g.CellSize * (z - zStartLength + gridOrigin.z));
                }
            }

            // z lines
            for (int x = 0; x < g.xDimension; x++)
            {
                for (int y = 0; y < g.yDimension; y++)
                {
                    g.zStart[x, y] = new Vector3(g.CellSize * (x - xStartLength + gridOrigin.x), g.CellSize * (y - yStartLength + gridOrigin.y), g.CellSize * (-zStartLength + gridOrigin.z));
                    g.zEnd[x, y]   = new Vector3(g.CellSize * (x - xStartLength + gridOrigin.x), g.CellSize * (y - yStartLength + gridOrigin.y), g.CellSize * (zEndLength + gridOrigin.z));
                }
            }


            return(g);
        }
Exemple #10
0
        // place this method in the Projector GameObject
        public void shiftGraph(GridVerticiesPayload g, Vector3 cameraShift)
        {
            #region notes
            //  how to shift using the gridVerticiesPayload?

            // what type of problem am I solving // refactoring

            // the problem I'm having is ->
            // I hate individually changing each individual variable because
            // it requires me to remember each variable.


            // I prefer calling methods which manipulate multiple variables at once, rather than
            // try to do it at every step

            // it adds extra cognitive load to the process, by repeating the steps needed t

            // what are the pros and cons of each use case.


            #endregion

            #region steps

            // I am interested in refactoring the gridPayload because
            // I feel that there will be multiple use cases I haven't accounted for
            // that I want to prepare for. // think about single responsibility problem

            // question -> should this be triggered by an event listener?

            // i.e. everytime there is a Time.deltaTime change, send an event to the delegate
            // so that this grid can make that change

            // step 0) -> From the public interface, have a
            // public method that allows for the shifting of the graph
            // i.e. g.shiftGraph(cameraShift);

            // step 1 -> in ShiftGraph, access the existing from and to
            // public variables, shift the opposite direction of movement,
            // and

            // step 2 -> change the start lengths and end lengths,
            // based on the SHIFT of the to and from variables. Internally
            // call g.changeGridLengths() method

            // step 4) recalculate the unitDimensions, using the private method
            // g.changeDimensions()

            // step 5) g.setGridDimensions() // this will parse through all the
            // grid private variables & set up grid dimensions.

            // step 6) g.generateGridVerticies() this will autopopulate the grid dimensions
            // with vertice coordinates

            // step 7) call the gridRenderer to rerender the

            // this means that we need access to the
            // to and from variables

            #endregion
        }