GLROTATE(3G)

πŸ“¦ version 1.1, in centos-stream 9, fedora 43, fedora 44

πŸ’« GLROTATE β€” bestie edition πŸ’«

okay so this is glRotated and glRotatef from the 3G manual (yes that's the OpenGL one, we're fancy here πŸŽ€). Sit down, grab a strawberry drink πŸ“, and let's spin some matrices together.


✨ NAME ✨

glRotated, glRotatef β€” multiply the current matrix by a rotation matrix. that's it. that's the whole job. iconic behavior honestly πŸ‘‘


🧚 C SPECIFICATION 🧚

void glRotated( GLdouble angle,
                GLdouble x,
                GLdouble y,
                GLdouble z )
void glRotatef( GLfloat angle,
                GLfloat x,
                GLfloat y,
                GLfloat z )

one's double, one's float. pick your fighter πŸ’…


🌸 PARAMETERS 🌸

  • angle β€” the angle of rotation, in degrees. not radians. degrees bestie, we're not doing trig homework here 😭
  • x, y, z β€” the x, y, and z coordinates of a vector, respectively. yes respectively, they're in order, relax 🫢

πŸ’– DESCRIPTION πŸ’–

glRotate produces a rotation of angle degrees around the vector (x,y,z). so like, you pick an axis, you pick how far to spin, and boom, rotation ✨

The current matrix (see glMatrixMode) gets multiplied by a rotation matrix, and the product replaces the current matrix β€” as if glMultMatrix were called with the following matrix as its argument:

                   x2(1βˆ’c)+c  xy(1βˆ’c)βˆ’zs xz(1βˆ’c)+ys 0
                  ⎝yx(1βˆ’c)+zs y2(1βˆ’c)+c  yz(1βˆ’c)βˆ’xs 0⎠
                   xz(1βˆ’c)βˆ’ys yz(1βˆ’c)+xs z2(1βˆ’c)+c  0
                       0          0          0      1

Where c=cos(angle), s=sin(angle), and ||(x,y,z)||=1 (if not, the GL will normalize this vector). so don't stress about your vector being unit length, it's got you 🫢

If the matrix mode is either GL_MODELVIEW or GL_PROJECTION, all objects drawn after glRotate is called are rotated. every single one. the whole friend group is coming with you πŸ’ƒ

Use glPushMatrix and glPopMatrix to save and restore the unrotated coordinate system. this is your "wait, put it back the way it was" button and it is SO important, no cap.


πŸ‘‘ NOTES πŸ‘‘

This rotation follows the right-hand rule, so if the vector (x,y,z) points toward the user, the rotation will be counterclockwise. right hand rule besties, it's giving physics class but make it cute πŸŒ€


πŸ’€ ERRORS πŸ’€

GL_INVALID_OPERATION is generated if glRotate is executed between the execution of glBegin and the corresponding execution of glEnd.

⚠️ so like… do NOT call this between glBegin and glEnd. the GL will simply not have it and will throw hands. it's giving "read the room" 😀

πŸ”₯ ASSOCIATED GETS πŸ”₯

  • glGet with argument GL_MATRIX_MODE
  • glGet with argument GL_COLOR_MATRIX
  • glGet with argument GL_MODELVIEW_MATRIX
  • glGet with argument GL_PROJECTION_MATRIX
  • glGet with argument GL_TEXTURE_MATRIX

🌈 SEE ALSO 🌈

glMatrixMode(3G), glMultMatrix(3G), glPushMatrix(3G), glScale(3G), glTranslate(3G)


and that's the whole page bestie!! this was GLROTATE(3G) from the 3G manual β€” same title, same section, just delivered with the energy it deserved. now go rotate something and make it the main character πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from