bouncing ball - Pong


I want a ball to bounce of the walls of a cube(no gravity) according to the rule new_dir = 2((-old_dir)*surface_normal)*surface_normal + old_dir) (hope this is right ). I’m just a beginner in OpenGL and can’t seem to get the idea of how this is done. Can anyone help? (Some example code perhaps ) My biggest problem is how to indicate the balls direction (a vector?), how to move the ball according to this direction (the collision I can do…), and how to do the calculation that I wrote above in OpenGL (many many problems!).

Thanks to everyone in advance!

ps. I have tried to search through the q ‘n’ a’s here in search for an answer, but I don’t need anything realistic as I have seen described here, just something simple for a beginner.

[This message has been edited by victoria (edited 03-04-2003).]

You can use 3 variables for the direction, each one representing how much the ball is changed in the x,y and z directions between each frame rendered. Another 3 variables is needed to store the actual ball position.

That is simple, perhaps was your question more about how to move objects in OpenGL.

If you place your cube in the direction of the coordinate system is it very easy to change the directions variables for a bounce.

  • negate the y direction for a bounce on the roof or floor
  • and so on