public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            var time    = particle.TimeAlive / particle.LifeSpan;
            var node_tr = GetAttachment(reference, transform);

            Vector3    deltap;
            Quaternion deltaq;

            if (DoTransform(reference, sparam, lasttime, globaltime, out deltap, out deltaq))
            {
                particle.Position    += deltap;
                particle.Orientation *= deltaq;
            }
            var p = Vector3.Transform(Vector3.Transform(particle.Position, particle.Orientation), node_tr);

            TextureHandler.Update(Texture, res);
            var c = Color.GetValue(sparam, time);
            var a = Alpha.GetValue(sparam, time);

            instance.Pool.DrawBasic(
                particle.Instance,
                this,
                TextureHandler,
                p,
                new Vector2(Size.GetValue(sparam, time)) * 2,
                new Color4(c, a),
                GetFrame(globaltime, sparam, ref particle),
                Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)),
                reference.Index
                );
        }
Example #2
0
        public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            var time    = particle.TimeAlive / particle.LifeSpan;
            var node_tr = GetAttachment(reference, transform);

            TextureHandler.Update(Texture, res);
            var c = Color.GetValue(sparam, time);
            var a = Alpha.GetValue(sparam, time);
            var q = particle.Orientation * Transform.GetDeltaRotation(sparam, lasttime, globaltime);

            particle.Orientation = q;
            var mat = Matrix4x4.CreateFromQuaternion(q);
            var p   = Vector3.Transform(particle.Position, transform);
            var p2  = Vector3.Transform(particle.Position + particle.Normal, transform);
            var n   = (p - p2).Normalized();

            instance.Pool.DrawPerspective(
                particle.Instance,
                this,
                TextureHandler,
                Vector3.Transform(particle.Position, transform),
                mat,
                new Vector2(Size.GetValue(sparam, time)),
                new Color4(c, a),
                GetFrame(globaltime, sparam, ref particle),
                n,
                Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)),
                reference.Index
                );

            if (DrawNormals)
            {
                Debug.DrawLine(p - (n * 100), p + (n * 100));
            }
        }
Example #3
0
        public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            var time    = particle.TimeAlive / particle.LifeSpan;
            var node_tr = GetAttachment(reference, transform);
            var src_pos = particle.Position;
            var l       = Length.GetValue(sparam, time);
            var w       = Width.GetValue(sparam, time);
            var sc      = Scale.GetValue(sparam, time);

            if (!CenterOnPos)
            {
                var nd = particle.Normal.Normalized();
                src_pos += nd * (l * sc * 0.25f);
            }
            var p = Vector3.Transform(src_pos, node_tr);

            TextureHandler.Update(Texture, res);
            var c  = Color.GetValue(sparam, time);
            var a  = Alpha.GetValue(sparam, time);
            var p2 = Vector3.Transform(src_pos + (particle.Normal * 20), node_tr);
            //var n = (p2 - p).Normalized();
            var n = Vector3.TransformNormal(particle.Normal, transform).Normalized();

            instance.Pool.DrawRect(
                particle.Instance,
                this,
                TextureHandler,
                p,
                new Vector2(l, w) * sc * 0.5f,
                new Color4(c, a),
                GetFrame(globaltime, sparam, ref particle),
                n,
                Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)),
                reference.Index
                );
            if (DrawNormals)
            {
                Debug.DrawLine(p - (n * 12), p + (n * 12));
            }
        }
Example #4
0
        public void DrawBeamApp(PolylineRender poly, float globalTime, NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            //get particles!
            var beam = instance.Beams[reference.BeamIndex];
            if (beam.ParticleCount < 2) { beam.ParticleCount = 0;  return; }
            AgeComparer.Instance.Particles = instance.Pool.Particles;
            Array.Sort(beam.ParticleIndices, 0, beam.ParticleCount, AgeComparer.Instance);
            //draw
            var node_tr = GetAttachment(reference, transform);
            Texture2D tex;
            Vector2 tl, tr, bl, br;
            var res = instance.Resources;
            TextureHandler.Update(Texture, res);
            var frame = GetFrame(globalTime, sparam, ref instance.Pool.Particles[beam.ParticleIndices[0]]);
            int index = (int) Math.Floor((TextureHandler.FrameCount - 1) * frame) * 4;
            tl = TextureHandler.Coordinates[index];
            tr = TextureHandler.Coordinates[index + 1];
            bl = TextureHandler.Coordinates[index + 2];
            br = TextureHandler.Coordinates[index + 3];
            //Sorting hack kinda
            var z = RenderHelpers.GetZ(instance.Pool.Camera.Position, Vector3.Transform(Vector3.Zero, node_tr));
            for (int j = 0; j < 2; j++) //two planes
            {
                poly.StartLine(TextureHandler.Texture ?? res.WhiteTexture, BlendInfo);
                bool odd = true;
                Vector3 dir = Vector3.Zero;

                for (int i = 0; i < beam.ParticleCount; i++)
                {
                    var pos = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i]].Position, node_tr);
                    if (i + 1 < beam.ParticleCount) {
                        var pos2 = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i + 1]].Position, node_tr);
                        var forward = (pos2 - pos).Normalized();
                        var toCamera = (instance.Pool.Camera.Position - pos).Normalized();
                        var up = Vector3.Cross(toCamera, forward);
                        up.Normalize();
                        dir = up;
                        if (j == 1)
                        {
                            //Broken? Doesn't show up
                            var right = Vector3.Cross(up, forward).Normalized();
                            dir = right;
                        }
                    }
                    var time = instance.Pool.Particles[beam.ParticleIndices[i]].TimeAlive / instance.Pool.Particles[beam.ParticleIndices[i]].LifeSpan;
                    var w = Width.GetValue(sparam, time);
                    poly.AddPoint(
                        pos + (dir * w / 2),
                        pos - (dir * w / 2),
                        odd ? tl : bl,
                        odd ? tr : br,
                        new Color4(
                            Color.GetValue(sparam, time),
                            Alpha.GetValue(sparam, time)
                        )
                    );
                    odd = !odd;
                }
                poly.FinishLine(z);
            }
            beam.ParticleCount = 0;
        }