Hey guys I was doing some work and got stuck on a certain question, can anyone help me?
I'm trying to analyze a piece of code and just got stumped on the last question
Comprehension Task 4: How does the function orientMe() makes the rotation possible and in fact *easy*? For this, you need to understand how functions gluLookAt() and glRotatef() work.
Also, discuss what you would had to do if you did not have these nice and powerful functions, to rotate a 3D scene.
and this is the code:
//This function is responsible for rotating about the y and x axis
void orientMe(float yRotate, float xRotate) {
//Load the identity matrix
glLoadIdentity();
//Set the camera
gluLookAt(x, y, z,
x+lx,y+ly,z+lz,
0.0f,1.0f,0.0f);
//Rotate about the y axis by yRotate degrees
glRotatef(yRotate, 0.0f, 1.0f, 0.0f);
//Rotate about the x axis by xRotate degrees
glRotatef(xRotate, 1.0f, 0.f, 0.f);
}
//This function controls what happens when special keys are pressed
void specialKeys(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT : sideAngle += 15; orientMe(sideAngle,upAngle); break;
case GLUT_KEY_RIGHT : sideAngle += -15; orientMe(sideAngle,upAngle); break;
case GLUT_KEY_UP : upAngle += 15; orientMe(sideAngle,upAngle); break;
case GLUT_KEY_DOWN : upAngle += -15; orientMe(sideAngle,upAngle); break;
}
}
//This function controls what happens when normal keys are pressed
void normalKeys(unsigned char key, int x, int y) {
switch (key) {
case 27 : exit(0); break;
case 's' : z += 2;
orientMe(sideAngle,upAngle); break;
case 'w' : z -= 2;
orientMe(sideAngle,upAngle); break;
}
}
//Reset the angles and views
case RESET :
sideAngle = 0;
upAngle = 0;
x = 0.0f;
y = 0.0f;
z = 11.0f;
orientMe (sideAngle, upAngle);
break;
void orientMe(float yRotate, float xRotate) {
//Load the identity matrix
glLoadIdentity();
//Set the camera
gluLookAt(x, y, z, x+lx,y+ly,z+lz, 0.0f,1.0f,0.0f);
//Rotate about the y axis by yRotate degrees
glRotatef(yRotate, 0.0f, 1.0f, 0.0f);
//Rotate about the x axis by xRotate degrees
glRotatef(xRotate, 1.0f, 0.f, 0.f);
}
orientMe function function just calling four functions.
1. To load matrix.
2. Set the camera.
3. Rotate about X axis
4. Rotate about Y axis.
all the above functions are updating/manipulating values stored in a matrix which represent a picture frame at given time.
we need to have code for the four function to give exact answer.
I don't see code for these functions in link given by you. If you provide the code here we will try to explain. Also please mark any specific piece of code or line where you got stuck.