Ejemplo n.º 1
0
        public void Render(GraphicsDeviceManager graphics, Matrix cameraViewMatrix, Matrix cameraProjectionMatrix, ParticleSystem system, Entity camera)
        {
            // TODO: Fix.

            Vector3 ps = new Vector3(pos.X, pos.Y, pos.Z);
            if (relativePosition)
            {
                ps += system.position;
            }

            Matrix billboardMatrix = Matrix.CreateBillboard(pos, camera.position, camera.getUpVector(), camera.getForwardVector());

            if (quad == null)
            {
            }
            quad = new Quad(ps, Vector3.Backward, Vector3.Up, size, size);
            quadVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

            foreach (VertexPositionNormalTexture v in quad.Vertices)
            {
                Vector3.Transform(v.Position, billboardMatrix);
            }

            graphics.GraphicsDevice.VertexDeclaration = quadVertexDeclaration;
            graphics.GraphicsDevice.DrawUserIndexedPrimitives
                <VertexPositionNormalTexture>(
                PrimitiveType.TriangleList,
                quad.Vertices, 0, 4,
                quad.Indexes, 0, 2);
        }
Ejemplo n.º 2
0
        public void Update(float t, ParticleSystem system)
        {
            vel += acc * t;
            pos += vel * t;
            angle += rot * t;
            age += t;

            float progress = age / maxAge;

            color = Color.Lerp(startColor, endColor, progress);

            // Kill if too old
            if (age >= maxAge) dying = true;

            // Kill if too far
            float distance2 = relativePosition ? pos.LengthSquared() : (system.position - pos).LengthSquared();
            if (distance2 > (maxDistance * maxDistance)) dying = true;

            alpha = normalAlpha;
            if (dying && dyingTime > 0)
            {
                dyingAge += t;
                alpha = MathHelper.Lerp(normalAlpha, 0, dyingAge/dyingTime);
            }

            if (dying && dyingAge > dyingTime) dead = true;
        }
Ejemplo n.º 3
0
        public Particle CreateParticle(GameTime time, float t, ParticleSystem particleSystem)
        {
            Random r = new Random();

            Particle p = new Particle();
            p.sprite = sprites[r.Next(sprites.Count)];
            p.pos = new Vector3(randomFloat(r, particleSpread), randomFloat(r, particleSpread), randomFloat(r, particleSpread));
            p.maxAge = particleLifeTime;
            p.maxDistance = particleSpread;
            p.angle = randomFloat(r, 180);
            p.normalAlpha = alpha;
            p.rot = rot;
            p.relativePosition = relativePosition;

            if (!relativePosition)
            {
                p.pos += particleSystem.position;
            }

            return p;
        }