Skip to main content
GameDev.net gamedev.net
🔒 Locked

traingle sample

Started by jagguy Mar 19, 2005 at 1:02 AM 5 replies 400+ views
Original Post
jagguy
jagguy
In the directX8 3D samples there is a tutorial program called Triangle and another called Vertices All I want to do is to use this code in the Triangle program (from Vertices) so I can define a triangle easier. I comment out the old code for these commands in the Triangle. // A structure for our custom vertex type struct CUSTOMVERTEX { FLOAT x, y, z, rhw; // The transformed position for the vertex DWORD color; // The vertex color }; // Our custom FVF, which describes our custom vertex structure #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) in the Triangle program and rotate the triangle about the y-axis I run the program and get a traingle but it doesnt move. It is the same code as the orignal triangle program other tha the above addition. The SetupMatrices doesnt do anything like the original Triangle.
jagguy
jagguy
Quote:
Original post by Anonymous Poster
Please, show us your SetupMatrices's code.

here you go


// Name: SetupMatrices()
// Desc: Sets up the world, view, and projection transform matrices.
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
// For our world matrix, we will just leave it as the identity
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixRotationX( &matWorld, timeGetTime()/500.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

// Set up our view matrix. A view matrix can be defined given an eye point,
// a point to lookat, and a direction for which way is up. Here, we set the
// eye five units back along the z-axis and up three units, look at the
// origin, and define "up" to be in the y-direction.
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 3.0f,-5.0f ),
&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

// For the projection matrix, we set up a perspective transform (which
// transforms geometry from 3D view space to 2D viewport space, with
// a perspective divide making objects smaller in the distance). To build
// a perpsective transform, we need the field of view (1/4 pi is common),
// the aspect ratio, and the near and far clipping planes (which define at
// what distances geometry should be no longer be rendered).
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}


....nothing happens?

Specchum
Specchum
I dont' have the dx8 triangle example here so can't comment on the code per se, but you'll probably want to change your CUSTOMVERTEX to:

// A structure for our custom vertex typestruct CUSTOMVERTEX{FLOAT x, y, z; // The UNtransformed position for the vertexDWORD color; // The vertex color};// Our custom FVF, which describes our custom vertex structure#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)


EDIT: I suppose some explanation is in order :)
RHW is used only for transformed vertices. I.e, you are telling DX that it does not need to perform any transformation on the vertices since you've already taken care of that (by using absolute screen co-ordinates for each vertice).

If you want DX to apply scaling, rotation and translation to the vertices, you need to drop the RHW to tell DX to apply the transforms you perform.
"There is no dark side of the moon." - Pink Floyd
jagguy
jagguy
Quote:
Original post by Specchum
I dont' have the dx8 triangle example here so can't comment on the code per se, but you'll probably want to change your CUSTOMVERTEX to:

*** Source Snippet Removed ***

EDIT: I suppose some explanation is in order :)
RHW is used only for transformed vertices. I.e, you are telling DX that it does not need to perform any transformation on the vertices since you've already taken care of that (by using absolute screen co-ordinates for each vertice).

If you want DX to apply scaling, rotation and translation to the vertices, you need to drop the RHW to tell DX to apply the transforms you perform.


OK that makes sense ( I cant do it that way).

How do you specift coordinates of a polygon in more meaningful terms eg 40,100,10 instead of .4,1,,.1........
Specchum
Specchum
Not sure what you mean by "meaningful" terms but think of the co-ordinates in units rather than absolute screen co-ord values. For ex, a triangle with vertices (0,1,0), (1,0,0) and (-1,0,0) could be read as:

"First vertex is 1 *unit* up on the y-axis, 2nd vertex is 1 *unit* on +x axis and the last vertex is 1 *unit* on -x axis". Now you can scale these values to whatever you want by applying a scale matrix.

If you compare .4,1,.1 and 40,100,10 (the values you gave) you'll see that you are just applying a scale factor of 100 (multiplying the values by 100). Similarly, you can scale a triangle/polygon to different size by multiplying the entire transform by a single scaling matrix. Neat no?

Note that these are NOT screen co-ordinates but rather model space co-ordinates. Possibly, this is your confusion? You need to apply the world, view and projection matrix to these co-ordinates to *transform* the object to the screen finally.

If you used RHW, then you would specify the co-ordinates in screen units but then you won't be able to apply and transformations to them, as mentioned before.

In a nutshell (and to put it rather simplistically), for transformed vertices (RHW) think screen co-ordinates. For untransformed vertices think model-space co-ordinates.

Hope things are a bit clear now...
"There is no dark side of the moon." - Pink Floyd
jagguy
jagguy
Quote:
Original post by Specchum
Not sure what you mean by "meaningful" terms but think of the co-ordinates in units rather than absolute screen co-ord values. For ex, a triangle with vertices (0,1,0), (1,0,0) and (-1,0,0) could be read as:

"First vertex is 1 *unit* up on the y-axis, 2nd vertex is 1 *unit* on +x axis and the last vertex is 1 *unit* on -x axis". Now you can scale these values to whatever you want by applying a scale matrix.

If you compare .4,1,.1 and 40,100,10 (the values you gave) you'll see that you are just applying a scale factor of 100 (multiplying the values by 100). Similarly, you can scale a triangle/polygon to different size by multiplying the entire transform by a single scaling matrix. Neat no?

Note that these are NOT screen co-ordinates but rather model space co-ordinates. Possibly, this is your confusion? You need to apply the world, view and projection matrix to these co-ordinates to *transform* the object to the screen finally.

If you used RHW, then you would specify the co-ordinates in screen units but then you won't be able to apply and transformations to them, as mentioned before.

In a nutshell (and to put it rather simplistically), for transformed vertices (RHW) think screen co-ordinates. For untransformed vertices think model-space co-ordinates.

Hope things are a bit clear now...


I knew you could do that, just multiply a matrix to desired coordinates but I was hoping for a easier way.
For 2 objects this becomes even more messy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.