Making a simple Physics Engine: Episode 3


Object Scenery Collisions

Ok this is where things start to get a bit more tricky. This is mainly because I want to have spheres (nice simple objects) colliding with polygons (not so nice irregular objects). As usual we have to start somewhere and I will start with gettings spheres to colide with planes. This is the first step to getting polygon collisions and will also be used for providing barriers on the edges of the playing field.

Collisions with planes

I specify a plane by a position (which can theoretically be any point on the plane) and a normal vector. The normal is important, as it can be used to determine the direction the plane faces, so we can work out which side of it we are on and whether we are moving towards it or away from it.

To figure out whether a sphere is intersecting a plane we simple need to find the distance from the center of the sphere to the plane and compare it with the radius of the sphere. This can be found in books, but I will sum it up here:

n = normal vector

r = position vector

p = point


dist = abs( n·p - n·r ) / |n|