public unsafe void Update(ParticleSystem particleSystem, float dt) { var accelerationField = particleSystem.GetOrCreateField(ParticleFields.Acceleration); foreach (var particle in particleSystem) { var acceleration = (Vector3*)particle[accelerationField]; *acceleration += GravityForce; } }
public void Update(ParticleSystem particleSystem, float dt) { var velocityField = particleSystem.GetOrCreateField(ParticleFields.Velocity); // No more than 1000 particles if (particleSystem.ParticleCount < 1000) { var particle = particleSystem.AddParticle(); // Default random velocity, going upward particle.Set(velocityField, new Vector3((float)rand.NextDouble() * 30.0f - 15.0f, (float)rand.NextDouble() * 30.0f - 15.0f, (float)rand.NextDouble() * 50.0f)); } }
public unsafe void Update(ParticleSystem particleSystem, float dt) { var lifetimeField = particleSystem.GetOrCreateField(LifetimeField); // Iterate over particles var particleEnumerator = particleSystem.GetEnumerator(); while (particleEnumerator.MoveNext()) { var particle = particleEnumerator.Current; var lifetime = (float*)particle[lifetimeField]; // Remove particle through enumerator. // Enumerator will be valid again in next loop. if ((*lifetime += dt) > Lifetime) particleEnumerator.RemoveParticle(); } }
public unsafe void Update(ParticleSystem particleSystem, float dt) { var accelerationField = particleSystem.GetOrCreateField(ParticleFields.Acceleration); var velocityField = particleSystem.GetOrCreateField(ParticleFields.Velocity); foreach (var particle in particleSystem) { var position = (Vector3*)particle[particleSystem.Position]; var acceleration = (Vector3*)particle[accelerationField]; var velocity = (Vector3*)particle[velocityField]; *velocity += *acceleration * dt; *position += *velocity * dt; } }