rotate camera on xyz axis?

Started by
3 comments, last by Shwanger 16 years, 10 months ago
VS.NET C++ DirectX I'm having trouble rotating my camera view correctly. The game is set in outer-space, so I need to be able to rotate fully in any direction. For example, if I press UP, then I want the camera view to move up relative to its current view (not necessarily up on the Y axis). And the same for left, right, and down. Currently I'm using a 3D vector for my camera position, and another 3D vector for its view/look-at point. I AM able to rotate the camera on the x, y, and z axis, but that's only good if the camera is looking straight down one of the axis, which is almost never. Thanks for any help.
Advertisement
there is an easy function to rotate the camera... except it may not be compatible with what you are doing...

D3DXMatrixRotationYawPitchRoll(&matrix, yaw, pitch, roll);
the matrix will have to be applied to the world transform

hope this helps at all... not sure if this is what you wanted
It sounds like you might have a case of the gimbal lock. Describe how you apply a rotation to your view vector. If it is like this:

if(UP_ARROW_PRESSED)
view.rotateX(delta_rotate);
if(LEFT_ARROW_PRESSED)
view.rotateY(delta_rotate);

etc, that ain't gonna work. What you should be doing is contructing a rotation matrix like Shwanger suggests and apply that to your look vector rather than try to twiddle with the Euler angles directly.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Thanks guys. D3DXMatrixRotationYawPitchRoll(&matrix, yaw, pitch, roll) appears to be what I'm looking for. I'm not really sure how to calculate the yaw, pitch, and roll parameters. Hopefully that'll come to me after checking a few references.
the yaw pitch and roll are in radians... so you could input in radians(i think 3.14 every 180 degrees) or however many degrees you want to rotate... use D3DXToRadian(degree);
so you could do it like every time you press the left key... it subtracts(or adds not sure) 10 degrees to yaw... i like using degrees and then converting it to radian... i think its much easier to work with than radians...

glad i could help :)

This topic is closed to new replies.

Advertisement