Physic Engine Series 1 (deprecated)

What can we learn from the market?

There are alot open source engines and some free to use propertary engines. Read and lern ;).

Engines i recommend to take a look at:

  • Nvidia (Ageia) PhysX
  • Farseer Physics Engine
  • Box2D

You can study the code, but i didn’t do that. I bought a book, that teaches me the missing knowledge. I used Farseer and PhysX in alot projects of mine so i knew the documentation pretty well. I recommend before writting any bigger “engine” look at the documentation of other engines. This helps you design interfaces and so on.

Parts of the Physic Engine?

Collision Detection

This topic is as big as the physic engine itself. The engine i created has an interface for collision data. It is possible for you to create your own collision detection part and use that interface to feed the physic engine part.

What will we implement?

  1. Bounding Sphere
  2. Segment Polygon Intersection

The Bounding Spheres keep the polygon-polygon intersection tests low!

Facts Collision Detection Part of mine

It is slow

The algorithms can be improved alot.

Improvement example 1:
You can implement Bounding AABB (Axis-Aligned Bounding Box) or better OBB (Oriented Bounding Box) instead of Bounding Spheres. They fit in the polygon far more accurate than Boundins Spheres. The collision detection part is not my passion todo so i kept it simple.

Improvement example 2:
You can implement the Sweep Line Algorithm to remove sensless checking of all Polygon Edges… In the next parts i explain the algorithms more in detail so you might get a better understanding what i am talking about.

Not every collision gets detected

Let’s pretend we have 2 Polygons. We call them PolygonA and PolygonB. If PolygonB is completly in PolygonA so the edges doesn’t touch then we can’t detect the collision. It is not that important for me because this should never happen :D. You can easily detect this. Just sum the angles from every vector from a point in PolygonA… If they are 360 degree the point is inside PolygonB. If that is true for all points of PolygonA the Polygon is completly in PolygonB. In 3D spaces more complicated scenarious can fail. I use this engine for 2D things so its ok for me.

Physic simulation

I implemented a Rigid Body Physic Engine. Forces and Impulses are used to simulate the physic. I recommend to look at a Particle Physic Engine first. Particle Physic Engines only simulate position changes and not Rotations. You can extend this engine with Rotation later. This is the way i did it. Force Generators are used to simulate Springs and so on. I am not completly finished with the engine yet (The reason why here is no source). Joints are missing for example. Sleep is missing too at the moment. Sleep improves the performance of the engine alot.

Want to learn for the next Series

Here is a list of things you can take a look at. You don’t have to learn. I try to explain everything in detail but that makes it easier to understand. If you find a mistake or some improvements. Just give me feedback 😉 :

  • Newton’s law of motion
  • Bouding Sphere Collision Detection
  • Segment Polygon Intersection

Next Series Part will start with the collision detection.

Leave a Reply

Your email address will not be published. Required fields are marked *