Little problem with camera rotation about X

Started by
7 comments, last by Drakex 18 years, 8 months ago
Hi. When i rotate camera about X axis and eye -- lookAt angle is between 90 and 270 degree, all scene is head over :-/ Petr
Advertisement
well, when u rotate the camera, u rotate the world.

u dont have to change the eye and lookat.
Quote:Original post by ramy
well, when u rotate the camera, u rotate the world.

u dont have to change the eye and lookat.


In aircraft's 3rd person camera is better way to move and rotate camera, not all scene, models etc.
by rotating the world that doesnt rotate the models. it simply rotates the world, u draw the aircraft, and u return the world back as it should be by identity. that does rotate entire models. i dont think it does that.

and u can just multiply the aircraft vertices with the rotation, but i think thats slower than modifing the world matrix.
Quote:Original post by ramy
by rotating the world that doesnt rotate the models. it simply rotates the world, u draw the aircraft, and u return the world back as it should be by identity. that does rotate entire models. i dont think it does that.

and u can just multiply the aircraft vertices with the rotation, but i think thats slower than modifing the world matrix.


Ohh ... little misunderstanding here. I'm have a aircraft model and 3rd person camera. When i moving with aircraft, need to move with camera too (camera is locked to aircraft entity to follow it). When i set pitch of aircraft between 90 and 270 degrees, all scene is head over. The camera lock must be separate from all other models and must follow only selected entity.

How can i compute angle between two vectors ?
Quote:How can i compute angle between two vectors ?


Use the dot product of the 2 vectors to find the angle in between.

Quote:How can i compute angle between two vectors ?


acos(dot(v1,v2)), in simple algebraic syntax. Or, in D3DX, acos(D3DXVec3Dot(&v1,&v2)).

However, I might suggest that you don't use the dirty, dirty method of LookUpRight camera rotation. It's confusing and counterintuitive. You can rotate your camera just like any other object. Just make the rotation matrix using the camera's angles, and use D3DXMatrixInverse on it before applying it to the device's View matrix.
_______________________________________________________________________Hoo-rah.
Quote:Original post by Drakex
Quote:How can i compute angle between two vectors ?


acos(dot(v1,v2)), in simple algebraic syntax. Or, in D3DX, acos(D3DXVec3Dot(&v1,&v2)).

However, I might suggest that you don't use the dirty, dirty method of LookUpRight camera rotation. It's confusing and counterintuitive. You can rotate your camera just like any other object. Just make the rotation matrix using the camera's angles, and use D3DXMatrixInverse on it before applying it to the device's View matrix.


Thanks to your advice, but how i add look at position into matrix ? How works D3DXMatrixLookAtLH ?
Quote:Thanks to your advice, but how i add look at position into matrix ?


Position your camera where you did before (behind your plane or whatever). Then use the following code to calculate the angles for the camera (these angles work for a YXZ [yaw-pitch-roll] rotation order):

float dx=plane_x-camera_x;float dy=plane_y-camera_y;float dz=plane_z-camera_z;float camera_angle_y=atan2(dx,dz);float camera_angle_x=-atan2(dy, sqrt((dx*dx)+(dz*dz)) );


camera_angle_x and camera_angle_y will be in radians. Use the D3DXToDegree() macro to convert these to degrees, if you need them in degrees.

Then, make your camera's transformation matrix, invert it, and set it to View:

D3DXMATRIX matPos, matRot, matView;D3DXMatrixTranslation(&matPos,camera_x,camera_y,camera_z);D3DXMatrixRotationYawPitchRoll(&matRot,camera_angle_y,camera_angle_x,0);D3DXMatrixMultiply(&matView,&matRot,&matPos);D3DXMatrixInverse(&matView,NULL,&matView);D3DDevice->SetTransform(D3DTS_VIEW,&matView);
_______________________________________________________________________Hoo-rah.

This topic is closed to new replies.

Advertisement