示例#1
0
 public IEnumerable <Voxel> GetVoxelsIntersecting(IEnumerable <Vector3> positions)
 {
     foreach (Vector3 vec in positions)
     {
         Voxel vox     = new Voxel();
         bool  success = ChunkData.GetVoxel(vec, ref vox);
         if (success)
         {
             yield return(vox);
         }
     }
 }
示例#2
0
        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;
                    }
                }
            }
        }
示例#3
0
        public void GenerateVein(OreVein vein, ChunkData chunks)
        {
            Voxel   vox           = new Voxel();
            Vector3 curr          = vein.Start;
            Vector3 directionBias = MathFunctions.RandVector3Box(-1, 1, -0.1f, 0.1f, -1, 1);

            for (float t = 0; t < vein.Length; t++)
            {
                if (curr.Y > vein.Type.MaxSpawnHeight ||
                    curr.Y < vein.Type.MinSpawnHeight)
                {
                    continue;
                }
                Vector3 p = new Vector3(curr.X, curr.Y, curr.Z);
                if (!chunks.GetVoxel(p, ref vox))
                {
                    continue;
                }

                if (vox.IsEmpty)
                {
                    continue;
                }

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

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

                vox.Type = vein.Type;
                Vector3 step = directionBias + MathFunctions.RandVector3Box(-1, 1, -1, 1, -1, 1) * 0.25f;
                step.Normalize();
                curr += step;
            }
        }