PDA

View Full Version : Rotations about an arbitrary axis

PeterK
03-27-2000, 04:59 PM
I have a vector, v = (v1,v2,v3), that I want to rotate about another vector r = (r1,r2,r3). I want to know the result, p = (p1,p2,p3), of this transfomration.

Is there an easy way of doing this?

glRotate3d does this automatically but I don't know how to get the result of its calculation.

Can I get OpenGL to do the calculation for me and return the result?

dmy
03-27-2000, 10:47 PM
sure! the steps are:
-setup a identity matrix
-retrieve the translation vector of the matrix

in code:

glMatrixMode(GL_MODELVIEW_MATRIX);

glTranslatef(v1,v2,v3);
glRotatef(degrees,r1,r2,r3);

float matrix[4][4];
glGetFloatv(GL_MODELVIEW_MATRIX,(float *)matrix);

your transformed point is hold into the last row of matrix, matrix[3], so:

p1=matrix[3][0]
p2=matrix[3][1]
p3=matrix[3][2]

Dolo/\/\ightY

[This message has been edited by dmy (edited 03-27-2000).]

PeterK
03-28-2000, 08:57 AM
Thanks for your help DMY -I really appreciate it.