Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: glutKeyboardFunc with glutTimerFunc problem

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12

    glutKeyboardFunc with glutTimerFunc problem

    Hi everybody,

    I have a small issue to come over.

    I have made a ball game which I kick a ball against a wall.

    Basically what is meant to happen is when I press 'z' once the ball is meant to be kicked against the wall.

    In order to do this I need a glutTimerFunction which needs to animate the ball and kick it against the wall, and if it hits the wall then the ball should retur back to where it started.

    With this code I have done I have so far I need to hold onto 'z' the key in order for it to kick the ball against the wall.


    I have supplied the relevant code below:

    GLfloat ballXpos = 40.0f;
    GLfloat ballYpos = -30.0f;
    GLfloat ballZpos = 160.0f;


    void frontWall()
    {
    glBegin(GL_QUADS);
    glVertex3f(-100.0, -50.0, -350.0);
    glVertex3f(-100.0, 50.0, -350.0);
    glVertex3f(100.0, 50.0, -350.0);
    glVertex3f(100.0, -50.0, -350.0);
    glEnd();
    }


    void normalKeys(unsigned char key, int x, int y) {
    {

    if (key == 'z') {
    ballZpos = ballZpos - ballZspeed;
    ballYpos = ballYpos + 0.5f;
    glutPostRedisplay();
    }


    void TimerFunc(int value)
    {

    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    174
    Assuming the 'normalKeys' function really does work, all you should have
    to do is -
    Code :
    void TimerFunc (int value)
    {
        ballZpos = ballZpos - ballZspeed;
        ballYpos = ballYpos + 0.5f;
        glutPostRedisplay();
    }

    Google something like 'TimerFunc example' to see how to set it up.
    Also read the manual on TimerFunc. Have fun.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    The normalKeys function works fine at the moment I have to hold down on 'z' key in order to move the ball, I want to set up a timerFunc so when I click it once the ball kicks against the wall. I believe to do this I have set up a glutTimerFunc with a Boolean function so when z = true then the timerFunc runs.

    I'm just a bit confused on how to do this.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •