Pitch camera or rotate by x-axe
Hello all,
I got a problem which is difficult to explain:
I want to rotate my cam around y and x axes. The rotation by y-axe is solved.
I go like this:
- first I get the direction via "view_look - view_start" in "direction"
- after that I normalize the vector and rotate it by "D3DXMatrixRotationY" with an angle of 90 degrees (so I get the vector to the side :-)
- I transform it with my "direction" and then move in given steps into that direction
- after all I add the new "direction"-vector to the old "view_look" and "view_start" and it turns around itself :-)
So far so good ...
I tried that with the x-axe too, to pitch the camera, but everytime it reaches the bottom or the top of the world, it turns around and inverts its view, so that on the other side (in the back) the camera is not upside down but normal ...
I hope I could explain this with my slight english-knowledge and anyone could help me out.
Have a nice day,
:-) Python
Spin the wheel of fortune - or learn to navigate.
The problem you are having is that you are not actually always rotating on the x -axis, you want to rotate on the right vector of the camera.
The way I do it in my engine is to calculate what the new view vector is and then build the matrix using a function similar to D3DXMatrixLookAtLH to form the matrix( I wrote my own version since i have the option to use DX or OpenGL). To calculate the new view vector I use:
The way I do it in my engine is to calculate what the new view vector is and then build the matrix using a function similar to D3DXMatrixLookAtLH to form the matrix( I wrote my own version since i have the option to use DX or OpenGL). To calculate the new view vector I use:
// Find the direction we are facing Vector3d View = (_view - _position); float cosTheta = cos(amount); float sinTheta = sin(amount); float x, y, z; x = _strafe.X; y = _strafe.Y; z = _strafe.Z; // Find the new x position for the new rotated point NewView.X = (cosTheta + (1 - cosTheta) * x * x) * View.X; NewView.X = NewView.X + ((1 - cosTheta) * x * y - z * sinTheta) * View.Y; NewView.X = NewView.X + ((1 - cosTheta) * x * z + y * sinTheta) * View.Z; // Find the new y position for the new rotated point NewView.Y = ((1 - cosTheta) * x * y + z * sinTheta) * View.X; NewView.Y += (cosTheta + (1 - cosTheta) * y * y) * View.Y; NewView.Y += ((1 - cosTheta) * y * z - x * sinTheta) * View.Z; // Find the new z position for the new rotated point NewView.Z = ((1 - cosTheta) * x * z - y * sinTheta) * View.X; NewView.Z += ((1 - cosTheta) * y * z + x * sinTheta) * View.Y; NewView.Z += (cosTheta + (1 - cosTheta) * z * z) * View.Z; _view = _position + NewView;
I''ll have a look on it .... btw: I meant that I calculate only the look-vec, the start-vec stays the same ... :-)
Spin the wheel of fortune - or learn to navigate.
Spin the wheel of fortune - or learn to navigate.
Sorry forgot to mention you find the strafe vector by taking the cross product of the view direction and the Upvector of the world.
This may be my problem. Could you explain the use of the upvector in that special case?
Thanks a lot in advance,
:-) Python
Spin the wheel of fortune - or learn to navigate.
Thanks a lot in advance,
:-) Python
Spin the wheel of fortune - or learn to navigate.
I just always use the constant upvector of (0, 1, 0) since y is up in my world. Unless you want to be able to roll and fly upside down like you would be able to in a plane. Just make sure that your view vector is a unit vector before taking the cross product. The cross product will return a unit vector in the direction of the right of the right vector.
Then just plug it in to the code I posted earlier.
I had a lot of trouble getting this right!
Then just plug it in to the code I posted earlier.
I had a lot of trouble getting this right!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement