# OpenGL Creating an own glRotatef

This topic is 3899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, For my matrix library I made a rotate function based on the references I found of the glRotatef function. This is my implementation:
inline void Rotate(float angle, float x, float y, float z)
{
vector3f axis(x, y, z);
axis.Normalize();

matrix4f rot; // auto set to identity

float b = angle;

float c = cosf(b);
float ac = 1.00f - c;
float s = sinf(b);

rot.m[0] = axis.x * axis.x * ac + c;
rot.m[1] = axis.x * axis.y * ac + axis.z * s;
rot.m[2] = axis.x * axis.z * ac - axis.y * s;

rot.m[4] = axis.y * axis.x * ac - axis.z * s;
rot.m[5] = axis.y * axis.y * ac + c;
rot.m[6] = axis.y * axis.z * ac + axis.x * s;

rot.m[8] = axis.z * axis.x * ac + axis.y * s;
rot.m[9] = axis.z * axis.y * ac - axis.x * s;
rot.m[10] = axis.z * axis.z * ac + c;


This should give the same result as:
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glRotatef(angle * 180 / 3.14, x,y,z);
glGetFloatv(GL_MODELVIEW_MATRIX, rot2.m);
glPopMatrix();


But it doesn't :| What am I doing wrong?

##### Share on other sites
Quote:
 Original post by Revelation60But it doesn't :|

How do the values differ?

##### Share on other sites
All I can think of is that you got the major order wrong. So where m[1] in your program is the component first from the left at the top, it should be first from the top at the left. I would check, but I can't remember whether GL matrices are row-major or column-major, and it doesn't seem to mention in that Rotate reference.

##### Share on other sites
I've solved it :) The problem was the way I multiplied the rotation matrix.

It should be M = R * M instead of M = M * R.

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009382
• ### Who's Online (See full list)

There are no registered users currently online

×