Ejemplo n.º 1
0
        public static DataStructures.Point getCaseIndex(Grid grid, Vector2 targ)
        {
            Vector2 min = grid.plane.min;
            Vector2 max = grid.plane.max;

            int   current_case_x = (int)Mathf.Floor(Mathf.Abs(max.x - targ.x) / grid.tile_size.x);
            int   current_case_y = (int)Mathf.Floor(Mathf.Abs(max.y - targ.y) / grid.tile_size.y);
            Plane p = new Plane(0f, 0f, grid.plane.lenght.x, grid.plane.lenght.y);



            int retour_x = current_case_x;
            int retour_y = current_case_y;

            if (retour_x == grid.nb_tiles.x)
            {
                retour_x = (int)grid.nb_tiles.x - 1;
            }
            if (retour_y == grid.nb_tiles.y)
            {
                retour_y = (int)grid.nb_tiles.y - 1;
            }
            retour_x = Math.Abs(((int)grid.nb_tiles.x - 1) - retour_x);
            retour_y = Math.Abs(((int)grid.nb_tiles.y - 1) - retour_y);
            return(new DataStructures.Point(retour_x, retour_y));
        }
Ejemplo n.º 2
0
        public static Vector3 GetPosInWorld(Grid grid, Point index, float z = 0f)
        {
            Vector2 pos2D = GetCaseInWorld(grid, index);
            Vector3 pos3D = new Vector3(pos2D.x, pos2D.y, z);

            return(pos2D);
        }
Ejemplo n.º 3
0
        public static Node[,] GenerateGraph(Grid grid, Dictionary <Point, int> obstacles)
        {
            int graphsize_x = (int)grid.nb_tiles.x;
            int graphsize_y = (int)grid.nb_tiles.y;

            Node[,] graph = new Node[graphsize_x, graphsize_y];
            for (int x = 0; x < graphsize_x; x++)
            {
                for (int y = 0; y < graphsize_y; y++)
                {
                    int value = 1;
                    if (obstacles.TryGetValue(new Point((int)x, (int)y), out value))
                    {
                        graph[x, y] = new Node(x, y, value);
                    }
                    else
                    {
                        graph[x, y] = new Node(x, y);
                    }
                }
            }
            for (int x = 0; x < graphsize_x; x++)
            {
                for (int y = 0; y < graphsize_y; y++)
                {
                    if (x > 0)
                    {
                        graph[x, y].neighbours.Add(graph[x - 1, y]);
                    }
                    if (x < graphsize_x - 1)
                    {
                        graph[x, y].neighbours.Add(graph[x + 1, y]);
                    }
                    if (y > 0)
                    {
                        graph[x, y].neighbours.Add(graph[x, y - 1]);
                    }
                    if (y < graphsize_y - 1)
                    {
                        graph[x, y].neighbours.Add(graph[x, y + 1]);
                    }
                }
            }
            return(graph);
        }
Ejemplo n.º 4
0
        public static Vector2 GetCaseInWorld(Grid grid, Point p_index)
        {
            Vector2 index = new Vector2(p_index.x, p_index.y);

            if (index.x < grid.nb_tiles.x && index.y < grid.nb_tiles.y)
            {
                Vector2 min = grid.plane.min;
                Vector2 max = grid.plane.max;

                Vector2 pos_cell_center = new Vector2((grid.plane.min.x + (index.x * grid.tile_size.x)) + grid.tile_size.x / 2.0f,
                                                      (grid.plane.min.y + (index.y * grid.tile_size.y)) + grid.tile_size.y / 2.0f);


                return(pos_cell_center);
            }
            else
            {
                throw new Exception("Index Greather or Egal than nb_tiles" + p_index + " " + grid.nb_tiles);
            }
        }
Ejemplo n.º 5
0
 public static DataStructures.Point getCaseIndex(Grid grid, Vector3 targ)
 {
     return(getCaseIndex(grid, new Vector2(targ.x, targ.y)));
 }