Swiftless
08-28-2005, 03:19 AM
When I press W, my camera translates the scene inwards. When I press A, the camera translates the scene to the left. S and D do the opposites. When I press W and then S or D, it stops translating inward and starts translating across. How can I make it so that when I press W and S, it translates both across and inward at the same time?
Here is my camera code:
void camera (void) {
int posz, posx;
posz = zpos + 1;
posx = xpos + 1;
ypos = map[posx][posz];
ypos += 2;
glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glTranslated(-xpos,-ypos,-zpos);
glutPostRedisplay();
}Here is my keypress code:
void normalKey (unsigned char key, int x, int y) {
float yrotrad;
switch (key) {
case 'w' :
yrotrad = (yrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) * 0.2;
zpos -= float(cos(yrotrad)) * 0.2;
break;
case 'a' :
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= float(cos(yrotrad)) * 0.2;
zpos -= float(sin(yrotrad)) * 0.2;
break;
} And here is my main code:
glutIgnoreKeyRepeat(0);
glutKeyboardFunc(normalKey);
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
(I am using GLUT in C++)
Here is my camera code:
void camera (void) {
int posz, posx;
posz = zpos + 1;
posx = xpos + 1;
ypos = map[posx][posz];
ypos += 2;
glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glTranslated(-xpos,-ypos,-zpos);
glutPostRedisplay();
}Here is my keypress code:
void normalKey (unsigned char key, int x, int y) {
float yrotrad;
switch (key) {
case 'w' :
yrotrad = (yrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) * 0.2;
zpos -= float(cos(yrotrad)) * 0.2;
break;
case 'a' :
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= float(cos(yrotrad)) * 0.2;
zpos -= float(sin(yrotrad)) * 0.2;
break;
} And here is my main code:
glutIgnoreKeyRepeat(0);
glutKeyboardFunc(normalKey);
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
(I am using GLUT in C++)