world transformation matrices and company

Started by
3 comments, last by Cipher3D 22 years, 5 months ago
The only demo I''ve made in 3d is using transformed and lit vertices - they seem to be easiest to use. However, when I start doing untransformed and unlit vertices, i get the black screen of death :-). Do I initialize the projection matrix first, then in FrameMove (I''m using the Common files provided by DirectX 8.0 SDK) set the view and world matrix? I''m a bit confused! If you reply, please explain how to create a triangle in 3d and let a camera move round and round around it. Cheers, Cipher3D
I eat heart attacks
Advertisement
PLEEZE help me figure this out!


Pleeeeeeeeeeaseee
I eat heart attacks
Yep, you usually initialise the Projection matrix once, then the View matrix whenever the camera needs to change position/direction, then the World matrix per object (world matrix transforms vertices from model space into world space).

Take a look at the tutorials which come with the SDK - look in the dxsdk\samples\Multimedia\Direct3D\Tutorials folder. In particular look at Tut03_Matrices.

The D3DXMatrixLookAtLH() function is what creates the matrix used to set the camera position/direction. You can change the parameters passed to that function, then do a SetTransform(D3DTS_VIEW,...) with the resultant matrix to change the position and orientation of the camera.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Projection matrix you usually set once (unless you change resolutions or clip planes). View matrix needs to be updated whenever your camera changes. World matrix should be set to the transformation matrix of each object before you render the object.

In the common files I believe camera is updated in framemove (assuming you are moving the camera), as its the transformation matrix for each object (assuming the object moves). World matrix is set in Render() to the transformation matrix of each object before you render the object.

If you are seeing black, maybe your camera is not pointing at your object? Place your object at the origin (0,0,0) and try using the D3DXMatrixLookAtLH function to make a camera that looks at the origin.

Also you should be aware that DirectX culls polygons facing away from the viewer (ie it doesn''t render things from the back). So if you specified the vertices in the wrong order, its possible you see nothing. You can change the cull mode to none with SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) for debugging purposes.
Thanks a lot.

however, i got my spinning nacho up and running, but i did not call D3DXMatrixLookAtLH(blah blah). instead, i did some weird math that looks like this:

D3DXVECTOR3 vLook = D3DXVECTOR3(0.0f,0.0f,1.0f);
D3DXVECTOR3 vUp = D3DXVECTOR3(0.0f,1.0f,0.0f);
D3DXVECTOR3 vRight = D3DXVECTOR3(1.0f,0.0f,0.0f);
D3DXVECTOR3 vPos = D3DXVECTOR3(0.0f,0.0f,-80.0f);

FLOAT fPitch,fYaw,fRoll;
fPitch=fYaw=fRoll=0.0f;
FLOAT fSpeed = 1.0f*m_fTimeElapsed;

D3DXVec3Normalize(&vLook,&vLook);
D3DXVec3Cross(&vRight, &vUp, &vLook); // Cross Produkt of the UP and LOOK Vector
D3DXVec3Normalize(&vRight, &vRight);
D3DXVec3Cross(&vUp, &vLook, &vRight); // Cross Produkt of the RIGHT and LOOK Vector
D3DXVec3Normalize(&vUp, &vUp);

// Matrices for pitch, yaw and roll
D3DXMATRIX matPitch, matYaw, matRoll;
D3DXMatrixRotationAxis(&matPitch, &vRight, fPitch );
D3DXMatrixRotationAxis(&matYaw, &vUp, fYaw );
D3DXMatrixRotationAxis(&matRoll, &vLook, fRoll);

// rotate the LOOK & RIGHT Vectors about the UP Vector
D3DXVec3TransformCoord(&vLook, &vLook, &matYaw);
D3DXVec3TransformCoord(&vRight, &vRight, &matYaw);

// rotate the LOOK & UP Vectors about the RIGHT Vector
D3DXVec3TransformCoord(&vLook, &vLook, &matPitch);
D3DXVec3TransformCoord(&vUp, &vUp, &matPitch);

// rotate the RIGHT & UP Vectors about the LOOK Vector
D3DXVec3TransformCoord(&vRight, &vRight, &matRoll);
D3DXVec3TransformCoord(&vUp, &vUp, &matRoll);

D3DXMATRIX view=matWorld;
D3DXMatrixIdentity( &view );
view._11 = vRight.x; view._12 = vUp.x; view._13 = vLook.x;
view._21 = vRight.y; view._22 = vUp.y; view._23 = vLook.y;
view._31 = vRight.z; view._32 = vUp.z; view._33 = vLook.z;
view._41 = - D3DXVec3Dot( &vPos, &vRight );
view._42 = - D3DXVec3Dot( &vPos, &vUp );
view._43 = - D3DXVec3Dot( &vPos, &vLook );

m_pd3dDevice->SetTransform(D3DTS_VIEW, &view);

I eat heart attacks

This topic is closed to new replies.

Advertisement