camera rotation

Started by
10 comments, last by supagu 20 years, 9 months ago
no, because the view matrix is inverted to move everything else the opposite way. thats why you keep and transform a seperate matrix and inverse it when you need to set the view matrix.
f@dzhttp://festini.device-zero.de
Advertisement
Hi

Try something like this.

Every frame create three matrixes that will become one matrix representing the view matrix.

Create one rotation matrix for X and Y axis. Thats 2 of 3.
D3DXMatrixRotationX (&viewTransformTemp, valueX);
viewRotationX *= viewTransformTemp;

D3DXMatrixRotationY (&viewTransformTemp, valueY);
viewRotationY *= viewTransformTemp;



Then create the camera translation(transform):

D3DXMatrixTranslation (&viewTransformTemp, valueX, valueY, valueZ);
viewTransform *= viewTransformTemp;


(Notice: the last frames data must be held to achieve an nice camera animation).

Now multiply the three matrixes together to get your view matrix(well not actually yet but getting closer).

viewMatrix = viewRotationX*viewRotationY*viewTransform;

Now every frame zero the D3DXMatrixLookAtLH() fucntion required componentes like Eye position, view target, view normal etc.. what ever you need to create the finel view matrix.

viewEyePosition = D3DXVECTOR3 ( 0.0f, 0.0f, 0.0f);
viewTarget = D3DXVECTOR3 ( 0.0f, 0.0f, 10.0f);
viewNormal = D3DXVECTOR3 ( 0.0f, 10.0f, 0.0f);

Something like above. Now multiply every component with the viewMatrix MATRIX(we just created it).
D3DXVec3TransformCoord (&viewEyePosition, &viewEyePosition, &viewMatrix);
D3DXVec3TransformCoord (&viewTarget, &viewTarget, &viewMatrix);
D3DXVec3TransformNormal (&viewNormal, &viewNormal, &viewMatrix);

Now your eye position, view target and view normal has been set to curent "view space". Then just multiply the components into a matrix and pass it to DirectX.

D3DXMatrixLookAtLH (&viewMatrix, &viewEyePosition, &viewTarget, &viewNormal);
DX9Interface->gmD3DDEVICE9->SetTransform(D3DTS_VIEW, &viewMatrix);

Voila.. But wait this doesn''t rotate the camera. Well yes it doesn''t, but hey now you can assign value to X, Y rotation, camera translation etc.. All you have to do is to pass to the rotation matrix operations and the translation operation values and the camera will start to come. Use functions like sin() and cos() to create and circle that will move your camera. As the last tip put every operation in their own function. So that you can alter the rotation and traslation matrixes as much as you want untill you are ready to create the final view matrix for DirectX.
Adrian Simionescu

This topic is closed to new replies.

Advertisement