# Show points in cartesian system with DirectX

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

## Recommended Posts

Hello, my name is Dimitris Sgourdos and I have a project for my university.
I need to display a set of 3d points in cartesian system.
I use visual studio 2010. But I read many tutotrials but I cannot find a way. More specific I try to compile their examples like
http://www.directxtutorial.com/Tutorial11/B-A/BA5.aspx#still
for example,
and I take some unresolved external problems.
Can someone direct me how can I display the points using c++ and visual studio 2010?
I would appreciate your help cause I try to "swim in an ocean" and I'm not so experienced as I'm still in the university.
I had tried and tried for days to find something that I can use but I didn't.

##### Share on other sites
Hi!

Have you looked into the Tutorials in the Sample Browser of the DirectX SDK? You won't have any problems with compiling them. Besides all of them have a brief documentation, explaining the most important things.
It’s best you look at the DirectX 11 Samples (even if your graphics card doesn’t support Dx11, you should use the Dx11 API, as you can always let it run on a lower feature level for older hardware).

“Sample 04: 3D Spaces” seems to be close to the things you need. You already have a camera moving in 3D space and the scene contains a cube. You’d have to change a few things for your purpose:

1. change the content of the vertex buffer (fill in your point data)
2. set the primitive topology to point list
From: g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
To: g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
3. use a draw call that does not use an index buffer (e.g. Draw instead of DrawIndexed)
From: g_pImmediateContext->DrawIndexed( 36, 0, 0 );
To: g_pImmediateContext->Draw(8, 0); // 8 points are in the scene.
4. you have to adapt the input layout, so it matches the data in your vertex buffer
5. and the shader must be changed it little (so that it only expects data you have included in your vertex buffer / defined in your input layout).

4. and 5. only apply if your points have other data than a position and a color (I don’t know… a point size perhaps).
If you do the steps 2. and 3., you should already see 8 colored points flying in space.

Cheers!

##### Share on other sites
It seems that I had missed that basic step
http://www.directxtu...DXWith2010.aspx
Your answer also help me to understand that I didn't installed the latest directX cause I missed some header files and I didn't have
C:\Program Files (x86)\Microsoft DirectX SDK......................
So now, the examples from the internet I tried before, they worked!
It took me time, but the first time is difficult if you are not experienced.
Anyway, thank you for the advises and of course now I will look the samples that you advised me!
Thank you!!!!!
Cheers, Dimitris
Anyway, thank you so much for your help! Now, it works!!!!! :-) :-)

##### Share on other sites
Hello Tsus,
“Sample 04: 3D Spaces” indeed seems to be close to the things I need.
I did all the changes you suggested me and I saw my points flying around :-)
But I want also with my points to show the x,y,z axes. So to have a complete cartesian coordinate system.
How can I do that? Is it possible? Can you advise me something?
Thank you again for your previous interest

##### Share on other sites
Hi!

You could render the axes as lines.
 // Create vertex buffer SimpleVertex vertices[] = { // line list of the axes. { XMFLOAT3( 0,0,0 ), XMFLOAT4( 1,0,0,1 ) }, // start of first line at (0,0,0) (color = red) { XMFLOAT3( 1,0,0 ), XMFLOAT4( 1,0,0,1 ) }, // end of first line at (1,0,0) (color = red) { XMFLOAT3( 0,0,0 ), XMFLOAT4( 0,1,0,1 ) }, // start of second line at (0,0,0) (color = green) { XMFLOAT3( 0,1,0 ), XMFLOAT4( 0,1,0,1 ) }, // end of second line at (0,1,0) (color = green) { XMFLOAT3( 0,0,0 ), XMFLOAT4( 0,0,1,1 ) }, // start of third line at (0,0,0) (color = blue) { XMFLOAT3( 0,0,1 ), XMFLOAT4( 0,0,1,1 ) }, // end of third line at (0,0,1) (color = blue) // point list for your points. { XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT4( 0.0f, 1.0f, 0.0f, 1.0f ) }, { XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT4( 0.0f, 1.0f, 1.0f, 1.0f ) }, { XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) }, { XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT4( 1.0f, 0.0f, 1.0f, 1.0f ) }, { XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT4( 1.0f, 1.0f, 0.0f, 1.0f ) }, { XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) }, { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f ) }, }; 

Don’t forget to set the byte width of the vertex buffer right.
bd.ByteWidth = sizeof( SimpleVertex ) * 14; // we added 6 more vertices to the buffer.

And then during rendering, we draw the first 6 vertices as a line list (your axes). Afterwards you switch to point rendering and draw the rest of the vertices (starting from index 6 we have 8 remaining vertices).
g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINELIST ); g_pImmediateContext->Draw(6, 0); g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST ); g_pImmediateContext->Draw(8, 6);

This is a rather simple way of rendering the axes. If you want to you can create triangle lists approximating a cylinder with a little cone on top (so it looks like an arrow).

Cheers!

##### Share on other sites
Thank you very much!!!
All the story is at these lines

g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINELIST );
g_pImmediateContext->Draw(6, 0);

g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
g_pImmediateContext->Draw(8, 6);

cause I didn't know how to select
D3D11_PRIMITIVE_TOPOLOGY_LINELIST
or
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST
simultaneously!!

Thank you in general! You have helped me as much as you cannot imagine and save me for wasting hours without result!!!

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013594
×