Particle3DEmitterTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Rendering3D.Particles.Tests Particle3DEmitterTests

Namespace: DeltaEngine.Rendering3D.Particles.Tests
Assembly: DeltaEngine.Rendering3D.Particles.Tests (in DeltaEngine.Rendering3D.Particles.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class Particle3DEmitterTests : TestWithMocksOrVisually

The Particle3DEmitterTests type exposes the following members.

Constructors

  NameDescription
Public methodParticle3DEmitterTests
Initializes a new instance of the Particle3DEmitterTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCircleEmitterGivesCylinderWithDifferingZ
Public methodCreateCamera
Public methodDisposingTwiceDoesNotError
Public methodDrawLensFlareEffect
Public methodEmittersFromSameDataAreStillIndependentlyChangeable
Public methodEscapeEmitterGivesCylinderWithDifferingZ
Public methodFire
Public methodFireOneBullet
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLoadParticleEmitterDataToGetConsistentValues
Public methodMultipleEmittersDifferentMaterials
Public methodParticlesTrackingEmitterUpdatingPosition
Public methodParticlesUpdatingPosition
Public methodParticleTracksEmitterAcrossScreenFor4Seconds
Public methodProjectileMovesAcrossScreenEmittingFire
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetDifferentBillBoardModes
Public methodSetDifferentBlendMode
Public methodSetForce
Public methodSmokeAndWind
Public methodSpawnOneBurst
Public methodSpawnOneTimedBurst
Public methodSpawnParticlesInCertainPosition
Public methodSpawnParticlesWithCertainRotation
Public methodSwitchMaterialsOfParticles
Public methodTooManyParticlesThrowsError
Public methodTrackRotationOfEmitter
Public methodTrackRotationOfEmitterVisually
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void SpawnOneBurst()
{
    camera.Position = Vector3D.One / 2;
    var emitterData = GetEmitterData(spark, 512);
    emitterData.SpawnInterval = 0.0f;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    new Command(() => emitter.Spawn(64)).Add(new KeyTrigger(Key.Space));
}
[Test, CloseAfterFirstFrame]
public void DisposingTwiceDoesNotError()
{
    var emitter = new ParticleEmitter(GetEmitterData(spark, 512), Vector3D.Zero);
    emitter.DisposeAfterSeconds(1);
    emitter.DisposeAfterSeconds(1);
}
[Test]
public void SpawnOneTimedBurst()
{
    var emitterData = GetEmitterData(spark, 512);
    emitterData.SpawnInterval = 0.0007f;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    emitter.DisposeAfterSeconds(emitterData.LifeTime);
}
[Test]
public void SmokeAndWind()
{
    window.BackgroundColor = new Color(40, 64, 20);
    var defaultForce = new RangeGraph<Vector3D>(Vector3D.Zero);
    var windForce = new RangeGraph<Vector3D>(new Vector3D(-0.5f, -0.01f, 0.0f),
        new Vector3D(-1.0f, 0.01f, 0.0f));
    var emitterData = GetEmitterData(spark, 256, 2.0f);
    emitterData.Color = new RangeGraph<Color>(Color.White, Color.Transparent(Color.DarkGray));
    emitterData.Size = new RangeGraph<Size>(new Size(0.05f), new Size(0.2f));
    emitterData.Acceleration = defaultForce;
    emitterData.StartVelocity = new RangeGraph<Vector3D>(new Vector3D(0.0f, 0.0f, 0.35f),
        new Vector3D(0.1f, 0.1f, 0.1f));
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    new Command(() => emitter.EmitterData.Acceleration = windForce).Add(new KeyTrigger(Key.Space));
    new Command(() => emitter.EmitterData.Acceleration = defaultForce).Add(
        new KeyTrigger(Key.Space, State.Releasing));
}
[Test]
public void Fire()
{
    var emitterData = GetEmitterData(fire, 512, 2.0f);
    emitterData.Color = new RangeGraph<Color>(new Color(16, 16, 16), new Color(255, 64, 64, 0));
    emitterData.Acceleration = new RangeGraph<Vector3D>(Vector3D.Zero, Vector3D.UnitZ * 0.1f);
    emitterData.Size = new RangeGraph<Size>(new Size(0.2f), new Size(0.1f));
    emitterData.StartVelocity = new RangeGraph<Vector3D>(new Vector3D(0.0f, 0.0f, 0.3f),
        new Vector3D(0.1f, 0.1f, 0.1f));
    new ParticleEmitter(emitterData, new Vector3D(0.1f, 0.0f, 0.0f));
    new ParticleEmitter(emitterData, new Vector3D(0.0f, 0.1f, 0.0f));
}
[Test, CloseAfterFirstFrame]
public void SetForce()
{
    var emitter = new ParticleEmitter(GetEmitterData(spark, 512), Vector3D.Zero);
    var force = new RangeGraph<Vector3D>(Vector3D.One);
    emitter.EmitterData.Acceleration = force;
    Assert.AreEqual(force, emitter.EmitterData.Acceleration);
}
[Test, CloseAfterFirstFrame]
public void TooManyParticlesThrowsError()
{
    var emitterData = GetEmitterData(spark, ParticleEmitter.MaxParticles + 1);
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    Assert.Throws<ParticleEmitter.MaximumNumberOfParticlesExceeded>(() => emitter.Spawn());
    emitter.IsActive = false;
}
[Test, CloseAfterFirstFrame]
public void ParticlesUpdatingPosition()
{
    Randomizer.Use(new FixedRandom());
    var emitter = new ParticleEmitter(GetEmitterData(logo), Vector3D.Zero);
    AdvanceTimeAndUpdateEntities(0.1f);
    Assert.AreNotEqual(emitter.Position, emitter.particles[0].Position);
    Assert.IsTrue(
        emitter.particles[0].Position.IsNearlyEqual(new Vector3D(-0.03333334f, -0.03333334f,
            0.0058f)));
}
[Test, CloseAfterFirstFrame]
public void ParticlesTrackingEmitterUpdatingPosition()
{
    Randomizer.Use(new FixedRandom());
    var emitterData = GetEmitterData(logo);
    emitterData.DoParticlesTrackEmitter = true;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    AdvanceTimeAndUpdateEntities(0.1f);
    emitter.Position = Vector3D.One;
    AdvanceTimeAndUpdateEntities(0.1f);
    Assert.IsTrue(
        emitter.particles[0].Position.IsNearlyEqual(new Vector3D(0.90025f, 0.90025f, 1.0175f)));
}
[Test]
public void ParticleTracksEmitterAcrossScreenFor4Seconds()
{
    var emitter = new ParticleEmitter(CreateTrackingParticleData(), Vector3D.Zero);
    emitter.Start<MoveAcrossScreen>();
    emitter.DisposeAfterSeconds(4);
}
[Test]
public void ProjectileMovesAcrossScreenEmittingFire()
{
    var start = -3 * Vector3D.UnitX;
    var emitter = new ParticleEmitter(CreateTrackingParticleData(), start);
    var emitter2 = new ParticleEmitter(CreateFireExhaustParticleData(), start);
    emitter.Start<MoveAcrossScreen>();
    emitter2.Start<MoveAcrossScreen>();
}
[Test]
public void FireOneBullet()
{
    var emitterData = GetEmitterData(water, 512, 2.0f);
    emitterData.SpawnInterval = 0.0f;
    emitterData.Acceleration = new RangeGraph<Vector3D>(Vector3D.Zero, Vector3D.Zero);
    emitterData.Color = new RangeGraph<Color>(new Color(255, 255, 255), new Color(255, 255, 255));
    emitterData.Size = new RangeGraph<Size>(new Size(0.5f), new Size(0.5f));
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    var enemy = new MockEnemy(new Vector3D(0, -3, 0), Size.Half, spark);
    new Command(() => //ncrunch: no coverage start
    {
        emitter.EmitterData.BillboardMode = BillboardMode.Ground;
        emitter.EmitterData.StartVelocity.Start = enemy.Position * 4.0f + enemy.direction * 0.5f;
        emitter.EmitterData.StartVelocity.End = Vector3D.Zero;
        emitter.Spawn();
    }).Add(new KeyTrigger(Key.Space));
    //ncrunch: no coverage end
}
[Test, CloseAfterFirstFrame]
public void LoadParticleEmitterDataToGetConsistentValues()
{
    var data = ContentLoader.Load<ParticleEmitterData>("FireEmitter");
    Assert.IsNotNull(data.ParticleMaterial.DiffuseMap);
    Assert.AreEqual(256, data.MaximumNumberOfParticles);
    Assert.AreEqual(5.0f, data.LifeTime);
    Assert.AreEqual(0.1f, data.SpawnInterval);
    Assert.AreEqual(Color.Red, data.Color.Start);
    Assert.AreEqual(Color.Green, data.Color.End);
}
[Test]
public void SetDifferentBlendMode()
{
    var emitterData = GetEmitterData(logo);
    emitterData.ParticleMaterial.DiffuseMap.BlendMode = BlendMode.Additive;
    emitterData.DoParticlesTrackEmitter = true;
    new ParticleEmitter(emitterData, Vector3D.Zero);
    AdvanceTimeAndUpdateEntities();
}
[Test]
public void SwitchMaterialsOfParticles()
{
    var emitterData = GetEmitterData(logo);
    emitterData.ParticleMaterial.DiffuseMap.BlendMode = BlendMode.Additive;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    AdvanceTimeAndUpdateEntities();
    emitter.particles[0].Material = new Material(ShaderFlags.ColoredTextured, "ParticleSpark");
    emitterData.ParticleMaterial.DiffuseMap.BlendMode = BlendMode.Additive;
    AdvanceTimeAndUpdateEntities();
}
[Test]
public void EmittersFromSameDataAreStillIndependentlyChangeable()
{
    var emitterData = GetEmitterData(logo);
    var emitterChanging = new ParticleEmitter(emitterData, Vector3D.Zero);
    var emitterStayingSame = new ParticleEmitter(emitterData, Vector3D.UnitX);
    emitterChanging.EmitterData.SpawnInterval += 0.2f;
    emitterChanging.EmitterData.Acceleration = new RangeGraph<Vector3D>(Vector3D.One);
    emitterChanging.EmitterData.Color = new RangeGraph<Color>(Color.Green, Color.Yellow);
    Assert.AreNotEqual(emitterStayingSame.EmitterData.SpawnInterval,
        emitterChanging.EmitterData.SpawnInterval);
    Assert.AreNotEqual(emitterStayingSame.EmitterData.Acceleration.Values,
        emitterChanging.EmitterData.Acceleration.Values);
    Assert.AreNotEqual(emitterStayingSame.EmitterData.Color.Values,
        emitterChanging.EmitterData.Color.Values);
}
[Test]
public void CircleEmitterGivesCylinderWithDifferingZ()
{
    var emitterData = GetEmitterData(logo, 256, 3);
    emitterData.PositionType = ParticleEmitterPositionType.CircleAroundCenter;
    emitterData.StartPosition = new RangeGraph<Vector3D>(new Vector3D(-0.1f, -0.1f, 0.0f),
        new Vector3D(0.1f, 0.1f, 0.0f));
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    emitter.Position = -0.2f * Vector3D.UnitZ;
    emitter.Rotation = Quaternion.FromAxisAngle(Vector3D.UnitY, -10);
}
[Test]
public void EscapeEmitterGivesCylinderWithDifferingZ()
{
    var emitterData = GetEmitterData(logo);
    emitterData.PositionType = ParticleEmitterPositionType.CircleEscaping;
    emitterData.StartPosition = new RangeGraph<Vector3D>(new Vector3D(-0.5f, -0.5f, 0.0f),
        new Vector3D(0.5f, 0.5f, 0.5f));
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    emitter.Position = -0.2f * Vector3D.UnitZ;
    emitter.Rotation = Quaternion.FromAxisAngle(Vector3D.UnitY, -10);
}
[Test]
public void MultipleEmittersDifferentMaterials()
{
    new ParticleEmitter(GetEmitterData(logo), Vector3D.Zero);
    new ParticleEmitter(GetEmitterData(spark), Vector3D.UnitX);
}
[Test]
public void TrackRotationOfEmitterVisually()
{
    var emitterData = CreateTrackingParticleData();
    emitterData.SpawnInterval = 0;
    emitterData.BillboardMode = BillboardMode.Ground;
    emitterData.LifeTime = 1.0f;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    new Command(Command.Click, 
        () => emitter.Rotation *= Quaternion.FromAxisAngle(Vector3D.UnitY, 30.0f)); //ncrunch: no coverage 
    new Command(Command.MiddleClick, () => emitter.Spawn(1));
}
[Test, CloseAfterFirstFrame]
public void TrackRotationOfEmitter()
{
    var emitterData = CreateTrackingParticleData();
    emitterData.SpawnInterval = 0;
    emitterData.BillboardMode = BillboardMode.Ground;
    emitterData.LifeTime = 0.0f;
    var emitter = new ParticleEmitter(emitterData, Vector3D.Zero);
    emitter.Rotation = Quaternion.FromAxisAngle(Vector3D.UnitZ, 60);
    AdvanceTimeAndUpdateEntities();
    emitter.Spawn(1);
    Assert.AreEqual(emitter.Rotation.CalculateAxisAngle(), emitter.particles[0].Rotation);
    emitter.Rotation = Quaternion.FromAxisAngle(Vector3D.UnitZ, 90);
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(emitter.Rotation.CalculateAxisAngle(), emitter.particles[0].Rotation);
}
[Test]
public void SpawnParticlesInCertainPosition()
{
    var emitter = new ParticleEmitter(GetEmitterData(logo), Vector3D.Zero);
    emitter.SpawnAtRelativePosition(Vector3D.One, 1);
    Assert.AreEqual(Vector3D.One, emitter.particles[0].Position);
    emitter.SpawnAtRelativePosition(Vector3D.UnitX);
    Assert.AreEqual(Vector3D.UnitX, emitter.particles[1].Position);
}
[Test]
public void SpawnParticlesWithCertainRotation()
{
    var emitter = new ParticleEmitter(GetEmitterData(logo), Vector3D.Zero);
    emitter.SpawnAtRelativePositionAndRotation(Vector3D.One, 0.5f, 1);
    Assert.AreEqual(Vector3D.One, emitter.particles[0].Position);
    emitter.SpawnAtRelativePositionAndRotation(Vector3D.UnitX, 0.5f);
    Assert.AreEqual(Vector3D.UnitX, emitter.particles[1].Position);
}
[Test]
public void DrawLensFlareEffect()
{
    grid.IsActive = false;
    freeCamera = Camera.Use<FreeCamera>();
    freeCamera.Position = Vector3D.UnitZ;
    CreateParticleEmitters();
    new Command(MoveLight).Add(new MouseMovementTrigger());
}
See Also