View Full Version : Rotate a vector about another vector?

TolTol

01-08-2003, 03:32 AM

Hello there,

I need some help with rotating vectors. I'm building a flight simulator and when the plane is rolling left or right I need to rotate the lift vector(up) around the thrust vector(straight out).

I think I have to do it using cos, sin and tan, but not sure how.

Any help would be muchly appreciated.

JustHanging

01-08-2003, 04:22 AM

Search google for quaternions, they are perfect for this kind of stuff.

-Ilkka

jebus

01-08-2003, 04:40 AM

read this (http://www.makegames.com/3drotation) . the part that talks about "other ways to make a rotation matrix" describe a simple formula for creating a rotation matrix using an arbitrary axis and angle. in your case the axis is thrust. any vector you multiply by this matrix will be rotated accordingly. i've done some extra reading and this formula was derived from quaternions, but it's very easy to use and wrap up into 1 function.

jebus

Halcyon

01-08-2003, 08:02 PM

I was wondering if you could just do this with a call to glRotate*(...). I believe that it lets you rotate something around any given axis. So if you had a vector called a and another called b and you want to rotate a around b...can't you just make the call:

glRotatef(angle,b.x,b.y,b.z)?

Does anyone know if you could do that?

-halcyon

Halcyon

01-08-2003, 08:14 PM

I just tested it and it does work! You can just use the glRotate*() call and specify the axis like i put in the post above!

- Halcyon

shinpaughp

01-08-2003, 10:16 PM

Try using vector addition. Set up unit vectors for each axes x', y', z'. A change in roll or rotation about the z' axes would result in an angular deflection of both x' and y' axes. Such that new x' would have x' vector + tan(angle) * y' vector, and new y' would have y' vector + tan(angle) * x' vector. This is for each axes of rotation so if you have rotation about many axes at same time you add them all up. The final normalized unit vectors would give you your transform matrix. In OpenGL the matrix would be:

| x'(x) x'(y) x'(z) 0 |

| y'(x) y'(y) y'(z) 0 |

| z'(x) z'(y) z'(z) 0 |

| 0 0 0 1 |

Sorry for so many edits. Gave too much info the first time around. Angles for flight simulator can be easily derived from the vectors relative to global coordiantes.

[This message has been edited by shinpaughp (edited 01-09-2003).]

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.