View Full Version : rotation about an arbitrary vector

angryGLfan

04-01-2002, 12:32 PM

does anyone know how to develop a matrix to rotate a vertex about an arbitrary vector like int openGL.

glRotatef(angle, vector.x, vector.y, vector.z);

where 'vector' is the vector to be rotated around.

thanks

If you first rotate the z-axis of your coordinate system to your arbitrary vector then you can

glRotatef(angle, 0.0, 0.0, 1.0) to get what you want.

If you want some details on how to rotate the z-axis to an arbitrary vector see

http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

for an explaination and source.

coredump

04-02-2002, 05:24 AM

http://www.makegames.com/3drotation/

look here under the section "Other Ways to Build a Rotation Matrix". there are some equations there to help you. you set a few variables using the axis(x,y,z) and the angle(in radians). then it's just plug'n'chug into the matrix equation.

good luck

b

jrbcast

04-03-2002, 11:19 PM

Originally posted by angryGLfan:

does anyone know how to develop a matrix to rotate a vertex about an arbitrary vector like int openGL.

glRotatef(angle, vector.x, vector.y, vector.z);

where 'vector' is the vector to be rotated around.

thanks

Hi,

I understand that you want to get the Matrix wich perfoms that rotation, isnīt it?.

If it is, you must think that OpenGL gives you glRotate to make your work easier but In a lower level It is calculating that matrix so you can get it like this:

// Will store your matrix

GLdouble mvmatrix[16];

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

// Put matrix to Identity

glLoadIdentity();

// Now actualizes the identity matrix with

// the rotation matrix corresponding to the

// rotation you want.

glRotatef(angle,axe.x,axe.y,axe.y);

// Now you want to retrieve it so:

glGetDoublev( GL_MODELVIEW_MATRIX , mvmatrix );

glPopMatrix(); // Returns to older matrix

I think It should work because I have used it. I would advice you to read about glGet... operations, they are very usefull.

There are other ways to calculate the matrix but I think that if you can use the opengl tools why to go around of it? ;-)

Hope It works.

Bye

Jambolo

04-04-2002, 09:02 PM

Originally posted by angryGLfan:

does anyone know how to develop a matrix to rotate a vertex about an arbitrary vector like int openGL.

Try this: http://www.google.com/search?sourceid=navclient&querytime=KQMXjB&q=rotation+arbitrary+axis

Deiussum

04-05-2002, 07:03 AM

If I understand the question correctly, you want to understand the math involved in an arbitrary rotation? The RedBook tries to explain the math involved for doing this. A link to that portion can be found here:

http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html

I have to admit, that the formulas presented there for arbitrary rotation can be a bit daunting. Awhile ago, I had started my own little library for performing matrix operations, and I have code somewhere for doing the calculation. I'll have to wait until I get home to find it for ya, though.

I haven't looked at the other links provided, so maybe they explain it better.

Deiussum

04-06-2002, 02:14 PM

Here's a code snippet that should help if what you're trying to do is create your own glRotate-like routine. It's not complete code, but you should be able to figure out what things like my Matrix4x4 and Matrix3x3 structs, and the DEGTORAD macros are.

void mat4Rotate(Matrix4x4 *mat, float angle, float x, float y, float z)

{

float len, ux, uy, uz;

float sinAng, cosAng;

Matrix3x3 S, uuT;

memset(mat, 0, sizeof(Matrix4x4));

len = (float)sqrt(x*x + y*y + z*z);

ux = x/len;

uy = y/len;

uz = z/len;

S.m11 = 0.0;

S.m12 = -uz;

S.m13 = uy;

S.m21 = uz;

S.m22 = 0.0;

S.m23 = -ux;

S.m31 = -uy;

S.m32 = ux;

S.m33 = 0.0;

sinAng = (float)sin(DEGTORAD(angle));

cosAng = (float)cos(DEGTORAD(angle));

uuT.m11 = ux*ux;

uuT.m12 = ux*uy;

uuT.m13 = ux*uz;

uuT.m21 = uy*ux;

uuT.m22 = uy*uy;

uuT.m23 = uy*uz;

uuT.m31 = uz*ux;

uuT.m32 = uz*uy;

uuT.m33 = uz*uz;

mat->m11 = uuT.m11 + cosAng*(1.0f-uuT.m11) + sinAng*S.m11;

mat->m12 = uuT.m12 + cosAng*(0.0f-uuT.m12) + sinAng*S.m12;

mat->m13 = uuT.m13 + cosAng*(0.0f-uuT.m13) + sinAng*S.m13;

mat->m21 = uuT.m21 + cosAng*(0.0f-uuT.m21) + sinAng*S.m21;

mat->m22 = uuT.m22 + cosAng*(1.0f-uuT.m22) + sinAng*S.m22;

mat->m23 = uuT.m23 + cosAng*(0.0f-uuT.m23) + sinAng*S.m23;

mat->m31 = uuT.m31 + cosAng*(0.0f-uuT.m31) + sinAng*S.m31;

mat->m32 = uuT.m32 + cosAng*(0.0f-uuT.m32) + sinAng*S.m32;

mat->m33 = uuT.m33 + cosAng*(1.0f-uuT.m33) + sinAng*S.m33;

mat->m44 = 1.0;

}

i believe youre all making it to complicated

just do straight linear algebra

glTranslatef(position_To_rotate_around.x,position_ To_rotate_around.y,position_To_rotate_around.z)

glRotatef(angle,axis.x, axis.y,axis.z);

(btw u might need to first do a loadidentity)

Deiussum

04-08-2002, 04:42 AM

Originally posted by zed:

i believe youre all making it to complicated

That could be possible. The original poster wasn't the most clear on what he wanted and hasn't seemed to stop by to clarify yet. I was under the impression he wanted to understand the math that OpenGL does, though. Hence his words "like int OpenGL."

deiussum after reading the original post more clearly youre correct + i was wrong, i must of just been reading the topics title, anyways i believe the original poster like elvis has left the building

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.