Exemplo n.º 1
0
        //===========================================================
        // Vertex Update 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="cParticle">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
            Sprite3DBillboardParticleSystemTemplateParticle particle = (Sprite3DBillboardParticleSystemTemplateParticle)Particle;

            //-----------------------------------------------------------
            // TODO: Put the Particle's properties into the required format for the
            // SpriteBatch's Draw() function, and add any more parameters to the Draw()
            // function that you like.
            //-----------------------------------------------------------

            // 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 = new Rectangle(0, 0, Texture.Width, Texture.Height);

            // 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, Color.White, 0, origin, scale, SpriteEffects.None, viewSpacePosition.Z);
        }
        public void InitializeParticleGrid(DPSFParticle Particle)
        {
            SpriteParticle cParticle = (SpriteParticle)Particle;

            int iLineWidth = 1;

            cParticle.Lifetime           = 0;
            cParticle.Color              = Color.Green;
            cParticle.RotationalVelocity = MathHelper.PiOver4;

            // If this should be a Horizontal Line
            if (NumberOfActiveParticles < miRows)
            {
                cParticle.Width  = miScreenWidth;
                cParticle.Height = iLineWidth;

                float fSpaceBetweenLines = miScreenHeight / miRows;

                float fX = miScreenWidth / 2;
                float fY = (fSpaceBetweenLines / 2) + (NumberOfActiveParticles * fSpaceBetweenLines) - (iLineWidth / 2);
                cParticle.Position = new Vector3(fX, fY, 0);
            }
            // Else it should be a Vertical Line
            else
            {
                cParticle.Width  = iLineWidth;
                cParticle.Height = miScreenHeight;

                float fSpaceBetweenLines = miScreenWidth / miColumns;

                float fX = (fSpaceBetweenLines / 2) + ((NumberOfActiveParticles - miRows) * fSpaceBetweenLines) - (iLineWidth / 2);
                float fY = miScreenHeight / 2;
                cParticle.Position = new Vector3(fX, fY, 0);
            }
        }
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            SpriteParticle cParticleToCopy = (SpriteParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            sPivotPoint = cParticleToCopy.sPivotPoint;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deep copy the ParticleToCopy's values into this Particle
        /// </summary>
        /// <param name="ParticleToCopy">The Particle whose values should be Copied</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle from its base type to its actual type
            EngineSpriteParticle cParticleToCopy = (EngineSpriteParticle)ParticleToCopy;
            base.CopyFrom(cParticleToCopy);

            //-----------------------------------------------------------
            // TODO: Copy your Particle properties from the given Particle here
            //-----------------------------------------------------------
            particleType = cParticleToCopy.particleType;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Deep copy the ParticleToCopy's values into this Particle
        /// </summary>
        /// <param name="ParticleToCopy">The Particle whose values should be Copied</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle from its base type to its actual type
            EngineSpriteParticle cParticleToCopy = (EngineSpriteParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);

            //-----------------------------------------------------------
            // TODO: Copy your Particle properties from the given Particle here
            //-----------------------------------------------------------
            particleType = cParticleToCopy.particleType;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deep copy the ParticleToCopy's values into this Particle
        /// </summary>
        /// <param name="ParticleToCopy">The Particle whose values should be Copied</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle from its base type to its actual type
            SpriteParticleSystemTemplateParticle cParticleToCopy = (SpriteParticleSystemTemplateParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);

            //-----------------------------------------------------------
            // TODO: Copy your Particle properties from the given Particle here
            //-----------------------------------------------------------
            Position = cParticleToCopy.Position;
            Velocity = cParticleToCopy.Velocity;
            Width    = cParticleToCopy.Width;
            Height   = cParticleToCopy.Height;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deep copy the ParticleToCopy's values into this Particle
        /// </summary>
        /// <param name="ParticleToCopy">The Particle whose values should be Copied</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle from its base type to its actual type
            BeatIndicatorParticleSystemParticle cParticleToCopy = (BeatIndicatorParticleSystemParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);

            //-----------------------------------------------------------
            // TODO: Copy your Particle properties from the given Particle here
            //-----------------------------------------------------------
            Position    = cParticleToCopy.Position;
            Velocity    = cParticleToCopy.Velocity;
            Orientation = cParticleToCopy.Orientation;
            Width       = cParticleToCopy.Width;
            Height      = cParticleToCopy.Height;
            Color       = cParticleToCopy.Color;
        }
Exemplo n.º 8
0
        //===========================================================
        // Vertex Update 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="cParticle">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
            SpriteParticleSystemTemplateParticle cParticle = (SpriteParticleSystemTemplateParticle)Particle;

            //-----------------------------------------------------------
            // TODO: Put the Particle's properties into the required format for the
            // SpriteBatch's Draw() function, and add any more parameters to the Draw()
            // function that you like.
            //-----------------------------------------------------------

            // 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);

            // Draw the Sprite
            cSpriteBatch.Draw(Texture, sDestination, Color.White);
        }
        public void InitializeParticleRotators(DPSFParticle Particle)
        {
            SpriteParticle cParticle = (SpriteParticle)Particle;

            cParticle.Lifetime = 0;
            cParticle.Color    = DPSFHelper.RandomColor();
            cParticle.Width    = cParticle.Height = 30;

            int iWidthBetweenParticles  = miScreenWidth / miColumns;
            int iHeightBetweenParticles = miScreenHeight / miRows;
            int iRow    = NumberOfActiveParticles / miColumns;
            int iColumn = NumberOfActiveParticles % miColumns;

            float fX = (iWidthBetweenParticles / 4) + (iColumn * iWidthBetweenParticles) - (cParticle.Width / 2);
            float fY = (iHeightBetweenParticles / 4) + (iRow * iHeightBetweenParticles) - (cParticle.Height / 2);

            cParticle.Position = new Vector3(fX, fY, 0);

            cParticle.sPivotPoint        = new Vector2(fX + (iWidthBetweenParticles / 4), fY + (iHeightBetweenParticles / 4));
            cParticle.RotationalVelocity = RandomNumber.Between(-MathHelper.TwoPi, MathHelper.TwoPi);
        }
        public void InitializeParticleAttraction(DPSFParticle Particle)
        {
            SpriteParticle cParticle = (SpriteParticle)Particle;

            cParticle.Lifetime      = 0;
            cParticle.Width         = cParticle.Height = 50;
            cParticle.Position      = new Vector3(RandomNumber.Next(-miScreenWidth / 2, miScreenWidth / 2), RandomNumber.Next(-miScreenHeight / 2, miScreenHeight / 2), 0);
            cParticle.Color         = DPSFHelper.RandomColor();
            cParticle.ExternalForce = new Vector3(0, mfGravity, 0);
            cParticle.Friction      = mfGravity;

            // If this is the Attractor Particle (i.e. the first Particle added)
            if (NumberOfActiveParticles == 0)
            {
                // Make the Attractor Particle larger than the rest
                cParticle.Width = cParticle.Height = 150;

                // Place the Attractor in the middle of the screen
                cParticle.Position = new Vector3(miScreenWidth / 2, miScreenHeight / 2, 0);

                // Make the Attractor White
                cParticle.Color = Color.White;
            }
        }
Exemplo n.º 11
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 virtual void UpdateVertexProperties(ref BeatIndicatorParticleSystemParticleVertex[] sVertexBuffer, int iIndex, DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            BeatIndicatorParticleSystemParticle cParticle = (BeatIndicatorParticleSystemParticle)Particle;

            //-----------------------------------------------------------
            // TODO: Copy the Particle's renderable properties to the Vertex Buffer.
            // NOTE: Because a Quad is made up of 4 Vertices, we must populate
            // each of the 4 Vertices data in the Vertex Buffer, as well as
            // specify the Vertex order in the Index Buffer.
            //-----------------------------------------------------------
            // 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 to make it face the Camera,
            // 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(0, 1);
            sVertexBuffer[iIndex].Color             = cParticle.Color;

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

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

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

            // 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're using the HiDef profile, fill in the regular Index Buffer.
            if (this.GraphicsDevice.GraphicsProfile == GraphicsProfile.HiDef)
            {
                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're using the Reach profile, so fill the Reach Index Buffer instead.
            else
            {
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 3);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
            }
        }