//=========================================================== // Particle System Update Functions //=========================================================== //=========================================================== // Other Particle System Functions //=========================================================== private void MakeButterflyFaceProperDirectionAndAdjustAnimationSpeed(DefaultAnimatedTexturedQuadParticle cParticle) { // Calculate the new Direction the Butterfly should face Vector3 sFacingDirection = Vector3.Cross(cParticle.Velocity, Vector3.Up); cParticle.Orientation = Orientation3D.GetQuaternionWithOrientation(sFacingDirection, Vector3.Up); // Make the Butterfly animation go faster based on how fast it is moving upwards float fNormalizedYVelocity = (cParticle.Velocity.Y + miButterflyMaxSpeed) / (miButterflyMaxSpeed * 2); float fNewAnimationTime = MathHelper.Lerp(mfMaxTimeBetweenAnimationImages, mfMinTimeBetweenAnimationImages, fNormalizedYVelocity); cParticle.Animation.CurrentAnimationsPictureRotationTime = fNewAnimationTime; }
//=========================================================== // Particle Update Functions //=========================================================== protected void KeepParticleInBox(DefaultAnimatedTexturedQuadParticle cParticle, float fElapsedTimeInSeconds) { bool bDirectionChanged = false; // If the Particle is heading outside of the box if ((cParticle.Position.X > msBoxMax.X && cParticle.Velocity.X > 0) || (cParticle.Position.X < msBoxMin.X && cParticle.Velocity.X < 0)) { // Reverse it's velocity to keep it inside the box cParticle.Velocity.X *= -1; bDirectionChanged = true; } // If the Particle is heading outside of the box if ((cParticle.Position.Y > msBoxMax.Y && cParticle.Velocity.Y > 0) || (cParticle.Position.Y < msBoxMin.Y && cParticle.Velocity.Y < 0)) { // Reverse it's velocity to keep it inside the box cParticle.Velocity.Y *= -1; bDirectionChanged = true; } // If the Particle is heading outside of the box if ((cParticle.Position.Z > msBoxMax.Z && cParticle.Velocity.Z > 0) || (cParticle.Position.Z < msBoxMin.Z && cParticle.Velocity.Z < 0)) { // Reverse it's velocity to keep it inside the box cParticle.Velocity.Z *= -1; bDirectionChanged = true; } // If the Direction was changed if (bDirectionChanged) { // Calculate the new Direction the Butterfly should face MakeButterflyFaceProperDirectionAndAdjustAnimationSpeed(cParticle); } }
protected void ChangeDirectionRandomly(DefaultAnimatedTexturedQuadParticle cParticle, float fElapsedTimeInSeconds) { // If we should pick a new Direction (happens randomly) (-1 is specified when initializing new particles) float fClamped = MathHelper.Clamp(fElapsedTimeInSeconds, -1f, 0.01f); if (RandomNumber.NextFloat() < fClamped || fElapsedTimeInSeconds < 0) { // Calculate a new Velocity direction cParticle.Velocity = new Vector3(RandomNumber.Next(-miButterflyMaxSpeed, miButterflyMaxSpeed), RandomNumber.Next(-miButterflyMaxSpeed, miButterflyMaxSpeed), RandomNumber.Next(-miButterflyMaxSpeed, miButterflyMaxSpeed)); // Calculate the new Direction the Butterfly should face MakeButterflyFaceProperDirectionAndAdjustAnimationSpeed(cParticle); } }
public void InitializeParticleAnimated(DefaultAnimatedTexturedQuadParticle cParticle) { InitializeParticleUsingInitialProperties(cParticle); cParticle.Animation.CopyFrom(mcAnimation); ChangeDirectionRandomly(cParticle, -1); }