Sign in to follow this  
PetrCBR

Little problem with camera rotation about X

Recommended Posts

PetrCBR    126
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.

Share this post


Link to post
Share on other sites
ramy    148
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 this post


Link to post
Share on other sites
PetrCBR    126
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 ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
How can i compute angle between two vectors ?


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

Share this post


Link to post
Share on other sites
Drakex    273
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 this post


Link to post
Share on other sites
PetrCBR    126
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 this post


Link to post
Share on other sites
Drakex    273
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);

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