Today I implemented the skeleton of the system that handles forces. It is entirely based on three classes (and eventual derived classes):
1) Particle: the physical entity. Each particles has an accumulator, which is the resulting force accumulated every frame. Through the integration the particle status is updated.
2) Force generator: It describes a force. I extended this base class to simulate gravity, drag, spring, anchored spring, "bungee" and "anchored bungee" forces. Each force generator can add its force to the accumulator of the particle
3) Force register: This is the class that wraps everything together. It registers a list of force-particle pairs. Every frame, each force calls it's "add_force" function on the corresponding particle.
With this simple system it is easy to handle an arbitrary number of forces. In the gif there are two particles: an orange one, which is moved manually and not registered with any force, and a white one, which is under the influence of gravity and of a spring connected to the orange particle.
In the evening I also tried to implement the RK4 integration, in order to solve precision errors when using springs. I decided not to do that after a while because it would not resolve every problem, and it will also lower the performances of the engine. And the major problem would be to handle it when I'll need to implement advanced features of the engine, because it introduces more complexity. So for now I'll continue to use the not-so-good, old, Euler integration.

Nessun commento:
Posta un commento