Page 2 of 2

Re: Constraint-Based Verlet Physics Engine

Posted: Sun Mar 09, 2008 7:24 pm
by Seth
hi, you're right, jellophysics seems to use springs which do not have endless stiffness. (easy to implement, because it only affects the length constraints of the polygon)
The problem is that I don't know what to do next, how to add friction, elasticity and collision response.

Re: Constraint-Based Verlet Physics Engine

Posted: Sun Mar 09, 2008 10:15 pm
by hardwire
Seth wrote:hi, you're right, jellophysics seems to use springs which do not have endless stiffness. (easy to implement, because it only affects the length constraints of the polygon)
The problem is that I don't know what to do next, how to add friction, elasticity and collision response.
As I said, collision response is made by simply moving the mass points so there is no overlap. You don't need to care about velocity, because it is changed implicitly.

If you want to add some bouncing then move last_pos of the mass point along -normal*CoR where "last_pos" is a last position of the mass point (you need to store this if you work with velocity less Verlet), "normal" is a collision normal (along which you moved the mass point in order to solve the overlap) and "CoR" is a coefficient of restitution between 0 and 1.

If you collide with static objects then you can simulate the friction by simply decreasing "velocity", so make last_pos+=(pos-last_pos)*CoF where "CoF" is a coefficient of friction. It seems strange but works nicely for me :) Perhaps it would be more accurate as if I did it the same way as with dynamic objects.

Friction of collision with a dynamic body is a little more tricky. You need to calculate relative velocity of colliding points. Let's assume your mass point I collided with and edge (defined by mass points J and K) of the other object (1 point vs 1 point is just a simpler scenario). Then the relative velocity is relVel = I.pos - I.last_pos - (J.pos + K.pos - J.last_pos - K.last_pos)/2. Then you compute tangent from the collision normal and project the relative velocity onto it:
relTanVel = tagent*dot(relVel, tangent)
Then you add/subtract (depending on how you computed tangent) some fraction of relTanVel to/from last_pos of I,J,K. What fraction it will be is determined by I,J,K masses and "hit coefficient" (because I is somewhere between J and K...you get the hit coefficient by projecting I onto the edge JK).

Again, this is probably not very accurate, but works fine for me and it looks good in the cases I needed. If you need something more accurate then mass-spring system for simulating bodies is maybe not a good idea, but as I remember you wanted something simple.

Re: Constraint-Based Verlet Physics Engine

Posted: Mon Mar 10, 2008 11:53 am
by Seth
hi,
thank you very much, this seems to be very helpful for me ;)
(does normal in your case mean that it has a length of 1 ?)
I also don't have to deal with masses ?

This is my try to deal with masses:

Code: Select all

  suminvmasses := A.invmass + B.invmass;
  mf := A.invmass * suminvmasses;
  for i := 0 to high(Bc) do
    B.vertices[Bc[i]].position := v2f_add(B.vertices[Bc[i]].position, v2f_scale(mtd, -1-mf));
  for i := 0 to high(Ac) do
    A.vertices[Ac[i]].position := v2f_add(A.vertices[Ac[i]].position, v2f_scale(mtd, mf));
instead of using 1/2 for scaling the collision normal, I use a relationship of the two inverse masses.
I think I also will need masses for friction, because heavy objects don't slide that much as they do now.

Could you post some of your friction code ? especially the part for moving objects ^^ because it's not very clear to me yet.
You said:
What fraction it will be is determined by I,J,K masses and "hit coefficient" (because I is somewhere between J and K...you get the hit coefficient by projecting I onto the edge JK).
How exactly does this work ? is this necessary if all masspoints of one polygon have the same mass ? As I said I think that heavy objects should slide less.

Current Version (with restitution and masses):
http://www.exec-dev.de/verlet.zip
The restitution seems to add energy to the system which is not good ^^

Re: Constraint-Based Verlet Physics Engine

Posted: Mon Mar 10, 2008 10:43 pm
by Seth
Now I finally managed to handle friction, this is what it looks like now:

http://www.exec-dev.de/verlet.zip

I think that heavy objects have to have much more friction, because they slide to easily. I used the normalvector scaled by the penetration depth for restitution, because otherwise the objects won't stop bouncing, is this correct ? (for friction I used the normal with length 1)

Here I have a Demo with a bridge (inlcuding the two constraint types rope and spring): http://www.exec-dev.de/Bridge.zip
I think it would be good, to add something like air friction because constructions like this bridge (or pendulums) don't stop moving. (I think just reduce the velocity like for normal friction)
But one really big problem is, that even if the "ball" is very heavy, the bridge doesn't "bend" more, the springs have to get much longer, but they dont. How can I solve this problem ?

I am now trying to fix this by calculating FG:
FG = m * g
because now I only take care of FN, like you can see here: http://de.wikipedia.org/wiki/Bild:Schiefe-Ebene.png
maybe this will solve my problem :P

EDIT: even if some approaches looked good, something weird always happens after some time.

Any ideas ?

thank you

Re: Constraint-Based Verlet Physics Engine

Posted: Fri Mar 28, 2008 3:05 pm
by oztune
Hey Seth
I've actually tried implementing a similar system not too long ago, and was somewhat stuck when it came to friction...
You can see my latest build at: http://www.physicsdev.com/files/fisix/demo1/demo1.html
I'm using the tetrahedron approach from jakobsen's paper, which actually works very well when it comes to constraints and contacts... that demo is very limited, but any polygon, and any type of constraint can be simulated there.

Now Raigan ('raigan2' on these forums) Implemented a similar system, and used 'motorized constraints' for friction, which he says works quite well...

Right now I'm looking at impulse based methods though... maybe there's a way to mix both

Re: Constraint-Based Verlet Physics Engine

Posted: Sun Mar 30, 2008 11:59 am
by Seth
hm, I managed to implement friction very easily, using the above mentioned method.
But I have another problem which doesn't seem to exist in your engine, maybe you can help ?

The problem is described here: http://www.bulletphysics.com/Bullet/php ... f=4&t=1974

thank you