Original Post
Hello!
I have done a small physic engine that uses only the point mechanic, so it manages only balls.
It works like this
loop {
for every interaction (friction, spring, etc), compute the force added to every balls
for every balls, compute their acceleration: a = sum(forces)/ mass
for every ball, update its speed and its position in relation with the acceleration
} endloop
Now, I'd like to add the collision in the interactions, but it is different from the others, because, besides it adds forces, it changes the position of the balls (ex: if 2 balls are in collision, the collision adds a force to them and also moves them further appart, so there is not penetration between the two balls anymore (distance = ray1 + ray2).
Because of this difference, I think that the collisions and other interactions modifying the position should not be treated as the others:
- For the moment, all my interactions was treated without order. But depending on whether a collision is treated after or before a spring, the positions will be different when the spring compute its force and the force will then be different. :P
- if the ball A is in collision with the balls B and C, the result is different depending on whether the collision between A and B is treated before the collision between A and C. :P
Somebody knows how to deal with it? Thanks a lot!!!
An idea that might work: an interaction can add force and gap, that affects the position after all the interactions are treated, but cannot change the position. I am not sure about the result, but the order of treatment of the interactions would not matter anymore. the loop becomes
loop {
for every interaction (friction, spring, collisions ), compute the force and the gap added to every balls (the position of the balls do not change)
for every balls, compute their acceleration: a = sum(forces)/ mass
for every ball, update its speed and its position in relation with the acceleration and the gap added.
} endloop
I have done a small physic engine that uses only the point mechanic, so it manages only balls.
It works like this
loop {
for every interaction (friction, spring, etc), compute the force added to every balls
for every balls, compute their acceleration: a = sum(forces)/ mass
for every ball, update its speed and its position in relation with the acceleration
} endloop
Now, I'd like to add the collision in the interactions, but it is different from the others, because, besides it adds forces, it changes the position of the balls (ex: if 2 balls are in collision, the collision adds a force to them and also moves them further appart, so there is not penetration between the two balls anymore (distance = ray1 + ray2).
Because of this difference, I think that the collisions and other interactions modifying the position should not be treated as the others:
- For the moment, all my interactions was treated without order. But depending on whether a collision is treated after or before a spring, the positions will be different when the spring compute its force and the force will then be different. :P
- if the ball A is in collision with the balls B and C, the result is different depending on whether the collision between A and B is treated before the collision between A and C. :P
Somebody knows how to deal with it? Thanks a lot!!!
An idea that might work: an interaction can add force and gap, that affects the position after all the interactions are treated, but cannot change the position. I am not sure about the result, but the order of treatment of the interactions would not matter anymore. the loop becomes
loop {
for every interaction (friction, spring, collisions ), compute the force and the gap added to every balls (the position of the balls do not change)
for every balls, compute their acceleration: a = sum(forces)/ mass
for every ball, update its speed and its position in relation with the acceleration and the gap added.
} endloop