Sign in to follow this  

DirectX Camera rotation

Recommended Posts

Can anyone please describe how to rotate the camera around the volume using DirectX.I am setting the view matrix to set the position of camera.But no idea about how to rotate the camera around the object.

Share this post

Link to post
Share on other sites
I tried to change the camera position as you suggested then my volume is going out of screen.

here is my code to set view matrix and projection matrix.

//Set the View Matrix
D3DXMATRIXA16 matView;
D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -3.0f );
D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMATRIX yawpitchMatrix;
D3DXMatrixRotationYawPitchRoll &yawpitchMatrix,m_stRenderingParams.m_fOrbitY,m_stRenderingParams.m_fOrbitX,0.0);
D3DXVec3TransformCoord(&vUpVec ,&vUpVec , &yawpitchMatrix);

vFromPt = vLookatPt + vUpVec * 1; D3DXMatrixLookAtLH( &matView, &vFromPt, &vLookatPt, &vUpVec );
m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// Set the projection matrix
FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height;
D3DXMatrixOrthoLH( &matProj,fAspect,1.0f,-5.0f, 5.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

Share this post

Link to post
Share on other sites
You don't usually want to rotate the camera around the object, you want to rotate the object around the camera.

Set your view matrix up as normal, at say (0, 0, -10) looking at (0, 0, 0), and then each frame you do the following (Assuming your object is centred at (0, 0, 0):

D3DXMATRIX matRot, matTrans, matFinal;
D3DXMatrixRotationY(&matRot, fAngle);
D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, 25.0f);
D3DXMatrixMultiply(&matFinal, &matRot, &matTrans);
pDevice->SetTransform(D3DTS_WORLD, &matFinal);

Where fAngle is the angle to rotate the object by, in radians (You'll want to increase it each frame).

I'd recommend you read up on matrix maths a bit before going much further, or you'll just get more and more confused.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this