PDA

View Full Version : FPS camera



riche606
08-19-2011, 02:20 AM
im trying to get a "camera" working so that it can go through my 3d level ive got it to compile with no issues but the camera doesnt move at all when i press a key, can anyone see where ive gone wrong

void keyboard (unsigned char key, int x, int y) {
if (key=='q')
{
xrot += 1;
if (xrot >360) xrot -= 360;
}

if (key=='z')
{
xrot -= 1;
if (xrot < -360) xrot += 360;
}

if (key=='w')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) ;
zpos -= float(cos(yrotrad)) ;
ypos -= float(sin(xrotrad)) ;
}

if (key=='s')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad)) ;
ypos += float(sin(xrotrad));
}

if (key=='d')
{
yrot += 1;
if (yrot >360) yrot -= 360;
}

if (key=='a')
{
yrot -= 1;
if (yrot < -360)yrot += 360;
}
if (key==27)
{
exit(0);
}
}

void mouseMovement(int x, int y) {
int diffx=x-lastx;
int diffy=y-lasty;
lastx=x;
lasty=y;
xrot += (float) diffy;
yrot += (float) diffx;

}

Zyx_2000
08-19-2011, 04:08 AM
How do you tell OpenGL to use those values for the camera?