(SOLVED) Making a waypoint line between nodes

Hello,

I am having trouble making the 3D lines between two waypoints. Here is an example picture from C&C Renegade

(It was the only picture I could find of these waypaths, the red arrows were already on it)

You see the blue triangles with the green lines between them? I am trying to make the green lines. I started with a tiny small box model made in 3dsMax and I am trying to figure out the matrix math to stretch it from one node to another.

My current method is to use a Matrix.Create_Scale(Distance, 1,1); to set the length and then rotate the matrix on the Y axis to spin it in to position BUT that doesn’t work if one node is higher than the others. I am thinking there is a better way to do this.

Here is my current code:

       Vector3 Offset = new Vector3(0.5f,.1f,0.5f);
        for (int i = 0; i < Node.Length; i++)
        {

            for (int t = 0; t < Node[i].Neighbors.Length;t++)
            {
                var Position = Node[i].Position;
                var nPosition = Node[i].Neighbors[t].Position;

                float Size = Node_Beam_Model.Meshes[0].BoundingSphere.Radius;


                var direction = Position - nPosition;
                var distance = Position.Distance(nPosition) + (1-Size);

                

                Matrix World = Matrix.Identity;
                float Half = Node_Beam_Model.Meshes[0].BoundingSphere.Radius / 2;
            
                float Angle = genlib.Angle(Node[i].Position, Node[i].Neighbors[t].Position);
                float amount = distance / Size;

                World *= Matrix.CreateTranslation(-new Vector3(-Half, 0, Half));

                World *= Matrix.CreateScale(new Vector3(amount, 1, 1));
                World *= Matrix.CreateRotationY(MathHelper.ToRadians(Angle * -1 + 90));
 
                World *= Matrix.CreateTranslation(Node[i].Position + Offset);
                
                Do(Node_Beam_Model, Camera, Color.White, World);
            }
        }

This does get the result I want as long as everything is flat obviously it would be with any elevation change

Here’s an easy method that’s also very fast:

Vector3 forward = posNext - pos;
Vector3 right = Vector3.Normalize(Vector3.Cross(forward, Vector.Up));
Vector3 up = Vector3.Normalize(Vector3.Cross(right, forward));

Matrix world = Matrix.Identity;
world.Translation = pos + forward / 2;
world.Forward = forward;
world.Right = right * lineWidth;
world.Up = up * lineWidth;

The length of the box has to be 1 and the pivot (center point) needs to be at the center, otherwise you have to make adjustments.

Yes! Perfect! Thank you so much!

Just for anyone wondering (and google searches) this is the exact code that it took to make it work in my scenario

                var Position = Node[i].Position;
                var nPosition = Node[i].Neighbors[t].Position;

                float Size = Node_Beam_Model.Meshes[0].BoundingSphere.Radius;

                var direction = Position - nPosition;
                var distance = Position.Distance(nPosition);

                float amount = (float)Math.Ceiling(distance / Size);
                Vector3 forward = nPosition - Position;
                Vector3 right = Vector3.Normalize(Vector3.Cross(forward, Vector3.Up));
                Vector3 up = Vector3.Cross(right, forward);
                forward.Normalize();

                Matrix world = Matrix.Identity;
                world.Translation = Position + new Vector3(0.5f, 0, 0.5f) + forward / 2;
                world.Forward = -forward * amount;
                world.Right = right * .6f;
                world.Up = up * .1f;

Ooops, I forgot to normalize the up vector, I just corrected my previous post. If you do that, you don’t need different scaling values for world.Right and world.Up.