School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

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!




DirectX10 Vertex Coordinates....Really Confused :(

 

DirectX10 Vertex Coordinates....Really Confused :(

DominationXVI

10 Jun, 2009 - 09:01 PM
Post #1

D.I.C Head
**

Joined: 2 Feb, 2008
Posts: 74



Thanked: 2 times
My Contributions
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:

CODE

// Create vertex buffer
SimpleVertex vertices[] =
{
    D3DXVECTOR3( 0.0f, 0.5f, 0.5f ),
    D3DXVECTOR3( 0.5f, -0.5f, 0.5f ),
    D3DXVECTOR3( -0.5f, -0.5f, 0.5f ),
};


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.

User is offlineProfile CardPM
+Quote Post


Kanvus

RE: DirectX10 Vertex Coordinates....Really Confused :(

11 Jun, 2009 - 02:36 AM
Post #2

D.I.C Regular
Group Icon

Joined: 19 Feb, 2009
Posts: 451



Thanked: 39 times
Dream Kudos: 50
My Contributions
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
User is offlineProfile CardPM
+Quote Post

stayscrisp

RE: DirectX10 Vertex Coordinates....Really Confused :(

11 Jun, 2009 - 02:55 AM
Post #3

Mouth->Insert(Foot);
Group Icon

Joined: 14 Feb, 2008
Posts: 1,380



Thanked: 53 times
Dream Kudos: 300
My Contributions
QUOTE(DominationXVI @ 10 Jun, 2009 - 09:01 PM) *

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:

CODE

// Create vertex buffer
SimpleVertex vertices[] =
{
    D3DXVECTOR3( 0.0f, 0.5f, 0.5f ),
    D3DXVECTOR3( 0.5f, -0.5f, 0.5f ),
    D3DXVECTOR3( -0.5f, -0.5f, 0.5f ),
};


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?

User is online!Profile CardPM
+Quote Post

Kanvus

RE: DirectX10 Vertex Coordinates....Really Confused :(

11 Jun, 2009 - 05:16 AM
Post #4

D.I.C Regular
Group Icon

Joined: 19 Feb, 2009
Posts: 451



Thanked: 39 times
Dream Kudos: 50
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

DominationXVI

RE: DirectX10 Vertex Coordinates....Really Confused :(

15 Jun, 2009 - 04:38 PM
Post #5

D.I.C Head
**

Joined: 2 Feb, 2008
Posts: 74



Thanked: 2 times
My Contributions
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:

CODE

SimpleVertex vertices[] =
{
    D3DXVECTOR3( 0.0f, 0.5f, 0.5f ),
    D3DXVECTOR3( 0.5f, -0.5f, 0.5f ),
    D3DXVECTOR3( -0.5f, -0.5f, 0.5f ),
};


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.
User is offlineProfile CardPM
+Quote Post

KYA

RE: DirectX10 Vertex Coordinates....Really Confused :(

15 Jun, 2009 - 05:22 PM
Post #6

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,193



Thanked: 490 times
Dream Kudos: 2825
Expert In: C, C++, Java

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

DominationXVI

RE: DirectX10 Vertex Coordinates....Really Confused :(

15 Jun, 2009 - 05:29 PM
Post #7

D.I.C Head
**

Joined: 2 Feb, 2008
Posts: 74



Thanked: 2 times
My Contributions
QUOTE(KYA @ 15 Jun, 2009 - 05:22 PM) *

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.
User is offlineProfile CardPM
+Quote Post

Tom9729

RE: DirectX10 Vertex Coordinates....Really Confused :(

15 Jun, 2009 - 05:33 PM
Post #8

Debian ninja
Group Icon

Joined: 30 Dec, 2007
Posts: 2,129



Thanked: 53 times
Dream Kudos: 425
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:24AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month