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 8 of 8

Thread: Stationary Ball (I fixed it, thanks people)

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    10

    Stationary Ball (I fixed it, thanks people)

    I am a noob as many of you was at one point or the other. I just have a simple question.

    I was told to make a Bat and Ball OpenGL game (pong), which I have. One problem I cannot solve is I have make a callback function (mouse left button input) to allow the user to Start the ball moving, meaning I have to start with a stationary position. How do I make it that the screen that appears is stationary (nothing moves) then when player presses the left button on the mouse the ball moves.

    Please Help.

    p.s you will one day see me in the advance section as I find OpenGL very intersting.

    Thanks in advacne

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    Re: Stationary Ball (I fixed it, thanks people)

    Let the ball have a variable representing its velocity. Also the ball will be positioned based on the value of a variable xPos (I'm assuming here that the ball only travels left and right, you're going to want to add a vertical velocity as well).

    each frame xPos gets incremented by the velocity:
    xPos += horizVelocity.

    before the user presses the left mouse button the ball's velocity is 0.
    so each frame xPos += horizVelocity (0).

    so, when you go to draw your ball:

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glTranslatef(xPos,0,0);
    //draw ball
    glPopMatrix();

    then when the user left clicks assign the ball a velocity and the ball'll start moving.

    this is one way to do it.
    hope it makes sense.

  3. #3
    Guest

    Re: Stationary Ball (I fixed it, thanks people)

    ^ Aeluned, I see what you mean. Right now my ball immedialty travels at an angle. Thanks for the help.

    I gonna make some modifications in the morning when I get back to Uni. I will give the feedback then. Thanks again

    Shak

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    10

    Re: Stationary Ball (I fixed it, thanks people)

    ^ it didnt work, it gave me error and stuff. I go it to be stationary in the begining, so when I click on the mouse button the ball moves. BUT, the ball only moves 1 frame and then I have to press the buttom again in order to move the ball another frame.

    Man it's annoying me. I spent over 3hours trying to figure this out, its not working.

    ***UPDATE***

    Hi everyone, i had a simple problem which i cant believe i over looked. basically in my main function I had to do this glIdleFunc(NULL); in the callback section and then in my Mouse fucntion I had to do this glIdleFunc();

    this actually solved the problem.

    i was meesing around the "time" idea but it was a bit complicated for me so my friend just said for me to do that.

    Thanks for the help people.

    Appreciate it

  5. #5
    Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    370

    Re: Stationary Ball (I fixed it, thanks people)

    Have you incorporated a timer class or something similar? Like that it could be as simple as:
    OnLeftClick -> StartTimer
    So world starts moving all the sudden.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    Re: Stationary Ball (I fixed it, thanks people)

    Shakeb,
    it seems like you're not implementing an animation loop.

    you need to either set up a timer like moucard suggested and on the timer event update xpos and redraw the scene or setup a loop that continually checks the Windows message:
    if the message is WM_QUIT the app exits
    if it's anything else handle it as usual
    else increment xpos and redraw the scene.

    this loop should be placed in WinMain().

    either way, this topic doesn't concern OpenGL and you're going to have to do a little digging to set that up...it shouldn't be all that difficult.

  7. #7
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    10

    Re: Stationary Ball (I fixed it, thanks people)

    Hi everyone, i had a simple problem which i cant believe i over looked. basically in my main function I had to do this glIdleFunc(NULL); in the callback section and then in my Mouse fucntion I had to do this glIdleFunc();

    this actually solved the problem.

    i was meesing around the "time" idea but it was a bit complicated for me so my friend just said for me to do that.

    Thanks for the help people.

    Appreciate it

  8. #8
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    10

    Re: Stationary Ball (I fixed it, thanks people)

    Hi everyone, i had a simple problem which i cant believe i over looked. basically in my main function I had to do this glIdleFunc(NULL); in the callback section and then in my Mouse fucntion I had to do this glIdleFunc();

    this actually solved the problem.

    i was meesing around the "time" idea but it was a bit complicated for me so my friend just said for me to do that.

    Thanks for the help people.

    Appreciate it

Posting Permissions

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