PDA

View Full Version : Camera



runedog48
02-27-2013, 08:25 PM
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.

tonyo_au
02-27-2013, 10:39 PM
It's just the movement
have you set a breakpoint in the keyboard event to be sure you are processing keys correctly.

runedog48
03-01-2013, 06:00 PM
What I meant was that I want the movement to follow where you're looking. So if I press W it goes where I'm currently looking instead of forward.

tonyo_au
03-01-2013, 07:44 PM
So if I press W it goes where I'm currently looking instead of forward.

You mean along the axis from the camera to the taget.

The easiest is to create your view matrix with the gluLookAt function modifing the eye and lookat positions

runedog48
03-01-2013, 08:11 PM
You mean along the axis from the camera to the taget.

The easiest is to create your view matrix with the gluLookAt function modifing the eye and lookat positions

Hmm, I didn't want to use gluLookAt but from what I've read it seems like the best way to do this.