Ok... I formed a question....

Started by
4 comments, last by hammerstein_02 21 years, 5 months ago
Right, I have been messing around with directx graphics over the past few days. And I am playing with the DirectX Graphics and Video: A Fresh Start.. which I am actually finding of more help than PRPGWDX by Jim Adams right now. I got to part 5.. and want to ask about this:
  
MYVERTEX vertices[] =
{
    // front face

    {  0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 1.0 }, // 0

    { -0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 1.0 }, // 1

    {  0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 0.0 }, // 2

    { -0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 0.0 }, // 3


    // top face

    {  0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 1.0 }, // 4

    { -0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 1.0 }, // 5

    {  0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 0.0 }, // 6

    { -0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 0.0 }, // 7


    // back face

    { -0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 1.0 }, // 8

    {  0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 1.0 }, // 9

    {  0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 0.0 }, // 10

    { -0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 0.0 }, // 11


    // left face

    {  0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 1.0 }, // 12

    {  0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 0.0 }, // 13

    {  0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 0.0 }, // 14

    {  0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 1.0 }, // 15


    // bottom face

    {  0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 1.0 }, // 16

    { -0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 0.0 }, // 17

    {  0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 0.0 }, // 18

    { -0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 1.0 }, // 19


    // right face

    { -0.5f,  0.5f,  0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0, 0.0 }, // 20

    { -0.5f,  0.5f, -0.5f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0, 0.0 }, // 21

    { -0.5f, -0.5f,  0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 0.0, 1.0 }, // 22

    { -0.5f, -0.5f, -0.5f, D3DCOLOR_ARGB(255, 127, 127, 127), 1.0, 1.0 }, // 23

};
  
Starting with point 0.. I know the points are defined in local space (object space right?) , but how do I decide what these values should be? I know they are coordinates.. but how do I know that the first x,y,z values should be 5.0f,5.0f,5.0f? Where are the relative too? I don''t quite understand.. can anyone explain this to me? =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=
Advertisement
I don''t know anything about DirectX but I believe I''ve an answer.

Your code looks the definition of a cube, right?
{x, y, z, color, ?, ?}

You ask for Where are coordinates relatives to?

It''s a personal decision !!!

In your code (well, Jim Adams''s code) you''ve choose the center of the cube as the origin of coordinates. But you could choose any other point as origin. You could add 0.5 to every coordinate of the model and then the origin will be in a vertice of the cube. Or you could add 1000.0 to every coordinate. Then the origin will be far away of the cube.

I suppose of the advantage of choose the center as origin will be shown when you draw the cube. I think that you will give a point when you want to draw it. This point will be the origin of coordinates of the cube.
If you choose a good origin for your model (the center of the cube) things will be allrigtht. If you choose the model that I said before (adding 1000.0) then you don''t see your model or you will see it, but far away from the place you wants to appear.
Huh? At what point did I decide that I was going to use the centre of the cube as the origin? Where do I say, "Hey, use the centre of the cube..". I know that the vertices are processed in order, but is every one relative to the previous, or are the all relative to the centre? I don''t quite understand how this functions.. hence my question. What determines where I draw from, and why do I see some examples.. 50.0f, 10.0f, 90.0f and then I see some 0.1f, 0.5f etc.. ?

=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=
quote:Original post by hammerstein_02
I know that the vertices are processed in order, but is every one relative to the previous, or are the all relative to the centre?


the points are relative to the origin of coordinates (object space).

Think that you have an infinit void space. That is the object space. Then you define in that space a figure (your code). While you are defining the figure you are using and arbitrary origin of coordinates in that inifinit void space. Do you agree with this?

After defining the figure you would like to draw it in your , also infinite, work space.

The object space and the work space are disjoint universes.

Then you want to draw your figure in the work space. You need to say where (a point in work space), with which orientation and with which scale.

To draw the figure, DirectX will translate every vertex of the figure in the object space to the work space. To do that DirectX will do overlap the origin of object space with the point in work space when you want to draw. Also will rotate the whole object space depending of what orientation you have specified. And also will enlarge or reduce the values of the coordinates of the vertex depending of the scale value.

Do you understand it now?
Ok, I really must be stupid.. but I am still struggling. When you define your model, if you are working in 3d, you use smaller coords right? You see I did the triangle example, and in that you specify vertices that are quite large.. then you get to the cube example and you are using smaller vertices..? and is the centre of the object always the point of reference? I don''t understand how this works.. can anyone else see my question? I am struggling to grasp this.
Vertices in object space are relative to an arbitrary point. It can be the center of your object, or it might not be. When rendering the object in world space, you select the world coordinates of this point (to which all the vertices in the object are relative).

Say you have a triangle whose vertices are at (-5, -5, -5), (0, 0, -5), and (-3, -3, -3) in object space. If you render this triangle to world space point (1, 1, 1), the rendered triangle''s vertices will be at (-4, -4, -4), (1, 1, -4), and (-2, -2, -2) in world space.

The point of reference in object space has little meaning. Besides, you will rarely have to deal with these numbers since you will use 3D modeling software to make objects instead of typing in vertex coordinates by hand.

This topic is closed to new replies.

Advertisement