Jump to content
  • Advertisement
Sign in to follow this  

DirectX Camera rotation

This topic is 4111 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

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
the way i do it (prob not the best):

cameraPos = targetPos + Vector3.TransformCoordinate( forwardDir, Matrix.RotationYawPitchRoll( yaw, pitch, 0.0f ) ) * radius;

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!