# draw a connecting line in 3d space?

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

## Recommended Posts

Hi there,

I can't seem to find any info on how to obtain a line in space made from a number of vertices. The line would need to be drawn from the moving character to a moving point in space (which represents the crosshair), so it'd be sort of like a ray but it'd need to be made of a number of vertices since i'd like to apply some algorithms to change the positions of those vertices with the sound of the music (using FMOD)...

I really just need to know how to put these vertices in space and connect them with a line...

Any suggestions?

Thank you very much

##### Share on other sites
On a similar post here someone suggested to use the following code:
D3DTLVERTEX vertex[2];int x=5,y=6,x2=20,y2=60;vertex[0]=D3DTLVERTEX(D3DVECTOR(x,y,0.0),1.0,RGB_MAKE(255,255,255),0,0,0);vertex[1]=D3DTLVERTEX(D3DVECTOR(x2,y2,0.0),1.0,RGB_MAKE(255,255,255),0,0,0);// Then draw it with:lpD3DDevice->DrawPrimitive(D3DPT_LINESTRIP,D3DFVF_TLVERTEX,&gridVertex,2,0);

but the compiler tells me that DrawPrimitive does not take 5 arguments? And it also doesn't recognise D3DTLVERTEX....

##### Share on other sites
Read the DX SDK documentation on DrawPrimitive. The primitive type is one of the parameters to that method, but the other parameters you pass to it do not make sense at all.

Also, you do know that in order for DrawPrimitive to actually use your vertex data, you must upload said data to the device by using vertex buffers, and set the vertex layout or the FVF of the data separately?

There is also a DrawPrimitiveUP method that can take a user memory pointer to the vertex data and upload it automatically, at the potential cost of performance in some common scenarios. However, your parameters don't fit that either.

##### Share on other sites
I'm sure he meant "DrawPrimitiveUP":

Quote:
 HRESULT DrawPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);

Edit @Nik02: Sorry, missed your last sentence.

##### Share on other sites
Yea, but his parameters do not make sense even if he did mean to use that method.

• The DPUP takes 4 parameters, but he has 5
• The vertex data is originally written in an array variable named "vertex", but the variable passed to the method is a pointer to a variable named "gridVertex"
• If you have two vertices, you only have one primitive of a line strip
• Neither 0 nor 2 is a possible match for the vertex stride

This is from a quick glance only.

##### Share on other sites
Quote:
 Original post by mind in a boxEdit @Nik02: Sorry, missed your last sentence.

I edited my post a little bit just after posting it. Sorry for the confusion :)

##### Share on other sites
Quote:
 Original post by Nik02Yea, but his parameters do not make sense even if he did mean to use that method.The DPUP takes 4 parameters, but he has 5The vertex data is originally written in an array variable named "vertex", but the variable passed to the method is a pointer to a variable named "gridVertex"If you have two vertices, you only have one primitive of a line stripNeither 0 nor 2 is a possible match for the vertex stride This is from a quick glance only.

Ok so I modified those lines that were suggested in the other post and changed to function to DrawPrimitiveUP
		D3DXVECTOR3 vertex[2];		vertex[0]=D3DXVECTOR3(1.0f, 1.0f, 1.0f);		vertex[2]=D3DXVECTOR3(7.0f, 10.0f, 7.0f);		device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,&vertex,0);

This one compiles ok but when I run it I get a " Stack around the variable 'vertex' was corrupted" error.... Could it be because of D3DXVECTOR3 type used? Or because I have to declare vertex as a class variable instead of calling these lines in the Render bit?

Thanks for the help

##### Share on other sites
Quote:
 D3DXVECTOR3 vertex[2];vertex[0]=D3DXVECTOR3(1.0f, 1.0f, 1.0f);vertex[2]=D3DXVECTOR3(7.0f, 10.0f, 7.0f);//ERROR...

You have wrote beyond array bounds, try:
D3DXVECTOR3 vertex[2];vertex[0]=D3DXVECTOR3(1.0f, 1.0f, 1.0f);vertex[1]=D3DXVECTOR3(7.0f, 10.0f, 7.0f);

i am suprised you are not getting any warnings from compiler?

I think you got one more error in your code:
Quote:
 device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,&vertex,0);

try:
device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,&vertex[0],0);

or:
device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,vertex,0);

##### Share on other sites
Quote:
Original post by belfegor
Quote:
 D3DXVECTOR3 vertex[2];vertex[0]=D3DXVECTOR3(1.0f, 1.0f, 1.0f);vertex[2]=D3DXVECTOR3(7.0f, 10.0f, 7.0f);//ERROR...

You have wrote beyond array bounds, try:
D3DXVECTOR3 vertex[2];vertex[0]=D3DXVECTOR3(1.0f, 1.0f, 1.0f);vertex[1]=D3DXVECTOR3(7.0f, 10.0f, 7.0f);

i am suprised you are not getting any warnings from compiler?

I think you got one more error in your code:
Quote:
 device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,&vertex,0);

try:
device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,&vertex[0],0);

or:
device->DrawPrimitiveUP(D3DPT_LINESTRIP,2,vertex,0);

Oh yeah, wrong array index, it runs ok now but nothing gets shown on screen...could it be because I'm using D3DXVECTOR3 instead of D3DLVERTEX like suggested in the other post?
Cos when I try and use D3DLVERTEX I keep getting an undeclared identifier error, even after including <ddraw.h> which I seem to understand is the required header...

Thanks for the help!

##### Share on other sites
Quote:
 Oh yeah, wrong array index, it runs ok now but nothing gets shown on screen...

Did you setup "camera" in your scene? like:
//global D3DXMATRIX world, view, proj;...//in some init functionD3DXMatrixIdentity(&world);D3DXVECTOR3 pos(0.0f, 0.0f, -100.0f);//move back a bitD3DXVECTOR3 lat = vertex[0];//look at vertex 1D3DXVECTOR3 upd(0.0f, 1.0f,   0.0f);D3DXMatrixLookAtLH(&view, &pos, &lat, &upd);float aspect = (float)ScreenWidth / (float)ScreenHeight;float fov    = D3DXToRadian(60.0f);D3DXMatrixPerspectiveFovLH(&proj, fov, aspect, 1.0f, 1000.0f);...//in some render functiondevice->SetTransform(D3DTS_WORLD, &world);device->SetTransform(D3DTS_VIEW, &view);device->SetTransform(D3DTS_PROJECTION, &proj);RenderLines();//function that render lines

Quote:
 ...could it be because I'm using D3DXVECTOR3 instead of D3DLVERTEX like suggested in the...

I doubt that D3DLVERTEX is part of DX SDK it must be some custom header that you failed to include/download with that demo? but it doesnt matter if it is used only for storing position.

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631715
• Total Posts
3001868
×