public void SimulateParticles(ParticleEmitterComponent component, ForcesComponent forces, TransformComponent transform) { if (component.IsEnabled) { this.SimulationEffect.Velocity = component.Velocity.ReadTarget; this.SimulationEffect.Position = component.Position.ReadTarget; this.SimulationEffect.InitialVelocity = component.InitialVelocity.ReadTarget; this.SimulationEffect.LengthScale = component.LengthScale; this.SimulationEffect.FieldSpeed = component.FieldSpeed; this.SimulationEffect.NoiseStrength = component.NoiseStrength; this.SimulationEffect.ProgressionRate = component.ProgressionRate; this.SimulationEffect.SpherePosition = component.SpherePosition; this.SimulationEffect.SphereRadius = component.SphereRadius; this.SimulationEffect.EmitterSize = component.Size; this.SimulationEffect.MaxLifeTime = component.MaxLifeTime; this.SimulationEffect.Elapsed = this.FrameService.Elapsed; this.SimulationEffect.Time = this.FrameService.Time; this.SimulationEffect.ParentVelocity = forces.Velocity; this.SimulationEffect.ObjectToWorld = transform.Matrix; this.SimulationEffect.WorldToObject = Matrix.Invert(transform.Matrix); this.SimulationEffect.ApplyParticleVelocitySimulationTechnique(); this.Device.SetRenderTarget(component.Velocity.WriteTarget); this.PostProcessTriangle.Render(this.Device); this.SimulationEffect.ApplyParticlePositionSimulationTechnique(); this.Device.SetRenderTargets(component.Position.WriteTarget, component.InitialVelocity.WriteTarget); this.PostProcessTriangle.Render(this.Device); component.Swap(); } }
public (ParticleEmitterComponent, TransformComponent, BoundingSphereComponent, ForcesComponent) Create(int paticleCount) { var entity = this.Entities.Create(); var particleEmitter = new ParticleEmitterComponent(entity, this.Device, paticleCount); var transform = new TransformComponent(entity); var bounds = new BoundingSphereComponent(entity, 1.0f); // Automatically adjusted by particle system var forces = new ForcesComponent(entity); this.Components.Add(particleEmitter, transform, bounds, forces); return(particleEmitter, transform, bounds, forces); }