Jump to content

  • Log In with Google      Sign In   
  • Create Account

Drawing a 3D Line in DirectX


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 AberAber   Members   -  Reputation: 122

Like
0Likes
Like

Posted 16 January 2007 - 03:04 PM

Are there any built-in or good snippets of code for drawing a 3d line in DirectX? I want to draw a line in space, for example (1, 2, 3) to (10, 30, 4). There was a built-in 3d line function I saw, but it seemed to always just display on the screen and not actually be in the world. Code snippets would be appreciated, thanks!

#2 Endurion   Crossbones+   -  Reputation: 4892

Like
0Likes
Like

Posted 16 January 2007 - 06:24 PM

You can simply use D3DPT_LINELIST or D3DPT_LINESTRIP with DrawPrimitive and provide the vertices in the buffer.

Note that the line is affected by lighting and texture as well.

#3 AberAber   Members   -  Reputation: 122

Like
0Likes
Like

Posted 16 January 2007 - 07:11 PM

Sorry can you explain it a little farther please.

According to msdn:
D3DPT_LINELIST
Renders the vertices as a list of isolated straight line segments.
D3DPT_LINESTRIP
Renders the vertices as a single polyline.

Is it like wireframe mode then? Does it have to be triangles or are they not triangles?

#4 Endurion   Crossbones+   -  Reputation: 4892

Like
0Likes
Like

Posted 16 January 2007 - 08:29 PM

For rendering triangles as triangle list you provide the three vertices of each face in the buffer.

For rendering lines as line list you just provide the two end points of a line inside the buffer. With a line strip the previous second vertex will be used as the first vertex of the next line.


If you want a wireframe rendering of a "normal" model consisting of triangles you could use the renderstate D3DRS_FILLMODE with D3DFILL_WIREFRAME.

#5 AberAber   Members   -  Reputation: 122

Like
0Likes
Like

Posted 17 January 2007 - 09:32 AM

Is there any way to add 3d thickness to these lines?

#6 Snuggles   Members   -  Reputation: 122

Like
0Likes
Like

Posted 17 January 2007 - 03:11 PM

Here's how you do it in c# with MDX:

Vector3[] startToEnd;
/*Fill out the points of the line in startToEnd*/
System.Drawing.Color color = Color.Red;
Line line = new Line(D3DDevice);
line.Antialias = true;
line.Width = 3.0f;
this.line.DrawTransform(startToEnd,D3DDevice.Transform.World*D3DDevice.Transform.View*D3DDevice.Transform.Projection,
color);

#7 AberAber   Members   -  Reputation: 122

Like
0Likes
Like

Posted 17 January 2007 - 06:02 PM

Great. Got it working!

D3DXVECTOR3 vertexList[2];
vertexList[0].x = 778;
vertexList[0].y = -55;
vertexList[0].z = -619;
vertexList[1].x = 507;
vertexList[1].y = -55;
vertexList[1].z = -619;

// Draw the line.
LPD3DXLINE _line;
D3DXCreateLine(g_pd3dDevice, &_line);
D3DXMATRIX tempFinal = TheCamera.m_matView * matProj;
_line->SetWidth(10.0f);
_line->Begin();
_line->DrawTransform(vertexList, 2, &tempFinal, 0xff408010);
_line->End();

[Edited by - AberAber on January 18, 2007 1:02:12 AM]




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS