Game Development Community

Motion trails?

by Alex Chouls · in Torque X 2D · 06/07/2007 (8:20 pm) · 1 replies

I'm trying to make glowing trails similar to those in Homeworld and fighting games. The objects are moving fast, so the particle trail method doesn't work.

Is there a way to build an arbitrary textured polygon shape in TorqueX? e.g. a ribbon of polygons built behind a moving sceneobject.

I've looked into T2dPolygon but that seems to be a wireframe polygon.
I've also looked at T2dQuad but can't figure out how to use it.

Is it possible to combine the underlying XNA functionality in a TorqueX render pass?

#1
06/12/2007 (9:01 pm)
You probably want to use a full triangle strip rather than a quad if you're going for a ribbon effect. You'll have to create your own object derived from T2DSceneObject. To get it to work you'll need to override the Render method. In the render method you'll need to create a RenderInstance object and add it to the render manager. The render instance holds stuff like the vertex buffer, index buffer, material, etc. Info about how triangle strips work and how to create and use them can be found all over the place on the internet, so I won't go into that.

It might be a bit tricky if you don't have source, so here's an example from T2DQuad.Render:
// Note: 'srs' is the SceneRenderState object passed to Render
            srs.World.Push();
            srs.World.MultiplyMatrixLocal(objToWorld);

            RenderInstance ri = SceneRenderer.RenderManager.AllocateInstance();
            ri.RotationOnly = rotation;

            // fils the render instance with relevant data (see below)
            FillRenderInstance(ri, srs);

            BaseSceneGraph.Instance.GetLightManager().GetBestLights(ri.Lights);

            SceneRenderer.RenderManager.AddInstance(ri);
            srs.World.Pop();

For great justice, here's the T2DQuad.FillRenderInstance method:
public void FillRenderInstance(RenderInstance ri, SceneRenderState srs)
        {
            GraphicsDevice d3d = srs.Gfx.Device;
            Assert.Fatal(d3d != null, "doh");

            ri.Type = RenderInstance.RenderInstanceType.Mesh2D;
            ri.SceneObject = srs.CurrentSceneObject;

            ri.ProjectionTransform = srs.Projection;
            ri.ObjectTransform = srs.World.Top;

            ri.PrimitiveType = PrimitiveType.TriangleFan;
            ri.VertexDeclaration = GFXVertexFormat.GetVertexDeclaration(srs.Gfx.Device);

            ri.VertexBuffer = _vb.Buffer as VertexBuffer;
            ri.BaseVertex = _vb.StartIndex;
            ri.NumVerts = _vb.Count;
            ri.VertexSize = _vb.ElementSize;

            ri.PrimitiveCount = 2;

            ri.TexU = _texU;
            ri.TexV = _texV;

            ri.Material = _material;
        }