Tim Nikias v2.0 wrote:
>>Now my particle system handles damping properly: the balls end up
>>sliding (looks like rolling...). I was afraid that I need some
>>conditionals to distinguish between slide/bounce state but "luckily" the
>>same piece of code handles both cases.
>>
>>There is no friction at all. The speed along the surface normal is
>>dampened by 30% every time a ball bounces off the floor.
>
>
> Nice one! How do you do it to keep particles out of the objects?
>
> And what's your "lucky" code which keeps particles sliding nicely?
I won't show the code (it is still very ugly) but here is what I'm
basically doing:
1. My approach is a "refined" Euler method - I guess :) When the
position of a particle is updated the gravity is also taken directly
into account - not only speed. So gravity affects both the speed and the
position during every step. Without it I see my particles bounce for too
long with damping. This also gives 100% accuracy (when particles are not
colliding) no matter how big time steps between frames.
2. If the new position indicates a collision, the previous position is
restored (so basically particles _can't_ intersect with an object). The
next happens:
a) speed is directed away from the surface taking the damping into
account: this gives basic bounces.
b) particle is moved along the surface: this allows rolling and the
bounces are also more accurate, still not perfect though. If I want them
perfect I would have to find the _exact_ moment of collision.
c) gravity affects the speed along the surface: this allows the increase
in speed when rolling - also the accuracy of bounces increase.
I might have forgotten something but basically it works like that.
By "lucky" I mean that there seems to be no bugs and everything seems to
work as expected after I implemented 2.b and 2.c. BTW, have you tried
how Cristophs particle system/MegaPov handles rolling/sliding? Just
curious. At least it is a lot faster as it is hard coded.
Now I have only planes as environment and I check collisions by shooting
a ray towards every plane. This obviously is accurate but a bad thing to
do when there are many objects. Next I have to make the environment as a
one single union and shoot proper rays towards it. Accuracy decreases
but I can use as complex environment as I want.
Severi
Post a reply to this message
|