I'm totally new to OpenGL and I'm working on a Sandbox game called CubeRealm. My problem you see is rotation. I've got it in my head that to rotate the 'camera' I just rotate all the scene by the negative value of the camera's rotational values. However so far it seems to not be working.
Here's the code snippets:
glPushMatrix();
lighting();
/*
(640^2)/(64^2)=amount of cubes on one 640x640 plane(409,600,4,096)
*/
//TODO: fix z axis problem for translating
glRotatef(-player.camera.rotation.x,1.0,0.0,0.0);
glRotatef(-player.camera.rotation.y,0.0,1.0,0.0);
glRotatef(-player.camera.rotation.z,0.0,0.0,1.0);
renderGrid();
glPopMatrix();
glutSwapBuffers();
//SNIPPET2...
case LOOK_UP:
if(player.camera.rotation.y!=-90.0){ //if they are not looking up
//make them look up
player.camera.rotation.y-=90.0;
//TODO: set direction the camera is facing in
}
break;
case ROTATE_LEFT:
if(player.camera.rotation.x!=0.0){
player.camera.rotation.x-=90.0;
//TODO: set direction the camera is facing in
}else{
player.camera.rotation.x=360.0;
player.camera.rotation.x-=90.0;
//TODO: set direction the camera is facing in
}
break;
case LOOK_DOWN:
if(player.camera.rotation.y!=90.0){ //if they are not looking down
//make them look down
player.camera.rotation.y+=90.0;
//TODO: set direction the camera is facing in
}
break;
case ROTATE_RIGHT:
if(player.camera.rotation.x!=360.0){
player.camera.rotation.x+=90.0;
//TODO: set direction the camera is facing in
}else{
player.camera.rotation.x=0;
player.camera.rotation.x+=90.0;
//TODO: set direction the camera is facing in
}
break;
When I press the right arrow key(rotate to the right) it doesn't rotate also when I rotate up(up arrow) it goes weird instead of allowing me to see the top of the skybox it still shows me my test cubes.
So guys how do I fix the rotation, what am I doing wrong?
Note the 'TODO: set direction' stuff is for my local axis system. Those TODOs are irrelevant to the question.