fps camera

Started by
0 comments, last by L. Spiro 12 years, 8 months ago
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;

}
Advertisement
Firstly you really need to move by an amount of time, or else you will move more slowly when your frames drop and perhaps super-fast when they are good.


You certainly do have code for updating variables.
Are you sure they are even being processed? If you are accepting WM_KEYDOWN virtual key codes, you would need to listen for 'A', not 'a', for example.
Are you sure that modifying those variables actually causes a reaction to the camera?


I am fairly sure that you will get a reaction once you are listening for the proper key codes, but I highly doubt it will be the reaction you want until you add some accounting for time.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement