public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.3f, 0.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.Black; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(1, 50); particle.ExternalForce = new Vector3(0, 80, 0); // We want the smoke to rise particle.Size = particle.StartSize = 1; // Have the particles start small and grow particle.EndSize = ExplosionParticleSize; // Give the particle a random initial orientation and random rotation velocity (only need to Roll the particle since it will always face the camera) particle.Rotation = RandomNumber.Between(0, MathHelper.TwoPi); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: textureCoordinates = _flameSmoke1TextureCoordinates; break; case 1: textureCoordinates = _flameSmoke2TextureCoordinates; break; case 2: textureCoordinates = _flameSmoke3TextureCoordinates; break; case 3: textureCoordinates = _flameSmoke4TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = 0.2f; particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-15, 15), RandomNumber.Next(-15, 15), RandomNumber.Next(-15, 15)); particle.Size = particle.StartSize = 1; particle.EndSize = ExplosionParticleSize; // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: textureCoordinates = _flash1TextureCoordinates; break; case 1: textureCoordinates = _flash2TextureCoordinates; break; case 2: textureCoordinates = _flash3TextureCoordinates; break; case 3: textureCoordinates = _flash4TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.5f, 1.0f); particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(30, 50); particle.ExternalForce = new Vector3(0, 20, 0); particle.Size = ExplosionParticleSize; particle.SetTextureCoordinates(_roundSparkTextureCoordinates); }
protected void UpdateParticleFireSmokeSize(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have particle grow to its full size within the first 20% of its lifetime if (particle.NormalizedElapsedTime < 0.2f) { particle.Size = MathHelper.Lerp(particle.StartWidth, particle.EndWidth, particle.NormalizedElapsedTime * 5); } else { particle.Size = particle.EndWidth; } }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFireSmokeColor(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have particle be the specified color for the first part of its lifetime float firstPartOfLifetime = 0.2f; if (particle.NormalizedElapsedTime < firstPartOfLifetime) { particle.Color = particle.StartColor; } // Then start fading it to black to look like smoke else { float lerpAmount = (particle.NormalizedElapsedTime - firstPartOfLifetime) * (1.0f / (1.0f - firstPartOfLifetime)); particle.Color = DPSFHelper.LerpColor(particle.StartColor, particle.EndColor, lerpAmount); } }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFlashSize(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have the particle reach its full size when it reaches half its lifetime, and then shrink back to nothing particle.Size = MathHelper.Lerp(particle.StartSize, particle.EndSize, DPSFHelper.InterpolationAmountForEqualLerpInAndLerpOut(particle.NormalizedElapsedTime)); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = 0.2f; particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-15, 15), RandomNumber.Next(-15, 15), RandomNumber.Next(-15, 15)); particle.Size = particle.StartSize = 1; particle.EndSize = ExplosionParticleSize; // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: textureCoordinates = _flash1TextureCoordinates; break; case 1: textureCoordinates = _flash2TextureCoordinates; break; case 2: textureCoordinates = _flash3TextureCoordinates; break; case 3: textureCoordinates = _flash4TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFlashSize(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have the particle reach its full size when it reaches half its lifetime, and then shrink back to nothing particle.Size = MathHelper.Lerp(particle.StartSize, particle.EndSize, DPSFHelper.InterpolationAmountForEqualLerpInAndLerpOut(particle.NormalizedElapsedTime)); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.3f, 0.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.Black; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(1, 50); particle.ExternalForce = new Vector3(0, 80, 0); // We want the smoke to rise particle.Size = particle.StartSize = 1; // Have the particles start small and grow particle.EndSize = ExplosionParticleSize; // Give the particle a random initial orientation and random rotation velocity (only need to Roll the particle since it will always face the camera) particle.Rotation = RandomNumber.Between(0, MathHelper.TwoPi); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: textureCoordinates = _flameSmoke1TextureCoordinates; break; case 1: textureCoordinates = _flameSmoke2TextureCoordinates; break; case 2: textureCoordinates = _flameSmoke3TextureCoordinates; break; case 3: textureCoordinates = _flameSmoke4TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(1.2f, 1.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.DarkGray; particle.Position = Emitter.PositionData.Position; particle.ExternalForce = new Vector3(0, -80, 0); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); particle.Velocity = DPSFHelper.RandomNormalizedVector(); // Calculate the direction the particle will travel in // We want the debris to travel upwards more often than downward, so if it's travelling downward switch it to travel upward 50% of the time if (particle.Velocity.Y < 0 && RandomNumber.Next(0, 2) == 0) particle.Velocity.Y *= -1; // Fire some particles towards the camera (but not directly at it) for a more dramatic effect if (RandomNumber.Between(0, 5) == 0) { // Calculate a point somewhere around the camera int distance = 10; Vector3 somewhereAroundTheCamera = new Vector3(CameraPosition.X + RandomNumber.Next(-distance, distance), CameraPosition.Y + RandomNumber.Next(-distance, distance), CameraPosition.Z + RandomNumber.Next(-distance, distance)); // Direct the Particle towards the spot around the camera particle.Velocity = somewhereAroundTheCamera - particle.Position; particle.Velocity.Normalize(); } // Set the Particle's Speed particle.Velocity *= RandomNumber.Next(100, 150); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 9)) { default: case 0: textureCoordinates = _debris1TextureCoordinates; break; case 1: textureCoordinates = _debris2TextureCoordinates; break; case 2: textureCoordinates = _debris3TextureCoordinates; break; case 3: textureCoordinates = _debris4TextureCoordinates; break; case 4: textureCoordinates = _debris5TextureCoordinates; break; case 5: textureCoordinates = _debris6TextureCoordinates; break; case 6: textureCoordinates = _debris7TextureCoordinates; break; case 7: textureCoordinates = _debris8TextureCoordinates; break; case 8: textureCoordinates = _debris9TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); // Set the Width to Height ratio so the image isn't skewed when we scale it particle.Width = textureCoordinates.Width; particle.Height = textureCoordinates.Height; // Set the particle to the specified size, give or take 25% particle.ScaleToWidth(ExplosionParticleSize * RandomNumber.Between(0.75f, 1.25f)); }
/// <summary> /// Updates the Particle's DistanceFromCameraSquared property to reflect how far this Particle is from the Camera. /// </summary> /// <param name="cParticle">The Particle to update.</param> /// <param name="fElapsedTimeInSeconds">How long it has been since the last update.</param> protected void UpdateParticleDistanceFromCameraSquared(DefaultSprite3DBillboardTextureCoordinatesParticle cParticle, float fElapsedTimeInSeconds) { //cParticle.DistanceFromCameraSquared = Vector3.DistanceSquared(this.CameraPosition, cParticle.Position); }
//=========================================================== // Particle Update Functions //=========================================================== protected void BounceOffFloor(DefaultSprite3DBillboardTextureCoordinatesParticle cParticle, float fElapsedTimeInSeconds) { // If the Particle has hit the floor and is still travelling downwards if (cParticle.Position.Y <= 0 && cParticle.Velocity.Y < 0) { // Make the Particle Bounce upwards cParticle.Velocity.Y *= -mfBounciness; // Reduce the Particles X and Z speed cParticle.Velocity.X *= 0.8f; cParticle.Velocity.Z *= 0.8f; // Reduce the Particles Rotation speed cParticle.RotationalVelocity *= 0.8f; } }
public void InitializeParticleWithTextureCoordinates(DefaultSprite3DBillboardTextureCoordinatesParticle cParticle) { // Initialize the particle using the InitialProperties specified above InitializeParticleUsingInitialProperties(cParticle); // Randomly pick which texture coordinates to use for this particle Rectangle sTextureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: sTextureCoordinates = msCloudTextureCoordinates; break; case 1: sTextureCoordinates = msSparkTextureCoordinates; break; case 2: sTextureCoordinates = msRockTextureCoordinates; break; case 3: sTextureCoordinates = msRingTextureCoordinates; break; } // Set the Particle's Texture Coordinates cParticle.SetTextureCoordinates(sTextureCoordinates); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(1.2f, 1.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.DarkGray; particle.Position = Emitter.PositionData.Position; particle.ExternalForce = new Vector3(0, -80, 0); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); particle.Velocity = DPSFHelper.RandomNormalizedVector(); // Calculate the direction the particle will travel in // We want the debris to travel upwards more often than downward, so if it's travelling downward switch it to travel upward 50% of the time if (particle.Velocity.Y < 0 && RandomNumber.Next(0, 2) == 0) { particle.Velocity.Y *= -1; } // Fire some particles towards the camera (but not directly at it) for a more dramatic effect if (RandomNumber.Between(0, 5) == 0) { // Calculate a point somewhere around the camera int distance = 10; Vector3 somewhereAroundTheCamera = new Vector3(CameraPosition.X + RandomNumber.Next(-distance, distance), CameraPosition.Y + RandomNumber.Next(-distance, distance), CameraPosition.Z + RandomNumber.Next(-distance, distance)); // Direct the Particle towards the spot around the camera particle.Velocity = somewhereAroundTheCamera - particle.Position; particle.Velocity.Normalize(); } // Set the Particle's Speed particle.Velocity *= RandomNumber.Next(100, 150); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 9)) { default: case 0: textureCoordinates = _debris1TextureCoordinates; break; case 1: textureCoordinates = _debris2TextureCoordinates; break; case 2: textureCoordinates = _debris3TextureCoordinates; break; case 3: textureCoordinates = _debris4TextureCoordinates; break; case 4: textureCoordinates = _debris5TextureCoordinates; break; case 5: textureCoordinates = _debris6TextureCoordinates; break; case 6: textureCoordinates = _debris7TextureCoordinates; break; case 7: textureCoordinates = _debris8TextureCoordinates; break; case 8: textureCoordinates = _debris9TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); // Set the Width to Height ratio so the image isn't skewed when we scale it particle.Width = textureCoordinates.Width; particle.Height = textureCoordinates.Height; // Set the particle to the specified size, give or take 25% particle.ScaleToWidth(ExplosionParticleSize * RandomNumber.Between(0.75f, 1.25f)); }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFireSmokeColor(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have particle be the specified color for the first part of its lifetime float firstPartOfLifetime = 0.2f; if (particle.NormalizedElapsedTime < firstPartOfLifetime) { particle.Color = particle.StartColor; } // Then start fading it to black to look like smoke else { float lerpAmount = (particle.NormalizedElapsedTime - firstPartOfLifetime) * (1.0f / (1.0f - firstPartOfLifetime)); particle.Color = DPSFHelper.LerpColor(particle.StartColor, particle.EndColor, lerpAmount); } }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.5f, 1.0f); particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(30, 50); particle.ExternalForce = new Vector3(0, 20, 0); particle.Size = ExplosionParticleSize; particle.SetTextureCoordinates(_roundSparkTextureCoordinates); }
protected void UpdateParticleFireSmokeSize(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have particle grow to its full size within the first 20% of its lifetime if (particle.NormalizedElapsedTime < 0.2f) { particle.Size = MathHelper.Lerp(particle.StartWidth, particle.EndWidth, particle.NormalizedElapsedTime * 5); } else { particle.Size = particle.EndWidth; } }