Archived

This topic is now archived and is closed to further replies.

The C modest god

Noob at Direct3D

Recommended Posts

Does the world matrix transform all the vertices streams? and them only? What does the world matrix values stand for, which columns or rows represent which values? How would I use world matrix to rotate vertices that are of screen coordinate values? I would appreaciate help on this matter.

Share this post


Link to post
Share on other sites
The world matrix represents a new cartesian space, optionally rotated, scaled and/or transformed.

In DirectX (Vectors being pre-multiplied to matrices), the first three rows represent the x,y,z axis of this new space. The fourth column give you your translation.

Your view matrix is the inverse of a similar matrix. You can extract your x,y,z axis (your orientation) from the 1st, 2nd and 3rd column of you view matrix.

Share this post


Link to post
Share on other sites
quote:
Original post by UdayK
The world matrix represents a new cartesian space, optionally rotated, scaled and/or transformed.

In DirectX (Vectors being pre-multiplied to matrices), the first three rows represent the x,y,z axis of this new space. The fourth column give you your translation.

Your view matrix is the inverse of a similar matrix. You can extract your x,y,z axis (your orientation) from the 1st, 2nd and 3rd column of you view matrix.

I got vertices with the values of x, y, z and rhw, color.
The world matrix would change only the x, y, z values?
Then how would a 4X4 matrix change the x, y, z values of the vertics?

Share this post


Link to post
Share on other sites
If you have rhw (which is usually set to 1), your x,y define the vertex in 2d screen coordinates and the z value specify the depth value for the vertex.

For how transformations are applied, you need a good introductry tutorial to help you. Gamedev.net hosts a very good collection of the same. You should try reading them up.

Share this post


Link to post
Share on other sites
quote:
Original post by UdayK
If you have rhw (which is usually set to 1), your x,y define the vertex in 2d screen coordinates and the z value specify the depth value for the vertex.

For how transformations are applied, you need a good introductry tutorial to help you. Gamedev.net hosts a very good collection of the same. You should try reading them up.


Does the stream buffer of vertices is the final stage before rendering? or does the world matrix is implemented on all the vertices in the stream buffer before rendered?

Share this post


Link to post
Share on other sites
The world transform would be applied to all untransformed vertices you have, before they are passed down the pipeline for per-pixel operations.

If you have vertex shaders you may choose to apply the transform or forward the vertices as they came in.

Share this post


Link to post
Share on other sites
quote:
Original post by UdayK
The world transform would be applied to all untransformed vertices you have, before they are passed down the pipeline for per-pixel operations.

If you have vertex shaders you may choose to apply the transform or forward the vertices as they came in.


In code speaking,

I have created and set a vertex buffer with values:


IDirect3DDevice9_CreateVertexBuffer(gDevice3D, 3*sizeof(CUSTOMVERTEX), 0 /* Usage */, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &gBuffer3D, NULL);

IDirect3DVertexBuffer9_Lock(gBuffer3D, 0, sizeof(gvertices), (void**)&pVertices, 0 );
memcpy( pVertices, gvertices, sizeof(gvertices) );
IDirect3DVertexBuffer9_Unlock(gBuffer3D);

IDirect3DDevice9_SetStreamSource(gDevice3D, 0, gBuffer3D, 0, sizeof(CUSTOMVERTEX) );
IDirect3DDevice9_SetFVF(gDevice3D, D3DFVF_CUSTOMVERTEX );

Then I have set a world matrix:


IDirect3DDevice9_SetTransform(gDevice3D, D3DTS_WORLD, &matWorld );


The rendering loop look like this:

IDirect3DDevice9_Clear(gDevice3D, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
IDirect3DDevice9_BeginScene (gDevice3D);
IDirect3DDevice9_DrawPrimitive(gDevice3D, D3DPT_TRIANGLELIST, 0, 1 );
IDirect3DDevice9_EndScene (gDevice3D);
IDirect3DDevice9_Present (gDevice3D, NULL, NULL, NULL, NULL);


Will the world matix have any effect on the vertices I have set?

Share this post


Link to post
Share on other sites
quote:
Original post by Nik02
It depends on the format of the vertices. If the rhw flag is set, then d3d doesn''t modify your vertices.

-Nik

it is set to D3DFVF_XYZRHW|D3DFVF_DIFFUSE.
Why would the rhw coordinate prevent from the world matrix to change the x, y, z coordinates?
As far as I understand the rhw coordinate is the surface color coordinate, or strength.

About the 4*4 world matrix, tell me if I am right...
The first 3 rows of the matrix are the axis(orientation and scaling) of the space represented by the matrix and the fourth row is the transformation of the space(origin point).
The fourth column has no role?

Share this post


Link to post
Share on other sites
quote:
Original post by The C modest god
quote:
Original post by Nik02
It depends on the format of the vertices. If the rhw flag is set, then d3d doesn''t modify your vertices.

-Nik

it is set to D3DFVF_XYZRHW|D3DFVF_DIFFUSE.
Why would the rhw coordinate prevent from the world matrix to change the x, y, z coordinates?
As far as I understand the rhw coordinate is the surface color coordinate, or strength.



Rhw specifically tells d3d that you have transformed the vertex yourself, and d3d should send it to rasterization right away. No offense, but it does no good to guess, when you could see the sdk for precise info on this.

The w can be thought as inverse depth of a vertex mapped to 0...1 (usually) from the vertex''s perspective space depth.
This is done because it enables, for example, a z-buffer to operate at an uniform scale, and various other operations involving fog and texture coordinate perspective correction.

quote:

About the 4*4 world matrix, tell me if I am right...
The first 3 rows of the matrix are the axis(orientation and scaling) of the space represented by the matrix and the fourth row is the transformation of the space(origin point).
The fourth column has no role?



The fourth column contains the coefficients of the w component.
It is primarily/commonly used in perspective projection with some multiplier on z row to cause a perspective divide.
But, in a world matrix, i rarely have seen perspective divide used...

Also, fourth row is translation, not transformation. It defines object''s origin position.

Kind rgds,
-Nik

Share this post


Link to post
Share on other sites