/// <summary>
        /// Set the current settings to the particle system attached
        /// </summary>
        private void LoadParticleSystem()
        {
            this.random = WaveServices.Random;

            if (this.mesh != null)
            {
                if (this.mesh.IndexBuffer != null)
                {
                    this.GraphicsDevice.DestroyIndexBuffer(this.mesh.IndexBuffer);
                }

                if (this.mesh.VertexBuffer != null)
                {
                    this.GraphicsDevice.DestroyVertexBuffer(this.mesh.VertexBuffer);
                }

                this.mesh = null;
            }

            this.settings = this.System;
            this.numParticles = this.System.NumParticles;
            this.numPrimitives = this.numParticles * 2;
            this.numVertices = this.numParticles * 4;
            this.numIndices = this.numParticles * 6;
            this.particles = new Particle[this.numParticles];

            // Create Indexbuffer
            ushort[] indices = new ushort[this.numIndices];

            for (int i = 0; i < this.numParticles; i++)
            {
                indices[(i * 6) + 0] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 1);

                indices[(i * 6) + 3] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 4] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            IndexBuffer indexBuffer = new IndexBuffer(indices);

            // Initialize Particles
            for (int i = 0; i < this.numParticles; i++)
            {
                double life = (this.settings.EmitRate > 0) ? -1 : TimeSpan.FromSeconds(this.random.NextDouble() * (this.numParticles * InitTimeMultipler)).TotalSeconds;

                this.particles[i] = new Particle()
                {
                    Alive = true,
                    Life = life
                };
            }

            this.vertices = new VertexPositionNormalColorTexture[this.numVertices];
            DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionNormalColorTexture.VertexFormat);
            vertexBuffer.SetData(this.vertices, this.numVertices);

            this.mesh = new Mesh(0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleList)
            {
                DisableBatch = true
            };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set the current settings to the particle system attached
        /// </summary>
        private void LoadParticleSystem()
        {
            this.random = WaveServices.Random;

            if (this.indexBuffer != null)
            {
                this.GraphicsDevice.DestroyIndexBuffer(this.indexBuffer);
            }

            if (this.vertexBuffer != null)
            {
                this.GraphicsDevice.DestroyVertexBuffer(this.vertexBuffer);
            }

            this.settings = this.System;
            this.numParticles = this.System.NumParticles;
            this.numPrimitives = this.numParticles * 2;
            this.numVertices = this.numParticles * 4;
            this.numIndices = this.numParticles * 6;
            this.particles = new Particle[this.numParticles];

            // Create Indexbuffer
            ushort[] indices = new ushort[this.numIndices];

            for (int i = 0; i < this.numParticles; i++)
            {
                indices[(i * 6) + 0] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 1);

                indices[(i * 6) + 3] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 4] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            this.indexBuffer = new IndexBuffer(indices);
            this.GraphicsDevice.BindIndexBuffer(this.indexBuffer);

            // Initialize Particles
            for (int i = 0; i < this.numParticles; i++)
            {
                this.particles[i] = new Particle()
                {
                    Alive = true,
                    Life = TimeSpan.FromMilliseconds(this.random.NextDouble() * (this.numParticles * InitTimeMultipler)).TotalMilliseconds
                };
            }

            this.vertices = new VertexPositionColorTexture[this.numVertices];
            this.vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat);
            this.vertexBuffer.SetData(this.vertices, this.numVertices);
            this.GraphicsDevice.BindVertexBuffer(this.vertexBuffer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the current settings to the particle system attached
        /// </summary>
        private void LoadParticleSystem()
        {
            this.random = WaveServices.Random;

            if (this.indexBuffer != null)
            {
                this.GraphicsDevice.DestroyIndexBuffer(this.indexBuffer);
            }

            if (this.vertexBuffer != null)
            {
                this.GraphicsDevice.DestroyVertexBuffer(this.vertexBuffer);
            }

            this.settings = this.System;
            this.numParticles = this.System.NumParticles;
            this.numPrimitives = this.numParticles * 2;
            this.numVertices = this.numParticles * 4;
            this.numIndices = this.numParticles * 6;
            this.particles = new Particle[this.numParticles];

            // Sets the time passed between 2 particles creation.
            this.emitLapse = (this.settings.EmitRate > 0) ? 1000 / this.settings.EmitRate : 0;

            // Create Indexbuffer
            ushort[] indices = new ushort[this.numIndices];

            for (int i = 0; i < this.numParticles; i++)
            {
                indices[(i * 6) + 0] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 1);

                indices[(i * 6) + 3] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 4] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            this.indexBuffer = new IndexBuffer(indices);
            this.GraphicsDevice.BindIndexBuffer(this.indexBuffer);

            // Initialize Particles
            for (int i = 0; i < this.numParticles; i++)
            {
                double life = (this.settings.EmitRate > 0) ? -1 : TimeSpan.FromMilliseconds(this.random.NextDouble() * (this.numParticles * InitTimeMultipler)).TotalMilliseconds;

                this.particles[i] = new Particle()
                {
                    Alive = true,
                    Life = life
                };
            }

            this.vertices = new VertexPositionColorTexture[this.numVertices];

            // Initializes the coordinate textures of the vertices
            for (int i = 0; i < this.numVertices; i++)
            {
                this.vertices[i++].TexCoord = TEXCOORD1;
                this.vertices[i++].TexCoord = TEXCOORD2;
                this.vertices[i++].TexCoord = TEXCOORD3;
                this.vertices[i].TexCoord = TEXCOORD4;
            }

            this.vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat);
            this.vertexBuffer.SetData(this.vertices, this.numVertices);
            this.GraphicsDevice.BindVertexBuffer(this.vertexBuffer);
        }