Earlier this year for a graphics project I did what seems to be the "classic" bouncing balls application.
Apparently since everybody does these, we are not allowed to have anything bouncy-ball related in our computer games course this year. Damn!
The basic concept is that we have 5 planes i.e. the floor and 3 walls, and we have a bunch of balls each with a random force vector. Every frame we are looking for intersections between the balls themselves, and between the balls and the walls. When an intersection happens, we do a little bit of Newtonian physics i.e. invert the force vector. Over time we gradually reduce the force of the vectors which will eventually bring the balls to rest. However if you hit the N key, all the balls will jump back into life as they will be assigned a new random force vector. Also pressing A will add new balls.
As time passes we do a few basic transformations on the camera matrix so you get a rotating view :)
private void UpdateCamera(GameTime gameTime) { double a = gameTime.TotalGameTime.TotalSeconds / 4; a += Math.Sin(a - Math.PI / 2) + 1; double r = 5000; cameraPosition = new Vector3((float)(Math.Cos(a) * r), 2500.0f, (float)(Math.Sin(a) * r)); }
Download: Application
Download: Video
Sources:
Copyright Tim Scarfe (c) 1999-2010