/// <summary> /// Update number of simulated marbles, 'Marbles' is requested to be equal to 'marbles'. /// </summary> void UpdateMarbles() { if (marbles < Marbles) { // Truncate the arrays. int remove = Marbles - marbles; MyMarbles.RemoveRange(marbles, remove); return; } // Extend the arrays. for (int i = Marbles; i < marbles; i++) { var radius = rnd.RandomFloat(0.4f, 1.0f); var color = Color.FromArgb(rnd.RandomInteger(0, 100), rnd.RandomInteger(0, 255), rnd.RandomInteger(0, 255)); var position = new Vector3(rnd.RandomFloat(-10.0f, 10.0f), rnd.RandomFloat(-10.0f, 10.0f), rnd.RandomFloat(-10.0f, 10.0f)); var velocity = Speed * new Vector3(rnd.RandomFloat(-2.0f, 2.0f), rnd.RandomFloat(-2.0f, 2.0f), rnd.RandomFloat(-2.0f, 2.0f)); var marble = new SphereObject(radius, color, position, velocity) { bouncyness = initBouncy, mass = initMass }; marble.Create(); MyMarbles.Add(marble); } }
private void SpawnMeteor() { var radius = rnd.RandomFloat(0.9f, 1.0f) * meteorSizeMulti; var xRange = 10 - radius; var zRange = 10 - radius; var yRange = 10 - radius; var color = Color.FromArgb(rnd.RandomInteger(200, 255), rnd.RandomInteger(0, 0), rnd.RandomInteger(0, 0)); var xLocationStart = rnd.RandomFloat(-20.0f, 20.0f); var zLocationStart = rnd.RandomFloat(-20.0f, 20.0f); var yLocationStart = rnd.RandomFloat(30.0f, 60.0f); var position = new Vector3(xLocationStart, yLocationStart, zLocationStart); var target = new Vector3(rnd.RandomFloat(-xRange, xRange), -yRange, rnd.RandomFloat(-zRange, zRange)); var velocity = (target - position) * 3;//Speed/100 * new Vector3(rnd.RandomFloat(-2.0f, -2.0f), rnd.RandomFloat(-2.0f, -2.0f), rnd.RandomFloat(-2.0f, -2.0f)); var marble = new SphereObject(radius, color, position, velocity) { mass = initMeteorMass, bouncyness = initMeteorBouncy }; marble.Type = SphereCurrentType.MeteorMarbleAtmosphere; marble.Create(); MyMarbles.Add(marble); }