O'Reilly logo

Beginning 3D Game Programming by Tom Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Basic Collision Detection

One of the basic things that virtually all games have is a collision detection method. In this case, all you need to determine is whether a particular moveable object is colliding with the level. (See Listing 14.12.)

Listing 14.12. Collision Detection Algorithm
 public bool HitTest(IMoveableObject obj, out Plane hitPlane) { // Default to an empty plane hitPlane = Plane.Empty; // This object hasn't left the level, has it hit a wall? IntersectInformation closestHit = new IntersectInformation(); if (levelMesh.Intersect(obj.Position, obj.Direction, out closestHit)) { // This will always return true since you will always be hitting the // outside of the level. Now you need to check to see if you're // close enough to really ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required