glRotatef and rotation around arbitrary axis

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 and here is not equal to matrix that glRotatef makes.

Which matrix glRotatef use, isn’t standard one?

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

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

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

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.

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 …

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.

That describes the difference :slight_smile: So the problem somewhere in my code … I’ll check it

Thanks everyone

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.