Example #1
0
            public Emitter(IModifier[] modifiers)
            {
                _modifiers = modifiers;

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    Particles.GetFloatValues("TimeAlive")[x]                   = 0;
                    Particles.GetFloatValues("RotationInRadians")[x]           = 1;
                    Particles.GetVector2Values("Position")[x]                  = new Vector2(100, 100);
                    Particles.GetVector2Values("ReferencePosition")[x]         = new Vector2(100, 100);
                    Particles.GetFloatValues("RotationalVelocityInRadians")[x] = 1f;
                    Particles.GetFloatValues("CurrentRed")[x]                  = 255;
                    Particles.GetFloatValues("CurrentGreen")[x]                = 255;
                    Particles.GetFloatValues("CurrentBlue")[x]                 = 255;
                    Particles.GetFloatValues("CurrentAlpha")[x]                = 255;
                    Particles.GetVector2Values("Size")[x]             = Vector2.Zero;
                    Particles.GetVector2Values("InitialSize")[x]      = new Vector2(32, 32);
                    Particles.GetVector2Values("Velocity")[x]         = new Vector2(100, 100);
                    Particles.GetByteValues("TextureSectionIndex")[x] = 0;
                    Particles.GetByteValues("InitialAlpha")[x]        = 255;
                    Particles.GetByteValues("InitialBlue")[x]         = 255;
                    Particles.GetByteValues("InitialGreen")[x]        = 255;
                    Particles.GetByteValues("InitialRed")[x]          = 255;
                    Particles.GetFloatValues("Altitude")[x]           = 0;
                    Particles.GetFloatValues("AltitudeVelocity")[x]   = 0;
                    Particles.GetIntValues("AltitudeBounceCount")[x]  = 0;
                }
            }
Example #2
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var offset      = Vector <float> .Count;
                var deltaVector = new Vector <float>(timeSinceLastFrame);

                var rotationInRadians           = particles.GetFloatValues("RotationInRadians");
                var rotationalVelocityInRadians = particles.GetFloatValues("RotationalVelocityInRadians");

                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);
                int x;

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var rotationsSlice = rotationInRadians.Slice(x, offset);
                    var rotationVector = new Vector <float>(rotationsSlice);

                    var velocityVector         = new Vector <float>(rotationalVelocityInRadians.Slice(x, offset));
                    var velocitySinceLastFrame = velocityVector * deltaVector;

                    (rotationVector + velocitySinceLastFrame).CopyTo(rotationsSlice);
                }

                // Remaining values
                for (; x < Program.ParticleCount; ++x)
                {
                    rotationInRadians[x] += rotationalVelocityInRadians[x] * timeSinceLastFrame;
                }
            }
Example #3
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var xSlice = velocityX.Slice(x, offset);
                    var ySlice = velocityY.Slice(x, offset);

                    var xVector = new Vector <float>(xSlice);
                    var yVector = new Vector <float>(ySlice);

                    var xDeltaVector = (xVector * Emitter.Drag) * timeSinceLastFrame;
                    var yDeltaVector = (yVector * Emitter.Drag) * timeSinceLastFrame;

                    (xVector - xDeltaVector).CopyTo(xSlice);
                    (yVector - yDeltaVector).CopyTo(ySlice);
                }

                // Remaining
                for (; x < Program.ParticleCount; x++)
                {
                    velocityX[x] -= Emitter.Drag * velocityX[x] * timeSinceLastFrame;
                    velocityY[x] -= Emitter.Drag * velocityY[x] * timeSinceLastFrame;
                }
            }
Example #4
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var sizeX = particles.GetFloatValues("SizeX");
                var sizeY = particles.GetFloatValues("SizeY");

                var sizeXChangeVector = new Vector <float>(Emitter.SizeChange);
                var sizeYChangeVector = new Vector <float>(Emitter.SizeChange);

                var offset = Vector <float> .Count;

                int x;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var sizeXSlice = sizeX.Slice(x, offset);
                    var sizeYSlice = sizeY.Slice(x, offset);

                    var sizeXVector = new Vector <float>(sizeXSlice);
                    var sizeYVector = new Vector <float>(sizeYSlice);

                    var deltaXVector = sizeXChangeVector * timeSinceLastFrame;
                    var deltaYVector = sizeYChangeVector * timeSinceLastFrame;

                    (sizeXVector + deltaXVector).CopyTo(sizeXSlice);
                    (sizeYVector + deltaYVector).CopyTo(sizeYSlice);
                }

                // Remaining items
                for (; x < Program.ParticleCount; ++x)
                {
                    sizeX[x] += timeSinceLastFrame * Emitter.SizeChange;
                    sizeY[x] += timeSinceLastFrame * Emitter.SizeChange;
                }
            }
Example #5
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX    = particles.GetFloatValues("VelocityX");
                var velocityY    = particles.GetFloatValues("VelocityY");
                var changeVector = new Vector <float>(Emitter.SizeChange);

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var xSlice = velocityX.Slice(x, offset);
                    var ySlice = velocityY.Slice(x, offset);

                    var xVector = new Vector <float>(xSlice);
                    var yVector = new Vector <float>(ySlice);

                    var xDeltaVector = changeVector * timeSinceLastFrame;
                    var yDeltaVector = changeVector * timeSinceLastFrame;

                    (xVector + xDeltaVector).CopyTo(xSlice);
                    (yVector + yDeltaVector).CopyTo(ySlice);
                }

                for (; x < Program.ParticleCount; ++x)
                {
                    velocityX[x] += timeSinceLastFrame * Emitter.SizeChange;
                    velocityY[x] += timeSinceLastFrame * Emitter.SizeChange;
                }
            }
Example #6
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var rotationInRadians           = particles.GetFloatValues("RotationInRadians");
                var rotationalVelocityInRadians = particles.GetFloatValues("RotationalVelocityInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    rotationInRadians[x] += rotationalVelocityInRadians[x] * timeSinceLastFrame;
                }
            }
Example #7
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");

                var rotationInRadians = particles.GetFloatValues("RotationInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    rotationInRadians[x] = (float)Math.Atan2(velocityY[x], velocityX[x]);
                }
            }
Example #8
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var textureSectionIndex = particles.GetByteValues("TextureSectionIndex");
                var timeAlive           = particles.GetFloatValues("TimeAlive");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    textureSectionIndex[x] = (byte)((timeAlive[x] / Emitter.MaxParticleLifeTime) * 10);
                }
            }
Example #9
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var sizeX        = particles.GetFloatValues("SizeX");
                var sizeY        = particles.GetFloatValues("SizeY");
                var initialSizeX = particles.GetFloatValues("InitialSizeX");
                var initialSizeY = particles.GetFloatValues("InitialSizeY");

                var endValueVector = new Vector <float>(Emitter.EndValue);
                var lifetimeVector = new Vector <float>(Emitter.MaxParticleLifeTime);

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var sizeXSlice = sizeX.Slice(x, offset);
                    var sizeYSlice = sizeY.Slice(x, offset);

                    var sizeXVector    = new Vector <float>(sizeXSlice);
                    var sizeYVector    = new Vector <float>(sizeYSlice);
                    var initialXVector = new Vector <float>(initialSizeX.Slice(x, offset));
                    var initialYVector = new Vector <float>(initialSizeY.Slice(x, offset));

                    var deltaXValue = (initialXVector - endValueVector) / lifetimeVector * timeSinceLastFrame;
                    var deltaYValue = (initialYVector - endValueVector) / lifetimeVector * timeSinceLastFrame;

                    (sizeXVector - deltaXValue).CopyTo(sizeXSlice);
                    (sizeYVector - deltaYValue).CopyTo(sizeYSlice);
                }

                // Remaining items
                for (; x < Program.ParticleCount; ++x)
                {
                    var width = (((initialSizeX[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                 timeSinceLastFrame);
                    var height = (((initialSizeY[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                  timeSinceLastFrame);
                    sizeX[x] -= width;
                    sizeY[x] -= height;
                }
            }
Example #10
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocity          = particles.GetVector2Values("Velocity");
                var position          = particles.GetVector2Values("Position");
                var referencePosition = particles.GetVector2Values("ReferencePosition");
                var altitude          = particles.GetFloatValues("Altitude");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    referencePosition[x] += velocity[x] * timeSinceLastFrame;
                    position[x].X         = referencePosition[x].X;
                    position[x].Y         = referencePosition[x].Y + altitude[x];
                }
            }
Example #11
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocity          = particles.GetVector2Values("Velocity");
                var rotationInRadians = particles.GetFloatValues("RotationInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    if (velocity[x] != Vector2.Zero)
                    {
                        rotationInRadians[x] =
                            (float)Math.Atan2(velocity[x].Y, velocity[x].X);
                    }
                }
            }
Example #12
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var currentRed   = particles.GetFloatValues("CurrentRed");
                var currentGreen = particles.GetFloatValues("CurrentGreen");
                var currentBlue  = particles.GetFloatValues("CurrentBlue");
                var currentAlpha = particles.GetFloatValues("CurrentAlpha");
                var initialRed   = particles.GetByteValues("InitialRed");
                var initialGreen = particles.GetByteValues("InitialGreen");
                var initialBlue  = particles.GetByteValues("InitialBlue");
                var initialAlpha = particles.GetByteValues("InitialAlpha");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    currentRed[x] -= (((initialRed[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                      timeSinceLastFrame);
                    currentGreen[x] -= (((initialGreen[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                        timeSinceLastFrame);
                    currentBlue[x] -= (((initialBlue[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                       timeSinceLastFrame);
                    currentAlpha[x] -= (((initialAlpha[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                        timeSinceLastFrame);
                }
            }
Example #13
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");
                var positionX = particles.GetFloatValues("PositionX");
                var positionY = particles.GetFloatValues("PositionY");
                var refPosX   = particles.GetFloatValues("ReferencePositionX");
                var refPosY   = particles.GetFloatValues("ReferencePositionY");
                var altitude  = particles.GetFloatValues("Altitude");

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var refPosXSlice = refPosX.Slice(x, offset);
                    var refPosYSlice = refPosY.Slice(x, offset);
                    var posXSlice    = positionX.Slice(x, offset);
                    var posYSlice    = positionY.Slice(x, offset);

                    var refPosXVector   = new Vector <float>(refPosXSlice);
                    var refPosYVector   = new Vector <float>(refPosYSlice);
                    var altitudeVector  = new Vector <float>(altitude.Slice(x, offset));
                    var velocityXVector = new Vector <float>(velocityX.Slice(x, offset));
                    var velocityYVector = new Vector <float>(velocityY.Slice(x, offset));

                    refPosXVector = (velocityXVector * timeSinceLastFrame) + refPosXVector;
                    refPosYVector = (velocityYVector * timeSinceLastFrame) + refPosYVector;

                    refPosXVector.CopyTo(refPosXSlice);
                    refPosYVector.CopyTo(refPosYSlice);

                    refPosXVector.CopyTo(posXSlice);
                    (refPosYVector + altitudeVector).CopyTo(posYSlice);
                }

                // Remaining
                for (; x < Program.ParticleCount; ++x)
                {
                    refPosX[x] += velocityX[x] * timeSinceLastFrame;
                    refPosY[x] += velocityY[x] * timeSinceLastFrame;

                    positionX[x] = refPosX[x];
                    positionY[x] = refPosY[x] + altitude[x];
                }
            }
Example #14
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var currentRed   = particles.GetFloatValues("CurrentRed");
                var currentGreen = particles.GetFloatValues("CurrentGreen");
                var currentBlue  = particles.GetFloatValues("CurrentBlue");
                var currentAlpha = particles.GetFloatValues("CurrentAlpha");
                var initialRed   = particles.GetFloatValues("InitialRed");
                var initialGreen = particles.GetFloatValues("InitialGreen");
                var initialBlue  = particles.GetFloatValues("InitialBlue");
                var initialAlpha = particles.GetFloatValues("InitialAlpha");

                var offset          = Vector <float> .Count;
                var endValueVector  = new Vector <float>(Emitter.EndValue);
                var lifetimeVector  = new Vector <float>(Emitter.MaxParticleLifeTime);
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                int x;

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    // Setup vectors
                    var currentRedSlice    = currentRed.Slice(x, offset);
                    var currentRedVector   = new Vector <float>(currentRedSlice);
                    var currentGreenSlice  = currentGreen.Slice(x, offset);
                    var currentGreenVector = new Vector <float>(currentGreenSlice);
                    var currentBlueSlice   = currentBlue.Slice(x, offset);
                    var currentBlueVector  = new Vector <float>(currentBlueSlice);
                    var currentAlphaSlice  = currentAlpha.Slice(x, offset);
                    var currentAlphaVector = new Vector <float>(currentAlphaSlice);

                    var initialRedVector   = new Vector <float>(initialRed.Slice(x, offset));
                    var initialGreenVector = new Vector <float>(initialGreen.Slice(x, offset));
                    var initialBlueVector  = new Vector <float>(initialBlue.Slice(x, offset));
                    var initialAlphaVector = new Vector <float>(initialAlpha.Slice(x, offset));

                    // Compute interpolated value
                    var interpolatedRedChangeVector   = ((initialRedVector - endValueVector) / lifetimeVector) * timeSinceLastFrame;
                    var interpolatedGreenChangeVector = ((initialGreenVector - endValueVector) / lifetimeVector) * timeSinceLastFrame;
                    var interpolatedBlueChangeVector  = ((initialBlueVector - endValueVector) / lifetimeVector) * timeSinceLastFrame;
                    var interpolatedAlphaChangeVector = ((initialAlphaVector - endValueVector) / lifetimeVector) * timeSinceLastFrame;

                    // Apply to current values
                    (currentRedVector - interpolatedRedChangeVector).CopyTo(currentRedSlice);
                    (currentGreenVector - interpolatedGreenChangeVector).CopyTo(currentGreenSlice);
                    (currentBlueVector - interpolatedBlueChangeVector).CopyTo(currentBlueSlice);
                    (currentAlphaVector - interpolatedAlphaChangeVector).CopyTo(currentAlphaSlice);
                }

                // Remaining values
                for (; x < Program.ParticleCount; ++x)
                {
                    currentRed[x] -= (((initialRed[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                      timeSinceLastFrame);
                    currentGreen[x] -= (((initialGreen[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                        timeSinceLastFrame);
                    currentBlue[x] -= (((initialBlue[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                       timeSinceLastFrame);
                    currentAlpha[x] -= (((initialAlpha[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                        timeSinceLastFrame);
                }
            }