Sign in to follow this  

rotate camera on xyz axis?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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