Today I started by adding another force generator to simulate the buoyancy. The formula used is a very crude approximation of the actual formula: it doesn't account for the shape of the object, and it behaves basically like a spring, with the difference that, when the object is fully immersed, the force becomes constant.
In the gif the white particle is kept floating thanks to this force, despite the gravity and spring force pulling it down.
I also implemented the first part of the contact resolver. Basically this class holds the info about a contact, and resolves the position of the two particles involved thanks to the "resolve" method. The resolve method calls two functions: resolve_velocity, which adds the resulting velocity after the collision to the particles, and the resolve_interpenetration method, which handles the fact that two particles might already be inside one another. I've implemented only the first method so far, and both of them will be difficult to test for now, because the particles have no shape yet.
An important thing to notice is that this class uses a contact_normal variable, which is the direction of the contact point. This must be provided by some other not-yet-implemented classes of the engine, because the Contact class itself ignores how the contact is generated, it just resolves it.

Nessun commento:
Posta un commento