Input when equals key is hit
Jul 29, 2013 at 5:43am UTC
I am working with OpenGL and I'm trying to allow hitting the enter key to zoom in. However, it won't zoom in. Here's the related code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
float zoom = 0.0f;
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
cleanup();
exit(0);
case 32:
spin = !spin;
case 61:
zoom -= 1.0f;
case 45:
zoom += 1.0f;
}
}
glTranslatef(0.0f, 0.0f, -10.0f - zoom);
glutKeyboardFunc(handleKeypress);
EDIT: Something is wrong with case 61. It doesn't change zoom.
Last edited on Jul 29, 2013 at 5:47am UTC
Jul 29, 2013 at 5:57am UTC
1 2 3 4 5 6 7 8 9 10 11 12
void handleKeypress(unsigned char key, int x, int y)
{
const unsigned char esc = 27 ;
switch (key)
{
case esc: cleanup(); exit(0);
case ' ' : spin = !spin; break ;
case '=' : zoom -= 1.0f; break ;
case '-' : zoom += 1.0f; break ;
}
}
is much more readable, isn't it?
Don't forget that cases fall through without a
break ;
. I don't see where you're actually doing anything with the key code for enter, so I'm not sure what the text of your question is about, particularly seeing it is at odds with the thread subject.
Last edited on Jul 29, 2013 at 5:59am UTC
Topic archived. No new replies allowed.