1
votes

I have problem understanding the mechanism of glrotatef or how does it work, after doing some research I found out that it consists it takes 4 variables, which are the angle that I use to rotate, 1 or 0 for x axis, 1 or 0 for y axis, and 1 or 0 for z axis.

answering of the following questions will help me understanding the glrotatef

the questions are

  1. if we're talking about a square that we want to rotate it, the angle that we send to the function glrotatef, will it work on vertex points of the square, or on the lines to rotate them ?
  2. what is the difference between writing the function glRotatef one time, and writing it four times when using it on rotating a square, does every one glRotatef function work on one side of the square ?
  3. how can I use glrotatef & gltranslatef to rotate a square around itself without moving from it's place.
  4. can anyone explain in the simplest way how does glrotatef work, and give some examples without relating to any part of codes because I'm a newbie and I didn't understand most of the codes written on stackoverflow questions about glrotatef.
1

1 Answers

0
votes

Before reading the answers of question, I suggest you to read how translate/rotate/scale is done with model matrix

When you need to transform your object, you simply perform operation for each vertex that your object has.

P = [x,y,z,1] -- your point in 3D
M = [..] -- your 4x4 rotation matrix

M * P -- your rotation operation

In the light of references I provide, here are the very simplified answers :

  1. When you do rotate, your each vertex coordinate position will be recalculated and Opengl will generate your square again from the new 4 vertex.
  2. There is no difference between rotating 1 times 60 degree and 2 times 30 degree you can simply control it by doing the math (check the rotation matrix link):

M1 = your 60 degree rotation matrix

M2 = your 30 degree rotation matrix

M1 = M2 * M2 => M1 * P = M2 * M2 * P

  1. Here there is my answer : Rotating around a point different from origin
  2. Rotatef() function is just creates a 4x4 rotation matrix according to your parameters you provided and it updates your ModelView matrix by multiplying with your rotation generated.