Variables
float camera_x = 0.5f; // X Axis
float camera_y = -1.8f; // Depth
float camera_z = -5.0f; // Y axis
float pitch = 0.0f; // Camera mouse x
float yaw = 0.0f; // Camera mouse y
float roll = 0.0f; // Not used
Key
case 'w':
camera_z += 0.1;
break;
case 's':
camera_z -= 0.1;
break;
case 'a':
camera_x += 0.1;
break;
case 'd':
camera_x -= 0.1;
break;
Mouse
if( 512 < x )
{
yaw += 1;
if( 360 < yaw )
{
yaw = 0;
}
}
if( 512 > x )
{
yaw -= 1;
if( -360 > yaw )
{
yaw = 0;
}
}
if( 384 < y )
pitch += 1;
if( 384 > y )
pitch -= 1;
if( x != 512 || y != 384 )
glutWarpPointer(512,384);
Actual camera function
glRotatef(pitch, 1.0f, 0.0f, 0.0f);
glRotatef(yaw, 0.0f, 1.0f, 0.0f);
glRotatef(roll, 0.0f, 0.0f, 1.0f);
glTranslatef(camera_x, camera_y, camera_z);