public void GenerateCluster(OreCluster cluster, ChunkData chunks)
        {
            Voxel vox = new Voxel();

            for (float x = -cluster.Size.X * 0.5f; x < cluster.Size.X * 0.5f; x += 1.0f)
            {
                for (float y = -cluster.Size.Y * 0.5f; y < cluster.Size.Y * 0.5f; y += 1.0f)
                {
                    for (float z = -cluster.Size.Z * 0.5f; z < cluster.Size.Z * 0.5f; z += 1.0f)
                    {
                        float radius = (float)(Math.Pow(x / cluster.Size.X, 2.0f) + Math.Pow(y / cluster.Size.Y, 2.0f) +
                                               Math.Pow(z / cluster.Size.Z, 2.0f));

                        if (radius > 1.0f + MathFunctions.Rand(0.0f, 0.25f))
                        {
                            continue;
                        }
                        Vector3 locPosition = new Vector3(x, y, z);

                        Vector3 globalPosition = Vector3.Transform(locPosition, cluster.Transform);

                        if (globalPosition.Y > cluster.Type.MaxSpawnHeight ||
                            globalPosition.Y < cluster.Type.MinSpawnHeight)
                        {
                            continue;
                        }

                        if (!chunks.GetVoxel(globalPosition, ref vox))
                        {
                            continue;
                        }

                        if (vox.IsEmpty)
                        {
                            continue;
                        }

                        if (!cluster.Type.SpawnInSoil && vox.Type.IsSoil)
                        {
                            continue;
                        }

                        if (!MathFunctions.RandEvent(cluster.Type.SpawnProbability))
                        {
                            continue;
                        }

                        vox.Type = cluster.Type;
                    }
                }
            }
        }
        public void GenerateCluster(OreCluster cluster, ChunkData chunks)
        {
            for (float x = -cluster.Size.X * 0.5f; x < cluster.Size.X * 0.5f; x += 1.0f)
            {
                for (float y = -cluster.Size.Y * 0.5f; y < cluster.Size.Y * 0.5f; y += 1.0f)
                {
                    for (float z = -cluster.Size.Z * 0.5f; z < cluster.Size.Z * 0.5f; z += 1.0f)
                    {
                        float radius = (float)(Math.Pow(x / cluster.Size.X, 2.0f) + Math.Pow(y / cluster.Size.Y, 2.0f) +
                                               Math.Pow(z / cluster.Size.Z, 2.0f));

                        if (radius > 1.0f + MathFunctions.Rand(0.0f, 0.25f))
                        {
                            continue;
                        }
                        Vector3 locPosition = new Vector3(x, y, z);

                        Vector3 globalPosition = Vector3.Transform(locPosition, cluster.Transform);

                        if (globalPosition.Y > cluster.Type.MaxSpawnHeight ||
                            globalPosition.Y < cluster.Type.MinSpawnHeight ||
                            globalPosition.Y <= 1)
                        {
                            continue;
                        }

                        var vox = new VoxelHandle(chunks,
                                                  GlobalVoxelCoordinate.FromVector3(globalPosition));

                        if (!vox.IsValid || vox.IsEmpty)
                        {
                            continue;
                        }

                        if (!cluster.Type.SpawnOnSurface && (vox.Type.IsSurface || vox.Type.IsSoil))
                        {
                            continue;
                        }

                        if (!MathFunctions.RandEvent(cluster.Type.SpawnProbability))
                        {
                            continue;
                        }

                        vox.RawSetType(cluster.Type);
                    }
                }
            }
        }
Exemple #3
0
        public void GenerateOres()
        {
            foreach (VoxelType type in VoxelLibrary.GetTypes())
            {
                if (type.SpawnClusters || type.SpawnVeins)
                {
                    int numEvents = (int)MathFunctions.Rand(75*(1.0f - type.Rarity), 100*(1.0f - type.Rarity));
                    for (int i = 0; i < numEvents; i++)
                    {
                        BoundingBox clusterBounds = new BoundingBox
                        {
                            Max = new Vector3(Bounds.Max.X, type.MaxSpawnHeight, Bounds.Max.Z),
                            Min = new Vector3(Bounds.Min.X, type.MinSpawnHeight, Bounds.Min.Z)
                        };

                        if (type.SpawnClusters)
                        {

                            OreCluster cluster = new OreCluster()
                            {
                                Size =
                                    new Vector3(MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize),
                                        MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize),
                                        MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize)),
                                Transform = MathFunctions.RandomTransform(clusterBounds),
                                Type = type
                            };
                            ChunkGen.GenerateCluster(cluster, ChunkData);
                        }

                        if (type.SpawnVeins)
                        {
                            OreVein vein = new OreVein()
                            {
                                Length = MathFunctions.Rand(type.VeinLength*0.75f, type.VeinLength*1.25f),
                                Start = MathFunctions.RandVector3Box(clusterBounds),
                                Type = type
                            };
                            ChunkGen.GenerateVein(vein, ChunkData);
                        }
                    }
                }
            }
        }