Ejemplo n.º 1
0
        /// <summary>
        /// Create marching squares
        /// </summary>
        /// <param name="map"></param>
        /// <param name="wallSize"></param>
        /// <param name="is3D"></param>
        static void CreateSquareGrid(IMarchingMap map, MapGenParams parameters)
        {
            if (map.MapData == null)
                return;

            MSNode[] allMeshNodes = new MSNode[map.MapData.NodeCount];
            for (int row = 0; row < map.MapData.RowCount; row++)
                for (int col = 0; col < map.MapData.ColCount; col++)
                {
                    allMeshNodes[row * map.MapData.ColCount + col] = new MSNode(
                        map.MapData.GetNodePos(row, col) - Vector3.forward * parameters.wallSize,
                        map.MapData.GetNode(row, col).m_type == MapNodeType.WALL,
                        map.MapData.NodeSize
                        );
                }

            m_marchSquareGrid = new MarchingSquare[(map.MapData.RowCount - 1) * (map.MapData.ColCount - 1)];
            for (int sq = 0; sq < (map.MapData.RowCount - 1) * (map.MapData.ColCount - 1); sq++)
            {
                int row = sq / (map.MapData.ColCount - 1);
                int col = sq % (map.MapData.ColCount - 1);

                m_marchSquareGrid[sq] = new MarchingSquare(
                    allMeshNodes[(row + 1) * map.MapData.ColCount + col],
                    allMeshNodes[(row + 1) * map.MapData.ColCount + col + 1],
                    allMeshNodes[row * map.MapData.ColCount + col],
                    allMeshNodes[row * map.MapData.ColCount + col + 1]

                    );
            }
        }
Ejemplo n.º 2
0
 public MarchingSquare(MSNode tl, MSNode tr, MSNode bl, MSNode br)
 {
     TL = tl;
     TR = tr;
     BL = bl;
     BR = br;
     CT = tl.right;
     CB = bl.right;
     CL = bl.top;
     CR = br.top;
 }