• Advertisement
Sign in to follow this  

ID3DXLine 3D?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have several points (coordinates in D3DXVECTOR3), and would like to draw lines they bound these points, equal to waypoints.

However ID3DXLine is only for 2D drawings, how can I do this?


Can i use IDirect3DDevice9::DrawPrimitive using D3DPT_LINESTRIP as the primitive type.?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
I did as follows:

	D3DXVECTOR3 vertices[2];
vertices[0].x = -35;
vertices[0].y = 5;
vertices[0].z = 8;

vertices[1].x = 0;
vertices[1].y = 5;
vertices[1].z = 8;

D3DXMATRIX matCoordinate;
D3DXMatrixIdentity(&matCoordinate);

D3DMATERIAL9 oldMaterial;
DWORD oldAmbient;
m_pDevice->GetMaterial( &oldMaterial );
m_pDevice->GetRenderState( D3DRS_AMBIENT, &oldAmbient );

// Disable depth buffering so Axis always shows up
m_pDevice->SetRenderState( D3DRS_ZENABLE, false );
m_pDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA(255, 255, 255, 255) );

m_pDevice->SetTransform( D3DTS_WORLD, &matCoordinate );
m_pDevice->SetFVF(D3DFVF_VERTEXPOSITION);

m_pDevice->DrawPrimitiveUP( D3DPT_LINELIST, 2, (LPVOID) &vertices[0], sizeof(VertexPos) );

// Restore states
m_pDevice->SetRenderState( D3DRS_ZENABLE, true );
m_pDevice->SetRenderState( D3DRS_AMBIENT, oldAmbient );
m_pDevice->SetMaterial( &oldMaterial );


The line was drawn correctly,

Now I need to draw the path given by my algorithm *A
it returns a std::list<D3DXVECTOR3> with all points,
how can I do to draw lines connecting all those points?

Share this post


Link to post
Share on other sites
Allocate an array on the heap, copy each vector into the array, call DrawPrimitiveUP(), then free the array.
Or, copy the elements into a std::vector, and pass the address of the first element of the std::vector to DrawprimitiveUP().

Share this post


Link to post
Share on other sites
Edit: Ninja'd by EvilSteve.

For this you could fill a vertex buffer with your points (Which is faster), but you can also stay with DrawPrimitiveUP if you need that just for debugging.

It would go like this:

At first you want to set the renderstates for all lines. I copied that out of your code:


D3DXMATRIX matCoordinate;
D3DXMatrixIdentity(&matCoordinate);

D3DMATERIAL9 oldMaterial;
DWORD oldAmbient;
m_pDevice->GetMaterial( &oldMaterial );
m_pDevice->GetRenderState( D3DRS_AMBIENT, &oldAmbient );

// Disable depth buffering so Axis always shows up
m_pDevice->SetRenderState( D3DRS_ZENABLE, false );
m_pDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA(255, 255, 255, 255) );

m_pDevice->SetTransform( D3DTS_WORLD, &matCoordinate );
m_pDevice->SetFVF(D3DFVF_VERTEXPOSITION);





Then you have to draw all the lines. You can do it like that (Semi-Pseudo-code):


D3DXVECTOR3 LastNode(0,0,0);
for(iterator it=List.Begin;it!=List.End; it++)
{
Vertex1=(*it);
Vertex2=LastNode;

DrawVertices();

LastNode=(*it);
}




And then you reset your drawing states.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement