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

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.

^ 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

^ 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

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.

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.

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

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