Ejemplo n.º 1
0
        static int ComputeConfiguration(WallGrid grid, int x, int y)
        {
            byte botLeft  = grid[x, y];
            byte botRight = grid[x + 1, y];
            byte topRight = grid[x + 1, y + 1];
            byte topLeft  = grid[x, y + 1];

            return(MarchingSquares.ComputeConfiguration(botLeft, botRight, topRight, topLeft));
        }
Ejemplo n.º 2
0
        void TriangulateSquare(int x, int y)
        {
            int configuration = ComputeConfiguration(grid, x, y);

            if (configuration != 0)
            {
                int[] points = MarchingSquares.GetPoints(configuration);
                SetVertexIndices(points, x, y);
                AddTriangles(points.Length);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Does the cave produced by this grid contain a floor at these world coordinates?
        /// </summary>
        public bool IsFloor(float x, float z)
        {
            if (x <= 0 || z <= 0 || xMax <= x || zMax <= z)
            {
                return(false);
            }
            x *= scaleReciprocal;
            z *= scaleReciprocal;
            int   gridX       = (int)x;
            int   gridZ       = (int)z;
            float fractionalX = x - gridX;
            float fractionalZ = z - gridZ;

            byte botLeft  = grid[gridX, gridZ];
            byte botRight = grid[gridX + 1, gridZ];
            byte topRight = grid[gridX + 1, gridZ + 1];
            byte topLeft  = grid[gridX, gridZ + 1];

            int configuration = MarchingSquares.ComputeConfiguration(botLeft, botRight, topRight, topLeft);

            return(!MarchingSquares.IntersectsTriangle(new Vector2(fractionalX, fractionalZ), configuration));
        }