/// <summary> /// Linearly interpolates the Particle's Color between it's Start Color and End Color based on the Particle's Normalized Elapsed Time. /// </summary> /// <param name="cParticle">The Particle to update</param> /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param> protected void UpdateParticleColorUsingLerp(DPSFDefaultBaseParticle cParticle, float fElapsedTimeInSeconds) { // Update the Particle's Color cParticle.Color = DPSFHelper.LerpColor(cParticle.StartColor, cParticle.EndColor, cParticle.NormalizedElapsedTime); }
/// <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; }