Exemple #1
0
    /// <summary>
    /// Adds or removes terrain at its surface.
    /// </summary>
    public void ModifyTerrain(Vector3 point, bool add)
    {
        for (float x = -TerrainRadius; x <= TerrainRadius; x = x + WorldGridInfo.kVoxelSize)
        {
            for (float z = -TerrainRadius; z <= TerrainRadius; z = z + WorldGridInfo.kVoxelSize)
            {
                // start at the bottom of world if adding terrain or at the top otherwise
                Vector3 worldPosition = new Vector3(point.x + x, add ? WorldGridInfo.kVoxelSize : _worldApi.GetHeight() - WorldGridInfo.kVoxelSize, point.z + z);

                // traverse the column at XZ position up or down
                while (worldPosition.y > 0 && worldPosition.y < _worldApi.GetHeight())
                {
                    Voxel voxelCopy = _worldApi.TryGetVoxel(in worldPosition, out VectorI3 indices);

                    if (!voxelCopy.Valid)
                    {
                        break;
                    }

                    // if adding and found a not full voxel yet
                    // if removing and found a not empty voxel yet
                    if ((add && voxelCopy.Solid < Voxel.kMaxVolume) || (!add && voxelCopy.Solid > 0))
                    {
                        ModifyVoxel(ref voxelCopy, in indices, add, false);
                        break;
                    }

                    worldPosition.y += add ? WorldGridInfo.kVoxelSize : -WorldGridInfo.kVoxelSize;
                }
            }
        }
    }
Exemple #2
0
    public void Initialize(WorldApi worldApi)
    {
        // orbit around the center of generated world
        Vector3 center = new Vector3(worldApi.GetWidth() * 0.5f, worldApi.GetHeight() * 0.5f, worldApi.GetDepth() * 0.5f);

        transform.parent.Translate(center);

        // zoom out from the world
        _distance += worldApi.GetDepth() * 0.5f;
    }