Sign in to follow this  
RichRoberts

fps camera

Recommended Posts

RichRoberts    100
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

[code]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;

}[/code]

Share this post


Link to post
Share on other sites
L. Spiro    25638
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this