Hello, I have made a simple camera. The only problem is it doesn’t follow the mouse. Ex: I will want to walk where I’m pointing and it walks forwards. After looking through tutorials I have found trig that I do not understand and did not use it. Can someone please help me with this? I currently have this:
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);
I’m using the OpenGlut library.
The mouse camera thing works. It’s just the movement. If you want the full code reach me on steam ( Runedog48 ) or on my Yahoo ( runedog48 AT yahoo (DOT) com ) I do not want people taking my code that I’ve worked on.