mercoledì 17 agosto 2016

Day 166: Sleep

I needed to stop working on the engine for a few days because my last game was approved on Steam and I had quite a few things to do. Today I had a bit of free time, and I added support for sleeping objects, which is very important to achieve high performance in the physical engine.

Basically each object have a motion value, which is a float number obtained from both rotation and velocity. The object is put to sleep if this value is low enough, and it is awoken again in three cases:

- The application of a force
- A change in velocity
- A collision

I tested it briefely, and it seems to work fine. It also need some fine tuning: the motion value is actually an average of the last frames as well, and it's crucial to find a good value of "how much" to keep of the last frames. And of course the threshold itself under which the object is put to sleep must be carefully chosen to be as big as possible, but not visible to the eye.

With this implementation I've actually concluded the implementation of the book. The engine is now roughly complete, but there are still things to do:

- Handle the friction and restitution coefficients (right now there is a universal value)
- Fix collision resolution (only sphere-sphere and sphere-plane seem to work without problems)
- Implement the octrees for the broad phase detection
- Lots of profiling and testin

Nessun commento:

Posta un commento