/// <summary> /// Example of how to create a Particle Initialization Function /// </summary> /// <param name="cParticle">The Particle to be Initialized</param> public void InitializeParticleProperties(DefaultSprite3DBillboardParticle cParticle) { //----------------------------------------------------------- // TODO: Initialize all of the Particle's properties here. // If you plan on simply using the default InitializeParticleUsingInitialProperties // Particle Initialization Function (see the LoadParticleSystem() function above), // then you may delete this function all together. //----------------------------------------------------------- // Set the Particle's Lifetime (how long it should exist for) cParticle.Lifetime = 0.1f; // Set the Particle's initial Position to be wherever the Emitter is cParticle.Position = Emitter.PositionData.Position; // Set the Particle's Velocity Vector3 sVelocityMin = new Vector3(-1.8f, -1.8f, -3f); Vector3 sVelocityMax = new Vector3(1.8f, 1.8f, -1.8f); cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); cParticle.Velocity += velocity; // Give the Particle a random Size // Since we have Size Lerp enabled we must also set the Start and End Size cParticle.Width = cParticle.StartWidth = cParticle.EndWidth = cParticle.EndHeight = cParticle.Height = cParticle.StartHeight = 2f * RandomNumber.NextFloat(); // Give the Particle a random Color // Since we have Color Lerp enabled we must also set the Start and End Color cParticle.Color = cParticle.StartColor = Color.Yellow; cParticle.EndColor = Color.Red; }
public void NextFloatTest() { float min = 0; float max = 100; float testFloat = RandomNumber.NextFloat(min, max); Assert.IsTrue(testFloat >= min && testFloat < max); }
protected override void OnNextBeat(int section, int bar, int beat, double dspTime, double beatTime) { if (bar == 0 && beat == 0) { sectionType = SongStructure.GetSection(section); } if (sectionType == SectionType.OUTRO && drumType != DrumType.CLAP) { return; } int augmentedBeat = 2 * (bar * 4 + beat); for (int i = 0; i < 2; ++i) { float volume = 1.0f; float p = RandomNumber.NextFloat(0.0f, 1.0f); bool play = false; switch (drumType) { case DrumType.KICK: play = p < 0.0025f || (p < 0.97f && augmentedBeat % 8 == 0); break; case DrumType.SNARE: play = p < 0.0025f || augmentedBeat % 8 == 4; if (augmentedBeat % 8 != 4) { volume = RandomNumber.NextFloat(0.75f, 1.0f); } break; case DrumType.CLAP: play = p < 0.0025f || augmentedBeat % 8 == 4; break; case DrumType.HH_CLOSED: play = p < 0.001f || augmentedBeat % 4 == 2 || (sectionType == SectionType.CHORUS && augmentedBeat % 2 == 0 && p < 0.9f); if (augmentedBeat % 4 != 2) { volume = RandomNumber.NextFloat(0.75f, 1.0f); } break; case DrumType.HH_OPEN: play = augmentedBeat % 32 == 0; break; } if (play) { double playTime = dspTime + i * 0.5 * beatTime; instrument.PlayNote(playTime, 0, volume); } ++augmentedBeat; } }
protected override void OnNextBeat(int section, int bar, int beat, double dspTime, double beatTime) { SectionType sectionType = SongStructure.GetSection(section); if (beat == beatOffset || (sectionType == SectionType.CHORUS && beat == ((beatOffset + 2) % 4))) { lastNote += RandomNumber.NextInt(-Scale.scaleLength / 4, Scale.scaleLength / 2); lastNote = System.Math.Max(-Scale.scaleLength / 4, System.Math.Min(Scale.scaleLength, lastNote)); Dictionary <int, int> sectionLines = null; if (lines.TryGetValue(sectionType, out sectionLines)) { int key = bar * numBeats + beat; int noteIndex = 0; if (!sectionLines.TryGetValue(key, out noteIndex)) { noteIndex = HarmonicProgression.GetHarmonic(section, bar) + lastNote; sectionLines.Add(key, noteIndex); } instrument.PlayNote(dspTime, noteIndex, RandomNumber.NextFloat(0.9f, 1.0f)); } } }
//=========================================================== // Initialization Function //=========================================================== /// <summary> /// Function to Initialize a Default Particle with default settings /// </summary> /// <param name="Particle">The Particle to be Initialized</param> public override void InitializeParticleUsingInitialProperties(DPSFParticle Particle) { // Cast the Particle to the type it really is DefaultQuadParticle cParticle = (DefaultQuadParticle)Particle; // Initialize the Particle according to the values specified in the Initial Settings base.InitializeParticleUsingInitialProperties(cParticle, mcInitialProperties); // If the Rotation should be interpolated between the Min and Max Rotation if (mcInitialProperties.InterpolateBetweenMinAndMaxRotation) { // Calculate the Particle's initial Rotational values Vector3 sRotation = Vector3.Lerp(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax, RandomNumber.NextFloat()); cParticle.Orientation = Quaternion.CreateFromYawPitchRoll(sRotation.Y, sRotation.X, sRotation.Z); } // Else the Rotation XYZ values should each be calculated individually else { // Calculate the Particle's initial Rotational values Vector3 sRotation = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax); cParticle.Orientation = Quaternion.CreateFromYawPitchRoll(sRotation.Y, sRotation.X, sRotation.Z); } // If the Rotational Velocity should be interpolated between the Min and Max Rotational Velocities if (mcInitialProperties.InterpolateBetweenMinAndMaxRotationalVelocity) { cParticle.RotationalVelocity = Vector3.Lerp(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax, RandomNumber.NextFloat()); } // Else the Rotational Velocity XYZ values should each be calculated individually else { cParticle.RotationalVelocity = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax); } // If the Rotational Acceleration should be interpolated between the Min and Max Rotational Acceleration if (mcInitialProperties.InterpolateBetweenMinAndMaxRotationalAcceleration) { cParticle.RotationalAcceleration = Vector3.Lerp(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax, RandomNumber.NextFloat()); } // Else the Rotational Acceleration XYZ values should each be calculated individually else { cParticle.RotationalAcceleration = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax); } // Calculate the Particle's Width and Height values cParticle.StartWidth = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartWidthMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartWidthMax); cParticle.EndWidth = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndWidthMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndWidthMax); cParticle.StartHeight = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartHeightMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartHeightMax); cParticle.EndHeight = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndHeightMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndHeightMax); cParticle.Width = cParticle.StartWidth; cParticle.Height = cParticle.StartHeight; }
public float RollDuration() { return(RandomNumber.NextFloat(MinDuration, MaxDuration)); }
public float RollHeight() { return(RandomNumber.NextFloat(MinHeight, MaxHeight)); }
public float RollWidth() { return(RandomNumber.NextFloat(MinWidth, MaxWidth)); }
public float RollInterval() { return(RandomNumber.NextFloat(MinInterval, MaxInterval)); }
/// <summary> /// Function to Initialize a Default Particle with the Initial Settings /// </summary> /// <param name="Particle">The Particle to be Initialized</param> /// <param name="cInitialProperties">The Initial Settings to use to Initialize the Particle</param> public void InitializeParticleUsingInitialProperties(DPSFParticle Particle, CInitialProperties cInitialProperties) { // Cast the Particle to the type it really is DPSFDefaultBaseParticle cParticle = (DPSFDefaultBaseParticle)Particle; // Initialize the Particle according to the values specified in the Initial Settings cParticle.Lifetime = DPSFHelper.RandomNumberBetween(cInitialProperties.LifetimeMin, cInitialProperties.LifetimeMax); // If the Position should be interpolated between the Min and Max Positions if (cInitialProperties.InterpolateBetweenMinAndMaxPosition) { cParticle.Position = Vector3.Lerp(cInitialProperties.PositionMin, cInitialProperties.PositionMax, RandomNumber.NextFloat()); } // Else the Position XYZ values should each be calculated individually else { cParticle.Position = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.PositionMin, cInitialProperties.PositionMax); } // If the Particle's Velocity should be affected by the Emitters Orientation if (cInitialProperties.VelocityIsAffectedByEmittersOrientation) { // Rotate the Particle around the Emitter according to the Emitters orientation cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation); } // If the Particle should be affected by the Emitters Position if (cInitialProperties.PositionIsAffectedByEmittersPosition) { // Add the Emitter's Position to the Particle's Position cParticle.Position += Emitter.PositionData.Position; } // If the Velocity should be interpolated between the Min and Max Velocity if (cInitialProperties.InterpolateBetweenMinAndMaxVelocity) { cParticle.Velocity = Vector3.Lerp(cInitialProperties.VelocityMin, cInitialProperties.VelocityMax, RandomNumber.NextFloat()); } // Else the Velocity XYZ values should each be calculated individually else { cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.VelocityMin, cInitialProperties.VelocityMax); } // Have the Emitters Rotation affect the Particle's starting Velocity cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); // If the Acceleration should be interpolated between the Min and Max Acceleration if (cInitialProperties.InterpolateBetweenMinAndMaxAcceleration) { cParticle.Acceleration = Vector3.Lerp(cInitialProperties.AccelerationMin, cInitialProperties.AccelerationMax, RandomNumber.NextFloat()); } // Else the Acceleration XYZ values should each be calculated individually else { cParticle.Acceleration = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.AccelerationMin, cInitialProperties.AccelerationMax); } // If the External Force should be interpolated between the Min and Max External Force if (cInitialProperties.InterpolateBetweenMinAndMaxExternalForce) { cParticle.ExternalForce = Vector3.Lerp(cInitialProperties.ExternalForceMin, cInitialProperties.ExternalForceMax, RandomNumber.NextFloat()); } // Else the External Force XYZ values should each be calculated individually else { cParticle.ExternalForce = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.ExternalForceMin, cInitialProperties.ExternalForceMax); } // Calculate the amount of Friction to use cParticle.Friction = DPSFHelper.RandomNumberBetween(cInitialProperties.FrictionMin, cInitialProperties.FrictionMax); // If the new Color values should be somewhere between the interpolation of the Min and Max Colors if (cInitialProperties.InterpolateBetweenMinAndMaxColors) { cParticle.StartColor = DPSFHelper.LerpColor(cInitialProperties.StartColorMin, cInitialProperties.StartColorMax, RandomNumber.NextFloat()); cParticle.EndColor = DPSFHelper.LerpColor(cInitialProperties.EndColorMin, cInitialProperties.EndColorMax, RandomNumber.NextFloat()); } // Else the RGBA Color values should each be randomly calculated individually else { cParticle.StartColor = DPSFHelper.LerpColor(cInitialProperties.StartColorMin, cInitialProperties.StartColorMax, RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat()); cParticle.EndColor = DPSFHelper.LerpColor(cInitialProperties.EndColorMin, cInitialProperties.EndColorMax, RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat()); } cParticle.Color = cParticle.StartColor; }
public void InitializeParticleSnow(DefaultTexturedQuadParticle cParticle) { // Position the Snow within 500 units of the emitter Vector3 sPosition = Emitter.PositionData.Position; sPosition.Y = 200; sPosition.X += RandomNumber.Next(-500, 500); sPosition.Z += RandomNumber.Next(-500, 500); cParticle.Lifetime = 0.0f; cParticle.Position = sPosition; cParticle.Size = RandomNumber.Next(2, 5); cParticle.Color = DPSFHelper.LerpColor(new Color(255, 255, 255, 50), new Color(255, 255, 255, 255), RandomNumber.NextFloat()); cParticle.Orientation = Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation); cParticle.Velocity = new Vector3(RandomNumber.Next(-10, 3), RandomNumber.Next(-15, -5), RandomNumber.Next(-10, 10)); cParticle.Acceleration = Vector3.Zero; cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); }
public void NextFloatTest1() { float testFloat = RandomNumber.NextFloat(); Assert.IsTrue(testFloat >= 0 && testFloat < 1); }