mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
799b1edb06
* yay, a start on data driven particles * added data driven support for all particle profiles * pretty much finished all of the particle serialization code * resolved an inconsistency with the interpolators
30 lines
955 B
C#
30 lines
955 B
C#
using Microsoft.Xna.Framework;
|
|
|
|
namespace MonoGame.Extended.Particles.Modifiers
|
|
{
|
|
public unsafe class VortexModifier : IModifier
|
|
{
|
|
// Note: not the real-life one
|
|
private const float _gravConst = 100000f;
|
|
|
|
public Vector2 Position { get; set; }
|
|
public float Mass { get; set; }
|
|
public float MaxSpeed { get; set; }
|
|
|
|
public void Update(float elapsedSeconds, ParticleBuffer.ParticleIterator iterator)
|
|
{
|
|
while (iterator.HasNext)
|
|
{
|
|
var particle = iterator.Next();
|
|
var diff = Position + particle->TriggerPos - particle->Position;
|
|
|
|
var distance2 = diff.LengthSquared();
|
|
|
|
var speedGain = _gravConst*Mass/distance2*elapsedSeconds;
|
|
// normalize distances and multiply by speedGain
|
|
diff.Normalize();
|
|
particle->Velocity += diff*speedGain;
|
|
}
|
|
}
|
|
}
|
|
} |