Ejemplo n.º 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
            DefaultTextureQuadTextureCoordinatesParticle cParticleToCopy = (DefaultTextureQuadTextureCoordinatesParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.NormalizedTextureCoordinateLeftTop     = cParticleToCopy.NormalizedTextureCoordinateLeftTop;
            this.NormalizedTextureCoordinateRightBottom = cParticleToCopy.NormalizedTextureCoordinateRightBottom;
        }
Ejemplo n.º 2
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);
            }
        }