• Advertisement
Sign in to follow this  

fps camera

This topic is 2382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement