Video Game Programming
Lab 5 : Collision Detection


In any decent game, there are hundreds of objects that move (enemies, obstacles, the player, etc). What we are going to do in this lab is come up with a class that all these objects can derive from -> Any basic object has a few common properties. Mass, velocity, acceleration, position and orientation. We need to come up with a class encapsulating all these basic properties (you can thank me for the physics readings later [;)] ). It is not required that you perform all your movement according to the laws of physics, but you are going to find out that learning the physics required is much easier than coming up with your own formulas.

Topics Covered :
  • A class for movable objects
  • Implementing realistic motion in 3 dimensions
  • Geometric principles in collision detection
  • Collision Response Physics
  • Collision Detection
    • Collision between a sphere and a plane


Your assignment is to come up with a class that encapsulates the above mentioned properties. You will need to instantiate this class in the form of a simple sphere. The initial motion of the sphere should be upward. After an amount of time it should slow down, stop and come back down (gravity). On its downward path, cause it to collide with a plane (N = <1,5,0> passing through the origin). The ball should then come to a stop. Remember, in order to display the plane on screen, you will need to rotate a cube so that it represents a plane with the normal defined above.

Extra credit:Implement realistic physics using the principle of reflection -> when the ball collides with the plane, make it rebound with the appropriate velocity. Remember, the angle of reflection equals the angle of incidence. In this case, we can find out the angle of incidence using the old velocity vector and the plane normal. We then need to construct the new velocity using the principle of reflection. The angle of reflection is the angle between the plane normal and the new velocity. You are required to come up with your own vector class to perform all the operations required.

  • Completion of Lab 4
  • A basic understanding of college level physics and geometry including:
    • Vector math (multiplication, cross and dot product)
    • Matrix Math (matrix / scalar multiplication)
  • A basic knowledge of computer graphics including:
    • Coordinate Systems (Right and Left Handed)
    • Affine Transformations (Translations, Rotations, Scaling)
    • Object to World Transformations
    • Projections
    • The View Matrix
    • World to View Transforms

  • Any college level physics textbook (Force, mass, acceleration)
  • Foley, Van Dam, Feiner, Hughes, Computer Graphics, 2002, Second Edition in C Pgs 1-283
  • Collision Detection Presentation Click Here

  • Sphere appears on screen
  • Sphere moves 
  • Gravity
  • Collision Detection
  • Code structure
  • Physics (extra credit)
  • 20%
  • 10%
  • 20%
  • 30%
  • 20%
  • 20%

Lab 5

This lab is being distributed as a zip file. You must unzip all files to the same directory.

This lab requires DirectX 9.0a End-User Runtime

Address questions regarding this lab to Prasan Samtani at