Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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);

        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:
        glRotatef(angle * 180 / 3.14, x,y,z);
        glGetFloatv(GL_MODELVIEW_MATRIX, rot2.m);

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

Share this post

Link to post
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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!