public override Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent) { var name = ComputeNewName(parent, "Smoke particle system"); var component = new ParticleSystemComponent(); var emitter = new ParticleEmitter { ParticleLifetime = new Vector2(1, 2) }; // 20 Particle per second var spawner = new SpawnerPerSecond { SpawnCount = 20 }; emitter.Spawners.Add(spawner); // Size var randSize = new InitialSizeSeed { RandomSize = new Vector2(0.35f, 0.55f) }; emitter.Initializers.Add(randSize); // Position var randPos = new InitialPositionSeed { PositionMin = new Vector3(-0.2f, 0, -0.2f), PositionMax = new Vector3(0.2f, 0, 0.2f) }; emitter.Initializers.Add(randPos); // Velocity var randVel = new InitialVelocitySeed { VelocityMin = new Vector3(-0.5f, 1f, -0.5f), VelocityMax = new Vector3(0.5f, 3, 0.5f) }; emitter.Initializers.Add(randVel); component.ParticleSystem.Emitters.Add(emitter); return(CreateEntityWithComponent(name, component)); }
public void EmitterUpdate() { var emitter = new ParticleEmitter(); var dummyParticleSystem = new ParticleSystem(); const float dt = 0.0166666666667f; // Updating the emitter forces the creation of a default spawner (100 particles per second) emitter.Update(dt, dummyParticleSystem); var forceField = new UpdaterForceField(); emitter.Updaters.Add(forceField); var positionSeed = new InitialPositionSeed(); emitter.Initializers.Add(positionSeed); var velocitySeed = new InitialVelocitySeed(); emitter.Initializers.Add(velocitySeed); // Fixed delta time for simulating 60 fps var totalTime = 0f; // Simulate 10 seconds while (totalTime < 10) { emitter.Update(dt, dummyParticleSystem); totalTime += dt; } emitter.Updaters.Remove(forceField); // Simulate 10 seconds while (totalTime < 10) { emitter.Update(dt, dummyParticleSystem); totalTime += dt; } emitter.Initializers.Remove(positionSeed); // Simulate 10 seconds while (totalTime < 10) { emitter.Update(dt, dummyParticleSystem); totalTime += dt; } emitter.Updaters.Add(forceField); emitter.Initializers.Add(positionSeed); // Simulate 10 seconds while (totalTime < 10) { emitter.Update(dt, dummyParticleSystem); totalTime += dt; } // The emitter update doesn't assert anything as the state of the particle system will be difficult to predict // Such tests will be part of the GraphicsTests }