I have been makeing a pong game in OpenGL (the first *real* thing i am making in openGL)
I have been useing the Nehe basecode (nehe.gamedev.com) and have been able to make 2 pods wich I can move up and down, I have been able to make a small box and add a texture to it so it looks like a ball.

Now to my problem :)

I cant get my "ball", wich is just a quad with a texture to it, to move.

I have made my ball like this "glVertex3f(ballLTX, ballLTY, 0.0f);" so I am able to move it any way I want too.
However If I put a code like this :

That will change the ball's position before displaying it. Try removing the loop and possibly changing 0.05f to 0.01f (just to make sure it doesn't dissappear too quickly).

Edit: Or maybe you meant that to be an if statement?

06-07-2004

Perspective

are you redrawing the screen after the ball's position has been updated? make sure you glFlush() too.

06-07-2004

Oluf

doh! Yes of cuase that should be a if...thanks for pointing it out...works now so thanks a lot :)

btw...I might need some help later with figuering out how my box knows when it hits a pod but I will try a few things out first

06-08-2004

bludstayne

It might be easier to just use a glTranslate instead of what you're doing. It'd be much easier to manage. Just a thought.

06-08-2004

Shakti

Yes just use glTranslatef instead, it will be much easier later on. To check if the ball hits one of the pods check the quad with the ball against the pods. For example:

The ball quad has the size 16x16 and the pods has the size 8x64 pixels.
Now calculate the middle coordinate for the ball quad and the pod quad (8,8 and 4, 32). Now lets say the ball is heading to the left. Check if the the balls top side is within the pods quad, if it is check if the balls left side is in the quad.

Hope I gave you some hints on how to check for hits, its not the best but its working. I am currently using something similar to this method in my alpha game demo I have posted here.