Example #1
0
        public void End()
        {
            if (!has_begun)
            {
                throw new InvalidOperationException("Begin must be called before End can be called.");
            }

            if (primitivebatch == null || material == null)
            {
                Warm(device);
            }

            material.Parameters["TextureEnabled"].SetValue(true);
            material.Parameters["World"].SetValue(Matrix.Identity);
            material.Parameters["View"].SetValue(camera.view);
            material.Parameters["Projection"].SetValue(camera.projection);

            foreach (Texture2D texture in particles.Keys)
            {
                List <ParticleInfo> list = particles[texture];

                if (list.Count <= 0)
                {
                    continue;
                }

                material.Parameters["Texture"].SetValue(texture);
                material.CurrentTechnique.Passes[0].Apply();

                primitivebatch.Begin(Primitive.Quad);
                float texture_pixel_width  = 1.0f / texture.Width;
                float texture_pixel_height = 1.0f / texture.Height;

                for (int i = 0; i < list.Count; i++)
                {
                    ParticleInfo  particle = list[i];
                    TextureRegion region   = particle.region;

                    primitivebatch.SetTransform(ref particle.transform);
                    primitivebatch.SetColor(particle.color);
                    primitivebatch.SetTextureCoords(region.u * texture_pixel_width, region.v * texture_pixel_height);

                    primitivebatch.AddVertex(-0.5f, 0.5f, 0, 0, 0);
                    primitivebatch.AddVertex(-0.5f, -0.5f, 0, 0, region.height * texture_pixel_height);
                    primitivebatch.AddVertex(0.5f, -0.5f, 0, region.width * texture_pixel_width, region.height * texture_pixel_height);
                    primitivebatch.AddVertex(0.5f, 0.5f, 0, region.width * texture_pixel_width, 0);
                }

                primitivebatch.End();

                list.Clear();
            }

            has_begun = false;
        }
Example #2
0
        public void Add(Particle particle)
        {
            TextureRegion region       = particle.region;
            ParticleInfo  particleinfo = new ParticleInfo(region, particle.color, ref particle.world);

            if (!particles.ContainsKey(region.texture))
            {
                particles[region.texture] = new List <ParticleInfo>();
            }
            particles[region.texture].Add(particleinfo);
        }
Example #3
0
        public void Add(Particle particle)
        {
            TextureRegion region = particle.region;
            ParticleInfo particleinfo = new ParticleInfo(region, particle.color, ref particle.world);

            if (!particles.ContainsKey(region.texture))
                particles[region.texture] = new List<ParticleInfo>();
            particles[region.texture].Add(particleinfo);
        }