Archived

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

World, View, Projection matrices - arrrrgh driving me nuts ! :)

This topic is 6390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

alrite here we go, tihs is a mouthful. so i thought i would start with just a simple triangle, 3 verts nothing more. after initialising all my d3d stuff with d3dx away i went. triangle defined as: V[0].v = D3DVECTOR(-2,-0.5f,1); V[0].c = D3DRGB(1,0,0); // Red V[1].v = D3DVECTOR( 0, 0.5f,1); V[1].c = D3DRGB(0,1,0); // Green V[2].v = D3DVECTOR( -1,-0.5f,1); V[2].c = D3DRGB(0,0,1); // Blue gave up on using D3DTLVERTEX - everytime i went to render it just drew the background, couldnt see the triangle at all. ok so that works (v is of type vector, defined by witchlord has a d3dvector and d3dcolor). i set up my view matrix like this: camera = D3DVECTOR(0, 0, -30); D3DXMATRIX T, Ry, Rx, Rz, Mtx; D3DXMatrixTranslation(&T, -camera.x, -camera.y, -camera.z); D3DXMatrixRotationY(&Ry, -0.0f); D3DXMatrixRotationX(&Rx, -0.f); D3DXMatrixRotationZ(&Rz, -0.f); Mtx = T * Ry * Rx * Rz; lpd3device->SetTransform(D3DTRANSFORMSTATE_VIEW, (D3DMATRIX*)&Mtx); and the world matrix is just the identity matrix, no rotations yet. the projection matrix is defined as: D3DXMATRIX T; D3DXMatrixPerspectiveLH(&T, 0.57f, 1.0f, 0.1f, 100.0f); lpd3device->SetTransform(D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX *)&T); so all my matrices are set. funny thing is there still doesnt seem to be any depth to my scene at all. like the triangle is drawn (no fill color just wireframe) but its just on the screen, doesnt look like its ''in'' the screen. also i have defined the triangle coords with respect to screen coords - is there any point applying the world matrix to them since it wont change them ? how can i rotate the camera around the triangle without the triangle moving ie. do i just translate the camera about the y axis ?

Share this post


Link to post
Share on other sites
From what I can tell you are rendering a triangle on the left half of the screen.

You can''t see any depth to the triangle as it is facing the camera forward vector, i.e. its normal is (0,0,-1). All vertices will have the same depth value after projection.

I''m not sure what you are trying to do. You ask if you can rotate the camera around the triangle, the answer to that is yes but it can be a little tricky with the model for the camera you have set up. If you want this I can show you how to do it.

If you however want the triangle to rotate about its y axis, yet remain at the same point I would suggest doing it with the world matrix, like this:

// Center the triangle around the origo
V[0].v = D3DVECTOR(-1,-0.5f,1); V[0].c = D3DRGB(1,0,0); // Red
V[1].v = D3DVECTOR( 1, 0.5f,1); V[1].c = D3DRGB(0,1,0); // Green
V[2].v = D3DVECTOR( 0,-0.5f,1); V[2].c = D3DRGB(0,0,1); // Blue

// Rotate the triangle and then translate to its position
D3DXMATRIX T, Ry, Mtx;
D3DXMatrixRotationY(&Ry, AngleY);
D3DXMatrixTranslation(&T, -1, 0, 0);

Mtx = Ry * T;
lpd3device->SetTransform(D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)&Mtx);

I hope this was what you wanted, otherwise I have wasted some of my precious time. (Time I wouldn''t use anyway, but still )



- WitchLord

Share this post


Link to post
Share on other sites