A common use for the dot product is scalar projection: Assuming B is normalized A dot B gives the distance of A in direction B.
The cross product gives a vector perpendicular to both A and B. In our 2D case it can be used to find on which side of a line a point lies depnding on the sign.
Download and test this base code and replace its vec2f with your own ("-lm" may need to be added to the Makefile).
Note that abs() and min/max functions on linux cast to an int. Use fabs() instead!
Using the base code, create an x-axis aligned line segment near the top left of the screen. This will be drawn using GL_LINES and should behave the same way as the paddle: Add code to make the ball bounce off the line segment. Note that the ball does not bounce correctly at the line end points.
For now we are not concerned with large timesteps (which may cause the ball to move straight through an object). We assume that a collision can be detected just by knowing if two objects currently intersect.
In this image the velocity is reflected just like the light vector was in phong lighting. Note that simply reflecting the velocity does not work when both objects can move. We'll cover this case next week.
Extra: