Join 300,579 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,241 people online right now. Registration is fast and FREE... Join Now!
I just started learning 3D programming with DirectX10, however, I've hit a roadblock that I can't seem to get around. In every tutorial I've encountered dealing with drawing a primitive shape (a triangle, to be specific), the coordinates for each vertex is defined as follows:
I believe these coordinates are relative to the shape itself. What if I want to define the vertex coordinates in actual "screen space", like by using actual screen coordinates? I read Kya's tutorial on vertices, and he seems to be doing just that (I think he's using DirectX 9, tho). However, I just cannot figure out how to do it. I mean, what if I want to place an object at a particular location on my screen? Any help you guys could give would be great; this whole coordinate thing is really slowing me down.
Correct me if I'm wrong but when spawning a shape, does it not start at the center of the screen? That is how 3D works because it operates in Perspective and not Orthographic and Cartesian coordinates. Even ortho starts at the middle. If you want to have it at the top left then you have to translate it to there or draw it there in the first place.
CODE
//Draws triangle towards top left of screen SimpleVertex vertices[] = { D3DXVECTOR3( -1.0f, 1.0f, 0.5f ). D3DXVECTOR3( 0.0f, -0.0f, 0.5f ), D3DXVECTOR3( -1.0f, -0.0f, 0.5f ), };
And it's slow because you're not supposed to type every coordinate in by hand. They are drawn in a 3d model program and then saved to a file that holds those vertices and you have to read them into DirectX using structs of triangles.
This post has been edited by Kanvus: 11 Jun, 2009 - 02:38 AM
I just started learning 3D programming with DirectX10, however, I've hit a roadblock that I can't seem to get around. In every tutorial I've encountered dealing with drawing a primitive shape (a triangle, to be specific), the coordinates for each vertex is defined as follows:
I believe these coordinates are relative to the shape itself. What if I want to define the vertex coordinates in actual "screen space", like by using actual screen coordinates? I read Kya's tutorial on vertices, and he seems to be doing just that (I think he's using DirectX 9, tho). However, I just cannot figure out how to do it. I mean, what if I want to place an object at a particular location on my screen? Any help you guys could give would be great; this whole coordinate thing is really slowing me down.
Hi
For what reason do you want to do this? are you trying to make a GUI or HUD?
He is starting to learn 3d programming so probably just wants to draw basic shapes but finds placing vertices by hand too cumbersome. Good point though. I wonder how often HUD are done 2d rather 3d these days. Seeing from SecondLife HUD design is purely 3d but is seen flat and you can't tell by looking.
Thank you for replying guys. I'm going to try to clarify my problem a bit more:
When I follow the triangle drawing tutorial on MSDN, the triangle always ends up right in the middle of my screen. This was a bit counter-intuitive to me at first because the coordinates I entered for the vertices of the triangle were like this:
It seemed to me that these "coordinates" couldn't possibly place something right in the middle of my screen. I believe the middle of my screen would be like x = 800, y = 500 (approx.). So how could I possibly move this shape around?
@stayscrisp:
I've just started learning DX10, so I'm just playing around trying to figure things out. I guess the most appropriate answer to your question is neither.
You're dealing with the window's coordinate system, not your system's when you are giving a shape points explicitly in your example. The "center" of the 3D world is [0,0,0], thus, your coordinates are drawing a triangle on or around the center based on its values.
You're dealing with the window's coordinate system, not your system's when you are giving a shape points explicitly in your example. The "center" of the 3D world is [0,0,0], thus, your coordinates are drawing a triangle on or around the center based on its values.
But the triangle is quite large (it occupies around half of the window's area), and the coordinates I've entered for the vertices would make for an obscenely small triangle, wouldn't they? I'm sorry if I'm missing something here.
Can't speak for DirectX but in OpenGL without applying any transformations, the viewport is generally 1.0f wide and 1.0f high (in world coordinates). You can always scale or translate backwards along the Z-axis if you want to make your triangle look smaller.