View Full Version : point vector rotation
03-25-2002, 12:50 PM
I have a point in space and a vector pointing towards another point. I want to rotate an object about the resulting axis.
Could somebody please send me a snippet on how to do that?
Thanks very much,
[This message has been edited by mphanke (edited 03-25-2002).]
use glRotatef(angle, Vx, Vy, Vz) where V is the vector to the other point and angle is the angle to rotate around that axis/vector.
03-26-2002, 12:13 AM
Hi, thanks for that reply but what I have to compute is the physical movement of the object. What I need is the mathematics behind that glRotate().
I'll try to make it more clear:
I*<---*I <- this is where I want to rotate
I V I the object
[This message has been edited by mphanke (edited 03-26-2002).]
03-26-2002, 02:07 AM
it is all very basic vector/matrix math
(you may also use quarternions, but personally i do not think they are good for anything, 'cause you can achieve the same effects using matrices)
take a look here and you will find all you need:
if this is not good enough for you search google for 'rotation arbitrary axis'
03-26-2002, 10:13 AM
Thanks satan for pointing out this resource of information.
Are you looking for the location where you will be in the next frame from the axis of rotation and the axis of rotation.
I was working on the same problem last weekend. I am in the process of testing it but my system is doing some funky stuff... I try to open any program and it says that it is "Not responding" in the running process under win98. I am also getting an error that my GL program is still running when I had terminated the program. So I have to reboot my system before I can recompile the program again. I konw the code is fine. I was compiling it on my sisters compter last weekend and it was working fine.
Anyway I am using a local coordinate system where I have the vector Z_UP <0,0,1> and I have another vector that contains the direction on the XY plane (Proj <cos(angle), sin(angle), 0> ). I do not care about the length of the vector. I then find the cross product between the Z_UP and Proj. This produces another vector perpendicular to the direction on the XY plane. I then take the crossproduct of the vector from the previous cross product and my rotation axis (my true up vector of the object). Thus giving me the direction that I am heading in my local coordinate system. Now all I have to do is change the vector's magnitude to the proper distance that I went in that time frame and add the vector to my last position in world X, Y, Z coordinates.
Hope this is clear. I was pulling it all from memory and remember I have not fully tested it but in theory it should work. NOTE: there are special cases since we took Z_UP to be the vector <0,0,1>. Doing a crossproduct with another vector that is paralell to Z_UP or lies in the XY plane. will have some problems with the above.
I also have know idea about how fast this algorithm is compared to multiplying matrixies together.
03-27-2002, 06:43 AM
Cool site satan!! http://www.opengl.org/discussion_boards/ubb/smile.gif
03-27-2002, 12:20 PM
thanks for your help, I solved my problem with your help and some of my old math books. I have alot of funcs done. So if someone would like to get the source of rotation funcs, throw me some lines I will mail it asap!
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.