Problems with mass center

Please don't post Bullet support questions here, use the above forums instead.
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Problems with mass center

Post by Seth »

Hi,

As you might know, I started to write a physics engine, based on the verlet integration equotation. (http://www.bulletphysics.com/Bullet/php ... f=4&t=1952)

My problem is best descriped with moving pictures, here is the exe of my project, which shows what the problem is:
http://www.exec-dev.de/mass.zip (It looks even worse with friction ^^)

Image

As you can see, though the center of mass of the top rectangle lies over the second rectangle, the rectangle falls down.
The rectangles are not exactly stacked, I shifted the top rectangle 1 pixel to the right, to show what the problem is.

I can reduce my collision resolver to simply push the two polygons apart and it still occurs.
This is what I do:

Code: Select all

calculate the mtd;
calculate contact points;
// Resolve Collision
suminvmasses := A.invmass + B.invmass;
mf := A.invmass * suminvmasses;
// Ac and Bc contain the contact points
for i := 0 to high(Bc) do
  // p -= mtd * (1-mf) 
  B.vertices[Bc[i]].position := v2f_add(B.vertices[Bc[i]].position, v2f_scale(mtd, -1-mf));
for i := 0 to high(Ac) do
  //p += mtd * mf
  A.vertices[Ac[i]].position := v2f_add(A.vertices[Ac[i]].position, v2f_scale(mtd, mf));
I hope that there is a solution for this problem ;)

thank you
Steinmetz
Posts: 26
Joined: Sat Dec 15, 2007 12:03 am

Re: Problems with mass center

Post by Steinmetz »

Hello,
I am not a source of very competent answers, but I recognized, that the speed of your polygons changes with the MTD, but that makes no sense . A polygon that penetrates an other by 5px will not bounce off faster, than one that penetrates it by 1px . You should not only translate the normal position, but also the position of last frame, so that the speed doesn't change.
If you want your polygons to stack, you'll have to calculate both contact points(only if there are two ;) ), and then apply Impulses to both of them.
I hope I could help in any way.
(Sorry for my english... :( )
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

I assign a new position to every polygon in the collision.

hardwire said:
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 I "correct" the old position like this:

Code: Select all

      dv := v2f_sub(B.vertices[Bc[i]].position, B.vertices[Bc[i]].position_old);
      B.vertices[Bc[i]].position := v2f_add(B.vertices[Bc[i]].position, v2f_scale(mtd, -1-mf));
      B.vertices[Bc[i]].position_old := v2f_sub(B.vertices[Bc[i]].position, dv);
it looks very strange and buggy. if I add dv, than it looks like having endless friction

now I'm not sure whats correct :?

(OT: Are you from germany ?)
Steinmetz
Posts: 26
Joined: Sat Dec 15, 2007 12:03 am

Re: Problems with mass center

Post by Steinmetz »

(OT: Are you from germany ?)
Yes I am ;)

I did a simple sphere-sphere collision with Verlet, and I did the same thing, that you did, translating the polygons/spheres, so that they don't penetrate, but then I calculated the speed
Point v1v = p1.pos - p1.oldpos;
Point v2v = p2.pos - p2.oldpos;
then got the new speed after a few calculations ...
v1 = ...;
v2 = ...;
and then set the new speed :
p1.oldpos = p1.pos - (v1);
p2.oldpos = p2.pos - (v2);
You can do it the other way also, but I think it wouldn't be correct?

Image
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

I think this code does what you said, but it doesn't work:

Code: Select all

      dv := v2f_sub(B.vertices[Bc[i]].position, B.vertices[Bc[i]].position_old);
      B.vertices[Bc[i]].position := v2f_add(B.vertices[Bc[i]].position, v2f_scale(mtd, -1-mf));
      B.vertices[Bc[i]].position_old := v2f_sub(B.vertices[Bc[i]].position, dv);
Or is there something missing ?

(OT: Wie du vielleicht an der URL des downloads gemerkt hast, bin ich auch Deutscher ;) )
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

I still didn't find any solution for my problem ....
Any ideas ?

thx
oztune
Posts: 24
Joined: Tue Aug 21, 2007 12:13 am

Re: Problems with mass center

Post by oztune »

How does inertia of the objects tie into your calculations? To me it seems like its not fitting the shape of the objects..
Do you construct your boxes with 4 particles and 6 constraints? because then it shouldn't be a problem
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

A box is made of 4 particles with equal masses and 6 constraints. Inertia is not used by the engine, I thought that with using point masses, it will work automatically. Am I wrong ?

thank you
oztune
Posts: 24
Joined: Tue Aug 21, 2007 12:13 am

Re: Problems with mass center

Post by oztune »

Yea.. that's what I figured after reading your post again. I don't do it quite the same way just because when you get into objects other than boxes it could get a bit expensive to constrain other shapes (especially since I'm working with the flash player at this point), so i use jakobsen's tetrahedral approach.

Your boxes should have no rotation problems though, unless the way in which you push the bodies out of collision is wrong. How do you handle point-edge collision? How do you push the edge out of collision? Jakobsen actually describes a nice method in his article for that somewhere towards the end
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

the code in the first post shows how I push the contact points away from the object.
its everything I do (except friction and stuff)
oztune
Posts: 24
Joined: Tue Aug 21, 2007 12:13 am

Re: Problems with mass center

Post by oztune »

Do you only use vertices as contact points? do you include a point on a line as a contact point?
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

yes and yes (for resting contact) ;)
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

hi again,
I still didn't find any solution for my problems... :(
oztune
Posts: 24
Joined: Tue Aug 21, 2007 12:13 am

Re: Problems with mass center

Post by oztune »

Hey Seth,

I'm curious as to how you push the line apart after a collision (how you decide where to move the two points of the line). I suspect the problem lies there. Do you push lines in non-resting collisions?
Seth
Posts: 21
Joined: Tue Mar 04, 2008 3:57 pm

Re: Problems with mass center

Post by Seth »

Hi,
I don't exactly know what you mean, above code is nearly everything I'm doing for the collision and after the collision nothing happens except the verlet integration.