示例#1
0
        public void ReadFrom(Stream stream)
        {
            int numMaterials = stream.ReadInt32();
            Layers = new MyMaterialLayer[numMaterials];
            for (int i = 0; i < numMaterials; ++i)
            {
                Layers[i] = new MyMaterialLayer();
                Layers[i].StartHeight = stream.ReadFloat();
                Layers[i].EndHeight = stream.ReadFloat();
                Layers[i].StartAngle = stream.ReadFloat();
                Layers[i].EndAngle = stream.ReadFloat();
                Layers[i].HeightStartDeviation = stream.ReadFloat();
                Layers[i].AngleStartDeviation = stream.ReadFloat();
                Layers[i].HeightEndDeviation = stream.ReadFloat();
                Layers[i].AngleEndDeviation = stream.ReadFloat();
                Layers[i].MaterialDefinition = MyDefinitionManager.Static.GetVoxelMaterialDefinition(stream.ReadString());
            }

            int numOreProbabilities = stream.ReadInt32();
            OreProbabilities = new MyOreProbability[numOreProbabilities];
            for (int i = 0; i < numOreProbabilities; ++i)
            {
                OreProbabilities[i] = new MyOreProbability();
                OreProbabilities[i].CummulativeProbability = stream.ReadFloat();
                OreProbabilities[i].OreName = stream.ReadString();
            }

            OreStartDepth = stream.ReadFloat();
            OreEndDepth = stream.ReadFloat();
        }
示例#2
0
        public void ReadFrom(Stream stream)
        {         
            int numOreProbabilities = stream.ReadInt32();
            OreProbabilities = new MyOreProbability[numOreProbabilities];
            for (int i = 0; i < numOreProbabilities; ++i)
            {
                OreProbabilities[i] = new MyOreProbability();
                OreProbabilities[i].CummulativeProbability = stream.ReadFloat();
                OreProbabilities[i].OreName = stream.ReadString();
            }

            OreStartDepth = stream.ReadFloat();
            OreEndDepth = stream.ReadFloat();
        }
        public MyCompositeOrePlanetDeposit(MyCsgShapeBase baseShape, int seed, float minDepth, float maxDepth, MyOreProbability[] oreProbabilties) :
            base(baseShape, null)
        {

            m_minDepth = minDepth;
            double outherSphereVolume = (4.0 * MathHelper.Pi * Math.Pow(minDepth, 3.0f)) / 3.0;
            double innerSphereVolume = (4.0 * MathHelper.Pi * Math.Pow(maxDepth, 3.0f)) / 3.0;

            double depositVolume = (4.0 * MathHelper.Pi * Math.Pow(DEPOSIT_MAX_SIZE, 3.0f)) / 3.0;
            double volume = outherSphereVolume - innerSphereVolume;

            m_numDeposits = (int)Math.Floor((volume * 0.4f) / depositVolume);

            int numSectors = (int)(minDepth / DEPOSIT_MAX_SIZE);

            MyRandom random = MyRandom.Instance;
            FillMaterialCollections();
            Vector3D offset = -new Vector3D(DEPOSIT_MAX_SIZE/2.0);
            using (var stateToken = random.PushSeed(seed))
            {
                for (int i = 0; i < m_numDeposits; ++i)
                {
                    Vector3D direction = MyProceduralWorldGenerator.GetRandomDirection(random);
                    float distanceFromCenter = random.NextFloat(maxDepth,minDepth);
                    Vector3D position = direction * distanceFromCenter;

                    Vector3I cellPos = Vector3I.Ceiling((Shape.Center() + position)/ DEPOSIT_MAX_SIZE);

                    MyCompositeShapeOreDeposit deposit;
                    if (m_deposits.TryGetValue(cellPos, out deposit) == false)
                    {
                        var oreDefinition = GetOre(random.NextFloat(0, 1), oreProbabilties);
                        var materialDefinition = m_materialsByOreType[oreDefinition.OreName][random.Next() % m_materialsByOreType[oreDefinition.OreName].Count];
                        deposit = new MyCompositeShapeOreDeposit(new MyCsgSimpleSphere(cellPos * DEPOSIT_MAX_SIZE + offset, random.NextFloat(64, DEPOSIT_MAX_SIZE / 2.0f)), materialDefinition);
                        m_deposits[cellPos] = deposit;
                    }
                }
            }

            m_materialsByOreType.Clear();
        }
        private MyOreProbability GetOre(float probability, MyOreProbability[] probalities)
        {
            foreach (var oreProbability in probalities)
            {
                if (oreProbability.CummulativeProbability >= probability)
                {
                    return oreProbability;
                }
            }

            return null;
        }
 private static void BuildOreProbabilities(MyPlanetDefinition planetDefinition)
 {
     m_oreCummulativeProbability = 0.0f;
     if (planetDefinition.MetalsOreProbability != null)
     {
         foreach (var oreProbability in planetDefinition.MetalsOreProbability)
         {
             MyOreProbability probability = new MyOreProbability();
             probability.Probability = MyRandom.Instance.NextFloat(oreProbability.Min, oreProbability.Max);
             m_oreCummulativeProbability += probability.Probability;
             probability.CummulativeProbability = m_oreCummulativeProbability;
             probability.OreName = oreProbability.OreName;
             m_oreProbalities.Add(probability);
         }
     }
 }