Improved the Box2D engine, have a few problems

Please don't post Bullet support questions here, use the above forums instead.
coderchris
Posts: 49
Joined: Fri Aug 18, 2006 11:50 pm

Improved the Box2D engine, have a few problems

Post by coderchris »

Hi everyone, I started working to add some new features to the Box2D engine and Iv succeeded with:

-a hash table based broadphase collision detection method that is about O(1) (plus a little overhead for clearing / updating the table)
-sleeping for bodies that dont move over a period of time
-basic shape system (have added a circle shape, working on capsule)
-few optimizations here and there
-restitution
-multi-threaded (collision detection / dynamics on different threads)

Most of these work pretty well, but I have a few problems and need some suggestions for solutions

Before I forget, heres the code for what I currently have: Source Code (Right click, save target as)

First off, the main problem is that when I enable multi-threading and the number of bodies gets over about 600 or so, it becomes unstable and eventually crashes. I believe this is because teh dynamics thread is trying to access an arbiter, but the collision detection thread is deleting it at the same time, though I am not completely sure.
In the demos, multi-threading is not enabled by default, to enable it go into Flags.h and uncomment the MULTI_THREAD line and recompile

Secondly, unless the bodies are moving at high speeds, restitution only seems to work in between similar shapes (for example, boxes only bounce off of boxes and circle off of circles)
I am baffled as to why this would happen...

The last thing is that the circles can be "inside" the boxes as if they were hollow. This is because I am using lines as the boxes boundry and the spheres only check for collisions on those lines. Im not too knolegable in the collision detection field yet so I havent been able to figure out how to do correct box-circle collisions

Any hints/suggestions/solutions to these problems would be greatly appreciated.

The statistics for the various processes are cout'd
As you will see, the collision detection and dynamics phases take about the same amount of time, so if the multithreading worked properly all the time it would cut the amount of time normaly needed in half
Erin Catto
Posts: 316
Joined: Fri Jul 01, 2005 5:29 am
Location: Irvine

Post by Erin Catto »

Nice demo!

The collision and constraint processing need to be sequential with each other. I would concentrate on multi-threading collision pairs and constraint islands.

For sphere vs box:
- Use clamping to find the closest point on the box perimeter to the sphere center. Use this point as the contact point.
- The point on the perimeter also defines the normal (the edge normal).
- The separation is this: dot(normal, center - point) - radius
CaptainNemo
Posts: 9
Joined: Fri Aug 18, 2006 7:24 pm

Post by CaptainNemo »

The download doesn't work here, I get only an angelfire site.
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Post by DevO »

Nice improvements coderchris!!!
For some time I have payed too with Box2D and done some improvements, not as many as you but I can post it here so you may use some of my ideas to improve Box2D more.

May be it would be nice to creare SourceForge project and make simple 2D physic library? :)
Of course if Erin Catto agre, do you agre?

@CaptainNemo: Copy the link and past it into the new browse windows!
CaptainNemo
Posts: 9
Joined: Fri Aug 18, 2006 7:24 pm

Post by CaptainNemo »

@DevO: Ah, that worked!. Thanks!
coderchris
Posts: 49
Joined: Fri Aug 18, 2006 11:50 pm

Post by coderchris »

@Erin Catto: Thanks, ill try multithreading that way and see if I can get the box-circle working right

@DevO: sure thing if you posted your improvemetns I could integrate them into mine to make it even better. I have no experience with using SourceForge but I would gladly do this if I can make the library good enough...There needs to be a nice 2d physics library out there.
raigan2
Posts: 197
Joined: Sat Aug 19, 2006 11:52 pm

Post by raigan2 »

Erin Catto wrote:Nice demo!
- The point on the perimeter also defines the normal (the edge normal).
- The separation is this: dot(normal, center - point) - radius
i might be misunderstanding, but i think you need to use the unit vector parallel to [point - center] as the normal (or, [center - point] if your convention is for the normal to point out of the box).

the seperation is just: ||point - center|| - radius


i'm tinkering with box2D myself and would be happy to contribute once i clean up my code a bit.
raigan2
Posts: 197
Joined: Sat Aug 19, 2006 11:52 pm

Post by raigan2 »

after some poking around trying to figure out why things were so bouncy, i discovered that you've unfortunately used an older version of Erin's code that lacks seperate position and velocity impulses. alas..

in case anyone else is trying to compile in code:blocks w/ the MSVC2003 compiler, deleting the "ShapeType::" from in front of all the ShapeType::BoxShape seems to get rid of all those errors ;)