# Connecting 2 "World" Points with D3DXLine

This topic is 2649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi

Im conneting 2 points in my 3D world using D3DXLine and D3DXVec3Project.

So what I do is, I project the 2 points from their world space to screen space using D3DXVec3Project and then I take those two points and give it to ID3DXLine::Draw( CONST D3DXVECTOR2* pVertexList, DWORD dwVertexListCount, D3DCOLOR Color ) to be drawn.

Now this works beautifully when both the points are in view and infront of the camera. But once the camera moves past a point and the point is now behind the camera, then the line jumps to an incorrect position.

Does anyone have any pointers? Obviously its projecting the "offscreen" point incorrectly, but Im not quiet sure how I would go about fixing it.

G

##### Share on other sites
It seems that D3DXLine is meant for drawing 2d lines.

As you have noted, you may do the transformations by yourself to present a 3d line with it. However, you are missing one phase which is clipping.

Check the link Here about the normal transformation pipeline. Practically you should transform your 3d line to 4d homogenous (clip) space and perform clipping there and then division by the w component. I won't go in to the details here since there is easier way to do it.

Is there any reason not to just draw a 3d line with DrawPrimitiveUP and correct transformations?

Cheers!

##### Share on other sites

Is there any reason not to just draw a 3d line with DrawPrimitiveUP and correct transformations?

Cheers!

Thanks Kauna,

I haven't thought about using DrawPrimitiveUP. I gonna try it.

How would one specify the "CONST void* pVertexStreamZeroData" as parameter of the function. I have never used it before, so I'm not sure how present that VertexStreamZeroData to the funciton parameter.

G

##### Share on other sites

[quote name='kauna' timestamp='1299592722' post='4783108']
Is there any reason not to just draw a 3d line with DrawPrimitiveUP and correct transformations?

Cheers!

Thanks Kauna,

I haven't thought about using DrawPrimitiveUP. I gonna try it.

How would one specify the "CONST void* pVertexStreamZeroData" as parameter of the function. I have never used it before, so I'm not sure how present that VertexStreamZeroData to the funciton parameter.

G
[/quote]

HRESULT DrawPrimitiveUP( [in] D3DPRIMITIVETYPE PrimitiveType, [in] UINT PrimitiveCount, [in] const void *pVertexStreamZeroData, [in] UINT VertexStreamZeroStride); 
[font="arial, verdana, tahoma, sans-serif"]
[/font]
 struct MyVertex { float x,y,z; } MyVertex Line[2]; Line[0].x = ... Line[1].x = ... DrawPrimitiveUP(D3DPT_LINE_STRIP,2,(void *)Line,sizeof(MyVertex)); 

pVertexStreamZeroData is the pointer to the vertex data. So the code goes something like as above. Please check for the primitive type since I wrote that from my memory. Also you'll need to set SetFVF or SetVertexDeclaration (or so) and the correct SetTransforms etc etc.

Cheers!

##### Share on other sites
Great stuff! thanks alot. I'll have a go with it.

##### Share on other sites
What is the difference between the LineList and LineStrip, since I'm getting different results but not sure why.

##### Share on other sites
 struct MyVertex { float x,y,z; } MyVertex Line[2]; Line[0].x = ... Line[1].x = ... DrawPrimitiveUP(D3DPT_LINE_STRIP,2,(void *)Line,sizeof(MyVertex)); 

pVertexStreamZeroData is the pointer to the vertex data. So the code goes something like as above. Please check for the primitive type since I wrote that from my memory. Also you'll need to set SetFVF or SetVertexDeclaration (or so) and the correct SetTransforms etc etc.

Cheers!
[/quote]

Shouldn't PrimitiveCount be 1 since I want only 1 line betweet 2 points?

##### Share on other sites
Cool it worked (after setting the primitive count to 1).

Thanks for the help.

Can you tell me if I can set the width of the line being drawn?

##### Share on other sites

Cool it worked (after setting the primitive count to 1).

Thanks for the help.

Can you tell me if I can set the width of the line being drawn?

Perhaps you were correct to use the D3DXLine version in the beginning. Check the link Here about DrawTransform method. I haven't used it so I don't know exactly how it works or if it understands the line widths etc etc.

Good luck!

##### Share on other sites

What is the difference between the LineList and LineStrip, since I'm getting different results but not sure why.

Line strip: http://msdn.microsoft.com/en-us/library/aa911032.aspx
Line list: http://msdn.microsoft.com/en-us/library/ee491437.aspx

Notice the expamples on the pages - the vertices are the same in both cases so you can see how the results differ.

Simply said - in line strip, the first and second vertex are connected with a line, then any following vertex is connected with the previous. The result is a single polyline, with the number of straight line segments equal to number of vertices minus one.
In line list, each pair of vertices describes a line segment. The resulting number of line segments is equal to the number of vertices divided by 2. Of course you can achieve the same looking polyline as with linestrip, but you would need more vertices - and most of them would be duplicates.

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631352
• Total Posts
2999484
×