示例#1
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultSprite3DBillboardParticle cParticleToCopy = (DefaultSprite3DBillboardParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.DistanceFromCameraSquared = cParticleToCopy.DistanceFromCameraSquared;
        }
示例#2
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultAnimatedTexturedQuadParticle cParticleToCopy = (DefaultAnimatedTexturedQuadParticle)ParticleToCopy;

            base.CopyFrom(ParticleToCopy);
            Animation.CopyFrom(cParticleToCopy.Animation);
        }
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultAnimatedSprite3DBillboardParticle cParticleToCopy = (DefaultAnimatedSprite3DBillboardParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            Animation.CopyFrom(cParticleToCopy.Animation);
        }
示例#4
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultSprite3DBillboardTextureCoordinatesParticle cParticleToCopy = (DefaultSprite3DBillboardTextureCoordinatesParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.TextureCoordinates = cParticleToCopy.TextureCoordinates;
        }
示例#5
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultTextureQuadTextureCoordinatesParticle cParticleToCopy = (DefaultTextureQuadTextureCoordinatesParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.NormalizedTextureCoordinateLeftTop     = cParticleToCopy.NormalizedTextureCoordinateLeftTop;
            this.NormalizedTextureCoordinateRightBottom = cParticleToCopy.NormalizedTextureCoordinateRightBottom;
        }
示例#6
0
        //===========================================================
        // Initialization Function
        //===========================================================

        /// <summary>
        /// Function to Initialize a Default Particle with default settings
        /// </summary>
        /// <param name="Particle">The Particle to be Initialized</param>
        public override void InitializeParticleUsingInitialProperties(DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultQuadParticle cParticle = (DefaultQuadParticle)Particle;

            // Initialize the Particle according to the values specified in the Initial Settings
            base.InitializeParticleUsingInitialProperties(cParticle, mcInitialProperties);

            // If the Rotation should be interpolated between the Min and Max Rotation
            if (mcInitialProperties.InterpolateBetweenMinAndMaxRotation)
            {
                // Calculate the Particle's initial Rotational values
                Vector3 sRotation = Vector3.Lerp(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax, RandomNumber.NextFloat());
                cParticle.Orientation = Quaternion.CreateFromYawPitchRoll(sRotation.Y, sRotation.X, sRotation.Z);
            }
            // Else the Rotation XYZ values should each be calculated individually
            else
            {
                // Calculate the Particle's initial Rotational values
                Vector3 sRotation = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax);
                cParticle.Orientation = Quaternion.CreateFromYawPitchRoll(sRotation.Y, sRotation.X, sRotation.Z);
            }

            // If the Rotational Velocity should be interpolated between the Min and Max Rotational Velocities
            if (mcInitialProperties.InterpolateBetweenMinAndMaxRotationalVelocity)
            {
                cParticle.RotationalVelocity = Vector3.Lerp(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax, RandomNumber.NextFloat());
            }
            // Else the Rotational Velocity XYZ values should each be calculated individually
            else
            {
                cParticle.RotationalVelocity = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax);
            }

            // If the Rotational Acceleration should be interpolated between the Min and Max Rotational Acceleration
            if (mcInitialProperties.InterpolateBetweenMinAndMaxRotationalAcceleration)
            {
                cParticle.RotationalAcceleration = Vector3.Lerp(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax, RandomNumber.NextFloat());
            }
            // Else the Rotational Acceleration XYZ values should each be calculated individually
            else
            {
                cParticle.RotationalAcceleration = DPSFHelper.RandomVectorBetweenTwoVectors(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax);
            }

            // Calculate the Particle's Width and Height values
            cParticle.StartWidth  = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartWidthMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartWidthMax);
            cParticle.EndWidth    = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndWidthMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndWidthMax);
            cParticle.StartHeight = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartHeightMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartHeightMax);
            cParticle.EndHeight   = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndHeightMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndHeightMax);
            cParticle.Width       = cParticle.StartWidth;
            cParticle.Height      = cParticle.StartHeight;
        }
示例#7
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DPSFDefaultBaseParticle cParticleToCopy = (DPSFDefaultBaseParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.Position = cParticleToCopy.Position;
            this.Color    = cParticleToCopy.Color;

            this.Velocity      = cParticleToCopy.Velocity;
            this.Acceleration  = cParticleToCopy.Acceleration;
            this.ExternalForce = cParticleToCopy.ExternalForce;
            this.Friction      = cParticleToCopy.Friction;
            this.StartColor    = cParticleToCopy.StartColor;
            this.EndColor      = cParticleToCopy.EndColor;
        }
示例#8
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultQuadParticle cParticleToCopy = (DefaultQuadParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.Orientation            = cParticleToCopy.Orientation;
            this.RotationalVelocity     = cParticleToCopy.RotationalVelocity;
            this.RotationalAcceleration = cParticleToCopy.RotationalAcceleration;
            this.Width       = cParticleToCopy.Width;
            this.Height      = cParticleToCopy.Height;
            this.StartHeight = cParticleToCopy.StartHeight;
            this.StartWidth  = cParticleToCopy.StartWidth;
            this.EndHeight   = cParticleToCopy.EndHeight;
            this.EndWidth    = cParticleToCopy.EndWidth;
            this.DistanceFromCameraSquared = cParticleToCopy.DistanceFromCameraSquared;
        }
示例#9
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteParticle cParticleToCopy = (DefaultSpriteParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.Rotation = cParticleToCopy.Rotation;
            this.Width    = cParticleToCopy.Width;
            this.Height   = cParticleToCopy.Height;
            this.FlipMode = cParticleToCopy.FlipMode;

            this.RotationalVelocity     = cParticleToCopy.RotationalVelocity;
            this.RotationalAcceleration = cParticleToCopy.RotationalAcceleration;

            this.StartWidth  = cParticleToCopy.StartWidth;
            this.StartHeight = cParticleToCopy.StartHeight;
            this.EndWidth    = cParticleToCopy.EndWidth;
            this.EndHeight   = cParticleToCopy.EndHeight;
        }
示例#10
0
        //===========================================================
        // Draw Sprite and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to draw a Sprite Particle. This function should be used to draw the given
        /// Particle with the provided SpriteBatch.
        /// </summary>
        /// <param name="Particle">The Particle Sprite to Draw</param>
        /// <param name="cSpriteBatch">The SpriteBatch to use to doing the Drawing</param>
        protected override void DrawSprite(DPSFParticle Particle, SpriteBatch cSpriteBatch)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteTextureCoordinatesParticle cParticle = (DefaultSpriteTextureCoordinatesParticle)Particle;

            // Get the Position and Dimensions of the Particle in 2D space
            Rectangle sDestination = new Rectangle((int)cParticle.Position.X, (int)cParticle.Position.Y,
                                                   (int)cParticle.Width, (int)cParticle.Height);

            // Get the Depth (Z-Buffer value) of the Particle clamped in the range 0.0 - 1.0 (0.0 = front, 1.0 = back)
            float fNormalizedDepth = MathHelper.Clamp(cParticle.Position.Z, 0.0f, 1.0f);

            // Get the Position and Dimensions from the Texture to use for this Sprite
            Rectangle sSourceFromTexture = cParticle.TextureCoordinates;

            // Make the Sprite rotate about its center
            Vector2 sOrigin = new Vector2(sSourceFromTexture.Width / 2, sSourceFromTexture.Height / 2);

            // Draw the Sprite
            cSpriteBatch.Draw(Texture, sDestination, sSourceFromTexture, cParticle.Color, cParticle.Rotation, sOrigin, cParticle.FlipMode, fNormalizedDepth);
        }
示例#11
0
        //===========================================================
        // Initialization Function
        //===========================================================

        /// <summary>
        /// Function to Initialize a Default Particle with default Properties
        /// </summary>
        /// <param name="Particle">The Particle to be Initialized</param>
        public override void InitializeParticleUsingInitialProperties(DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteParticle cParticle = (DefaultSpriteParticle)Particle;

            // Initialize the Particle according to the values specified in the Initial Settings
            base.InitializeParticleUsingInitialProperties(cParticle, mcInitialProperties);

            // Calculate the Particle's Rotation values
            cParticle.Rotation               = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax);
            cParticle.RotationalVelocity     = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax);
            cParticle.RotationalAcceleration = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax);

            // Calculate the Particle's Width and Height values
            cParticle.StartWidth  = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartWidthMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartWidthMax);
            cParticle.EndWidth    = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndWidthMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndWidthMax);
            cParticle.StartHeight = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartHeightMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartHeightMax);
            cParticle.EndHeight   = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndHeightMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndHeightMax);
            cParticle.Width       = cParticle.StartWidth;
            cParticle.Height      = cParticle.StartHeight;
        }
示例#12
0
        //===========================================================
        // Draw Sprite and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to draw a Sprite Particle. This function should be used to draw the given
        /// Particle with the provided SpriteBatch.
        /// </summary>
        /// <param name="Particle">The Particle Sprite to Draw</param>
        /// <param name="cSpriteBatch">The SpriteBatch to use to doing the Drawing</param>
        protected override void DrawSprite(DPSFParticle Particle, SpriteBatch cSpriteBatch)
        {
            // Cast the Particle to the type it really is
            DefaultSprite3DBillboardTextureCoordinatesParticle particle = (DefaultSprite3DBillboardTextureCoordinatesParticle)Particle;

            // Calculate the sprites position in 3D space, and flip it vertically so that it is not upside-down.
            Vector3 viewSpacePosition = Vector3.Transform(particle.Position, this.View);

            // Get the Position of the Particle relative to the camera
            Vector2 destination = new Vector2(viewSpacePosition.X, viewSpacePosition.Y);

            // Get the Position and Dimensions from the Texture to use for this Sprite
            Rectangle sourceFromTexture = particle.TextureCoordinates;

            // Calculate how much to scale the sprite to get it to the desired Width and Height.
            // Use negative height in order to flip the texture to be right-side up.
            Vector2 scale = new Vector2(particle.Width / sourceFromTexture.Width, -particle.Height / sourceFromTexture.Height);

            // Make the Sprite rotate about its center
            Vector2 origin = new Vector2(sourceFromTexture.Width / 2, sourceFromTexture.Height / 2);

            // Draw the Sprite
            cSpriteBatch.Draw(Texture, destination, sourceFromTexture, particle.ColorAsPremultiplied, particle.Rotation, origin, scale, particle.FlipMode, viewSpacePosition.Z);
        }
示例#13
0
 /// <summary>
 /// Deep copy the ParticleToCopy's values into this Particle
 /// </summary>
 /// <param name="ParticleToCopy">The Particle whose values should be Copied</param>
 public virtual void CopyFrom(DPSFParticle ParticleToCopy)
 {
     this.Lifetime    = ParticleToCopy.Lifetime;
     this.Visible     = ParticleToCopy.Visible;
     this.ElapsedTime = ParticleToCopy.ElapsedTime;                 // This also copies the Automatic variables' values automatically
 }
示例#14
0
        //===========================================================
        // Structures and Variables
        //===========================================================

        //===========================================================
        // Vertex Update and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to update the Vertex properties according to the Particle properties
        /// </summary>
        /// <param name="sVertexBuffer">The array containing the Vertices to be drawn</param>
        /// <param name="iIndex">The Index in the array where the Particle's Vertex info should be placed</param>
        /// <param name="Particle">The Particle to copy the information from</param>
        protected virtual void UpdateVertexProperties(ref DefaultTexturedQuadParticleVertex[] sVertexBuffer, int iIndex, DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultTexturedQuadParticle cParticle = (DefaultTexturedQuadParticle)Particle;

            // Calculate what half of the Quads Width and Height are
            float fHalfWidth  = cParticle.Width / 2.0f;
            float fHalfHeight = cParticle.Height / 2.0f;

            // Calculate the Positions of the Quads corners around the origin
            Vector3 sTopLeft     = new Vector3(-fHalfWidth, -fHalfHeight, 0);
            Vector3 sTopRight    = new Vector3(fHalfWidth, -fHalfHeight, 0);
            Vector3 sBottomLeft  = new Vector3(-fHalfWidth, fHalfHeight, 0);
            Vector3 sBottomRight = new Vector3(fHalfWidth, fHalfHeight, 0);

            // Rotate the Quad corners around the origin according to its Orientation,
            // then calculate their final Positions
            sTopLeft     = Vector3.Transform(sTopLeft, cParticle.Orientation) + cParticle.Position;
            sTopRight    = Vector3.Transform(sTopRight, cParticle.Orientation) + cParticle.Position;
            sBottomLeft  = Vector3.Transform(sBottomLeft, cParticle.Orientation) + cParticle.Position;
            sBottomRight = Vector3.Transform(sBottomRight, cParticle.Orientation) + cParticle.Position;

            // Effects expect a premultiplied color, so get the actual color to use.
            Color premultipliedColor = cParticle.ColorAsPremultiplied;

            // Copy this Particle's renderable Properties to the Vertex Buffer
            // This is a Quad so we must copy all 4 Vertices over
            sVertexBuffer[iIndex].Position          = sBottomLeft;
            sVertexBuffer[iIndex].TextureCoordinate = new Vector2(0, 1);
            sVertexBuffer[iIndex].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 1].Position          = sTopLeft;
            sVertexBuffer[iIndex + 1].TextureCoordinate = new Vector2(0, 0);
            sVertexBuffer[iIndex + 1].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 2].Position          = sBottomRight;
            sVertexBuffer[iIndex + 2].TextureCoordinate = new Vector2(1, 1);
            sVertexBuffer[iIndex + 2].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 3].Position          = sTopRight;
            sVertexBuffer[iIndex + 3].TextureCoordinate = new Vector2(1, 0);
            sVertexBuffer[iIndex + 3].Color             = premultipliedColor;

            // Fill in the Index Buffer for the newly added Vertices.
            // Specify the Vertices in Clockwise order.
            // It takes 6 Indices to represent a quad (2 triangles = 6 corners).
            // If we should be using the 32-bit Integer Index Buffer, fill it.
            if (this.IsUsingIntegerIndexBuffer)
            {
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
                IndexBuffer[IndexBufferIndex++] = iIndex;
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 3;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
            }
            // Else we should be using the 16-bit Short Index Buffer.
            else
            {
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 3);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 2);
            }
        }
示例#15
0
        //===========================================================
        // Initialization Functions
        //===========================================================

        /// <summary>
        /// Function to Initialize a Default Particle with the Initial Settings
        /// </summary>
        /// <param name="Particle">The Particle to be Initialized</param>
        public virtual void InitializeParticleUsingInitialProperties(DPSFParticle Particle)
        {
            InitializeParticleUsingInitialProperties(Particle, mcInitialProperties);
        }
示例#16
0
        /// <summary>
        /// Function to Initialize a Default Particle with the Initial Settings
        /// </summary>
        /// <param name="Particle">The Particle to be Initialized</param>
        /// <param name="cInitialProperties">The Initial Settings to use to Initialize the Particle</param>
        public void InitializeParticleUsingInitialProperties(DPSFParticle Particle, CInitialProperties cInitialProperties)
        {
            // Cast the Particle to the type it really is
            DPSFDefaultBaseParticle cParticle = (DPSFDefaultBaseParticle)Particle;

            // Initialize the Particle according to the values specified in the Initial Settings
            cParticle.Lifetime = DPSFHelper.RandomNumberBetween(cInitialProperties.LifetimeMin, cInitialProperties.LifetimeMax);

            // If the Position should be interpolated between the Min and Max Positions
            if (cInitialProperties.InterpolateBetweenMinAndMaxPosition)
            {
                cParticle.Position = Vector3.Lerp(cInitialProperties.PositionMin, cInitialProperties.PositionMax, RandomNumber.NextFloat());
            }
            // Else the Position XYZ values should each be calculated individually
            else
            {
                cParticle.Position = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.PositionMin, cInitialProperties.PositionMax);
            }

            // If the Particle's Velocity should be affected by the Emitters Orientation
            if (cInitialProperties.VelocityIsAffectedByEmittersOrientation)
            {
                // Rotate the Particle around the Emitter according to the Emitters orientation
                cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation);
            }

            // If the Particle should be affected by the Emitters Position
            if (cInitialProperties.PositionIsAffectedByEmittersPosition)
            {
                // Add the Emitter's Position to the Particle's Position
                cParticle.Position += Emitter.PositionData.Position;
            }

            // If the Velocity should be interpolated between the Min and Max Velocity
            if (cInitialProperties.InterpolateBetweenMinAndMaxVelocity)
            {
                cParticle.Velocity = Vector3.Lerp(cInitialProperties.VelocityMin, cInitialProperties.VelocityMax, RandomNumber.NextFloat());
            }
            // Else the Velocity XYZ values should each be calculated individually
            else
            {
                cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.VelocityMin, cInitialProperties.VelocityMax);
            }

            // Have the Emitters Rotation affect the Particle's starting Velocity
            cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);

            // If the Acceleration should be interpolated between the Min and Max Acceleration
            if (cInitialProperties.InterpolateBetweenMinAndMaxAcceleration)
            {
                cParticle.Acceleration = Vector3.Lerp(cInitialProperties.AccelerationMin, cInitialProperties.AccelerationMax, RandomNumber.NextFloat());
            }
            // Else the Acceleration XYZ values should each be calculated individually
            else
            {
                cParticle.Acceleration = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.AccelerationMin, cInitialProperties.AccelerationMax);
            }

            // If the External Force should be interpolated between the Min and Max External Force
            if (cInitialProperties.InterpolateBetweenMinAndMaxExternalForce)
            {
                cParticle.ExternalForce = Vector3.Lerp(cInitialProperties.ExternalForceMin, cInitialProperties.ExternalForceMax, RandomNumber.NextFloat());
            }
            // Else the External Force XYZ values should each be calculated individually
            else
            {
                cParticle.ExternalForce = DPSFHelper.RandomVectorBetweenTwoVectors(cInitialProperties.ExternalForceMin, cInitialProperties.ExternalForceMax);
            }

            // Calculate the amount of Friction to use
            cParticle.Friction = DPSFHelper.RandomNumberBetween(cInitialProperties.FrictionMin, cInitialProperties.FrictionMax);

            // If the new Color values should be somewhere between the interpolation of the Min and Max Colors
            if (cInitialProperties.InterpolateBetweenMinAndMaxColors)
            {
                cParticle.StartColor = DPSFHelper.LerpColor(cInitialProperties.StartColorMin, cInitialProperties.StartColorMax, RandomNumber.NextFloat());
                cParticle.EndColor   = DPSFHelper.LerpColor(cInitialProperties.EndColorMin, cInitialProperties.EndColorMax, RandomNumber.NextFloat());
            }
            // Else the RGBA Color values should each be randomly calculated individually
            else
            {
                cParticle.StartColor = DPSFHelper.LerpColor(cInitialProperties.StartColorMin, cInitialProperties.StartColorMax, RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat());
                cParticle.EndColor   = DPSFHelper.LerpColor(cInitialProperties.EndColorMin, cInitialProperties.EndColorMax, RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat());
            }
            cParticle.Color = cParticle.StartColor;
        }
示例#17
0
        //===========================================================
        // Vertex Update and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to update the Vertex properties according to the Particle properties
        /// </summary>
        /// <param name="sVertexBuffer">The array containing the Vertices to be drawn</param>
        /// <param name="iIndex">The Index in the array where the Particle's Vertex info should be placed</param>
        /// <param name="Particle">The Particle to copy the information from</param>
        protected override void UpdateVertexProperties(ref DefaultTexturedQuadParticleVertex[] sVertexBuffer, int iIndex, DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultTextureQuadTextureCoordinatesParticle cParticle = (DefaultTextureQuadTextureCoordinatesParticle)Particle;

            // Calculate what half of the Quads Width and Height are
            float fHalfWidth  = cParticle.Width / 2.0f;
            float fHalfHeight = cParticle.Height / 2.0f;

            // Calculate the Positions of the Quads corners around the origin
            Vector3 sTopLeft     = new Vector3(-fHalfWidth, fHalfHeight, 0);
            Vector3 sTopRight    = new Vector3(fHalfWidth, fHalfHeight, 0);;
            Vector3 sBottomLeft  = new Vector3(-fHalfWidth, -fHalfHeight, 0);;
            Vector3 sBottomRight = new Vector3(fHalfWidth, -fHalfHeight, 0);;

            // Rotate the Quad corners around the origin according to its Orientation,
            // then calculate their final Positions
            sTopLeft     = Vector3.Transform(sTopLeft, cParticle.Orientation) + cParticle.Position;
            sTopRight    = Vector3.Transform(sTopRight, cParticle.Orientation) + cParticle.Position;
            sBottomLeft  = Vector3.Transform(sBottomLeft, cParticle.Orientation) + cParticle.Position;
            sBottomRight = Vector3.Transform(sBottomRight, cParticle.Orientation) + cParticle.Position;

            // Copy this Particle's renderable Properties to the Vertex Buffer
            // This is a Quad so we must copy all 4 Vertices over
            sVertexBuffer[iIndex].Position          = sBottomLeft;
            sVertexBuffer[iIndex].TextureCoordinate = new Vector2(cParticle.NormalizedTextureCoordinateLeftTop.X, cParticle.NormalizedTextureCoordinateRightBottom.Y);
            sVertexBuffer[iIndex].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 1].Position          = sTopLeft;
            sVertexBuffer[iIndex + 1].TextureCoordinate = cParticle.NormalizedTextureCoordinateLeftTop;
            sVertexBuffer[iIndex + 1].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 2].Position          = sBottomRight;
            sVertexBuffer[iIndex + 2].TextureCoordinate = cParticle.NormalizedTextureCoordinateRightBottom;
            sVertexBuffer[iIndex + 2].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 3].Position          = sTopRight;
            sVertexBuffer[iIndex + 3].TextureCoordinate = new Vector2(cParticle.NormalizedTextureCoordinateRightBottom.X, cParticle.NormalizedTextureCoordinateLeftTop.Y);
            sVertexBuffer[iIndex + 3].Color             = cParticle.Color;

            // Fill in the Index Buffer for the newly added Vertices.
            // Specify the Vertices in Counter-Clockwise order.
            // It takes 6 Indices to represent a quad (2 triangles = 6 corners).
            // If we're using the HiDef profile, fill in the regular Index Buffer.
            if (this.GraphicsDevice.GraphicsProfile == GraphicsProfile.HiDef)
            {
                IndexBuffer[IndexBufferIndex++] = iIndex;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
                IndexBuffer[IndexBufferIndex++] = iIndex + 3;
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
            }
            // Else we're using the Reach profile, so fill the Reach Index Buffer instead.
            else
            {
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 3);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
            }
        }