# Little problem with camera rotation about X

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. When i rotate camera about X axis and eye -- lookAt angle is between 90 and 270 degree, all scene is head over :-/ Petr

##### Share on other sites
well, when u rotate the camera, u rotate the world.

u dont have to change the eye and lookat.

##### Share on other sites
Quote:
 Original post by ramywell, 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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by ramyby 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 ?

##### Share on other sites
Quote:
 How can i compute angle between two vectors ?

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

##### Share on other sites
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.

##### Share on other sites
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 ?

##### Share on other sites
Quote:

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);

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633405
• Total Posts
3011680
• ### Who's Online (See full list)

There are no registered users currently online

×