Sign in to follow this  

Rotating and moving a vector.

This topic is 2831 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

Hi guys. This is my first post here, I've read a lot about the topic and was thinking a lot about the problem but couldn't find a correct solution. What I would like to do is to rotate my camera with mouse and move it along the vector in which the camera is pointing. I guess this is a very common problem but I couldn't find a single tutorial how to do this. I was reading here: http://en.wikipedia.org/wiki/Rotation_%28mathematics%29 and rotation in 2D is pretty straightforward but when it comes to the 3D rotation I am lost. I am using an OpenGL in my case and I know that I can use glRotate(); to achive rotation but after this I do not know the new vector. This is another thing which worries me: OpenGL is making a rotation for me but I have to make rotation on my own to know the newly pointed vector. So the same operation is made twice and my calculations can be different (in terms of precision) to the ones performed by OpenGL. How to solve this problem? I was thinking about two solutions to the rotation problem: 1. Multiply my vector by a rotation matrix but I do not know how to construct such matrix. 2. Rotate a vector around three axises separately and then combine a result. The movement problem: When I have a new vector I would like to move my camera along this vector by some unit distance. Am I thinking correctly that to do this I need to: 1. Normalize the vector. 2. Multiply normalized vector by the unit distance 3. Add the result to the oryginal vector Thanks for your time.

Share this post


Link to post
Share on other sites
If you would like to construct a rotation matrix that you can apply to your vector, this is fairly simple to do. On this article for Rotation Matrix, if you scroll down the page it gives the formula for converting an axis/angle rotation to a 3x3 matrix under "Rotation matrix given an axis and an angle". You can turn this into 4x4 OpenGL compatible matrix by adding a row and column of zeros on the bottom and right and setting element 15 to 1.

If you want to move any object "forward" after you rotate it, then you can just translate it in the negative z direction after you rotate it. Because the translation will always be applied to the object's local axis, negative z will always be "forward in the direction the object is pointing". You shouldn't really even need to maintain a separate direction vector. You can just use this transformation matrix to represent your object's position and orientation.

Because this is your camera you will of course have to invert the matrix, but I'm not sure if you need that explanation or not (please ask if you don't understand).

Share this post


Link to post
Share on other sites
Thank you.
I think I understand, however I am still having problems with correct behaviour of my camera.

Since now I have some working example in OpenGL, I will post the topic titled:
"Problems with camera movement and rotation" under OpenGL section.

If you could look at it I will be grateful,

thanks again.

Share this post


Link to post
Share on other sites

This topic is 2831 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