View Full Version : glRotatef and rotation around arbitrary axis

sizeof

10-23-2010, 11:32 PM

Hi all,

My primary task to rotate around arbitrary axis, but I can't use glRotatef because some other calculations after transformations to be done. So I need manually transform each vector by rotation matrix. The problem is that my manual matrix taken from here (http://web.archive.org/web/20041029003853/http:/www.j3d.org/matrix_faq/matrfaq_latest.html#Q38) and here (http://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_given_an_axis_and_ an_angle) is not equal to matrix that glRotatef makes.

Which matrix glRotatef use, isn't standard one?

Anirban Talukdar

10-23-2010, 11:54 PM

You can directly manipulate ModelView matrix. So after all the calculations you can directly set the modelview matrix to OpenGL matrix stack.

Regards

Anirban Talukdar

sizeof

10-24-2010, 12:48 AM

You can directly manipulate ModelView matrix. So after all the calculations you can directly set the modelview matrix to OpenGL matrix stack.

OK that fine but my question was, how can I reproduce manually glRotate? Which matrix glRotate uses?

ZbuffeR

10-24-2010, 12:55 AM

RTFM :

http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

Alfonse Reinheart

10-24-2010, 01:12 AM

The problem is that my manual matrix taken from here and here is not equal to matrix that glRotatef makes.

How did you make that determination? I hope you didn't just test the floats to see if they were equal.

sizeof

10-24-2010, 02:45 AM

How did you make that determination? I hope you didn't just test the floats to see if they were equal.

Actually that what I did .. But before in both cases I loaded identity matrix. Also in both cases I used same rotation vector and angle ...

Alfonse Reinheart

10-24-2010, 04:20 AM

Actually that what I did

That's what I figured.

You can never expect to get binary-identical floating-point values like that. Whatever the driver is doing to compute glRotatef, it's almost certainly not the exact same floating-point code you are using. As such, it will likely not provide the exact same, binary-identical floating-point results.

Just look at the two matrices, in text form. If they look reasonably close enough (within ~4-5 significant digits), then your rotate function is probably working.

sizeof

10-24-2010, 05:00 AM

That describes the difference :) So the problem somewhere in my code ... I'll check it

Thanks everyone

mhagain

10-24-2010, 08:57 AM

glRotate can go around an arbitrary axis, and you can retrieve the resulting matrix (for further calculation) with glGetFloatv. This won't stall the pipeline as none of this is performed in hardware - only the final multiplication of position by MVP is.

Are you normalizing your axis vector before doing your own rotation? The spec for glRotate requires this, so if you want your code to match as closely as possible you should also be doing it.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.