Ejemplo n.º 1
0
    private int GetAdjacentVoxel(VoxelMap map, IntVector3 key, FaceDirection dir, out IntVector3 adjacentVoxel)
    {
        switch (dir)
        {
        case FaceDirection.TOP: adjacentVoxel = key.Translate(0, 1, 0); break;

        case FaceDirection.BOTTOM: adjacentVoxel = key.Translate(0, -1, 0); break;

        case FaceDirection.RIGHT: adjacentVoxel = key.Translate(1, 0, 0); break;

        case FaceDirection.LEFT: adjacentVoxel = key.Translate(-1, 0, 0); break;

        case FaceDirection.FRONT: adjacentVoxel = key.Translate(0, 0, 1); break;

        case FaceDirection.BACK: adjacentVoxel = key.Translate(0, 0, -1); break;

        default:
            adjacentVoxel = IntVector3.ZERO;
            return(0);
        }

        if (adjacentVoxel.x < 0 ||
            adjacentVoxel.y < 0 ||
            adjacentVoxel.z < 0 ||
            adjacentVoxel.x >= map.Columns ||
            adjacentVoxel.y >= map.Rows ||
            adjacentVoxel.z >= map.Pages)
        {
            return(0);
        }
        else
        {
            return(VoxelMap[adjacentVoxel]);
        }
    }