Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

(SOLVED) Making a waypoint line between nodes

$
0
0

@oblivion165 wrote:

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

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles