growing bacteria using rigid body

timrudge
Posts: 3
Joined: Fri Aug 06, 2010 12:08 pm

growing bacteria using rigid body

Post by timrudge »

Hi,

I am experimenting with Bullet (first time user) to develop a simple model of bacteria growing and dividing. I have been using the capsule shape, since this is pretty much exactly the right geometry, and should be fast.

My issue is how to have the capsule grow. I tried applying a local scaling which increases at each time step. This gave strange results, with the capsules kind of dancing around in mid air.

It also seems inelegant to bypass the dynamics altogether, so now I am thinking about a compound shape, consisting of 2 capsules on a slider constraint (the bacteria only grow along their long axis), with something like an elastic spring force between them. This would mean that the pair of capsules in each compound should be excluded from collision (in fact they would always intersect).

I am trying to avoid using a soft body triangle mesh, because ultimately I want to have large numbers of bacteria, growing and bumping into each other.

Any ideas or advice would be much appreciated, thanks.

Tim
arazaes
Posts: 2
Joined: Fri Mar 05, 2010 9:59 am

Re: growing bacteria using rigid body

Post by arazaes »

Hi

I think you could use a prismatic constraint between two capsules to get the growing effect, as you suggest. I'm only a beginner too and have limited myself to hinges, but looks like the slider constraint can be powered by a motor, so you could use this to grow at a certain velocity by pushing your two capsules apart.
http://www.bulletphysics.com/Bullet/Bul ... raint.html

You can make the collision detection ignore constrained bodies when you create the constraint in the world:
btDynamicsWorld::addConstraint (btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)

Maybe one problem will be growing beyond 2x the original length though?

best wishes
Stan
timrudge
Posts: 3
Joined: Fri Aug 06, 2010 12:08 pm

Re: growing bacteria using rigid body

Post by timrudge »

Thanks for they reply. I got this to work really nicely. And actually, at 2x length I want the cells to divide anyway, which I have implemented - so now have a growing colony of bacteria :)

A spectacularly dim question: how can I specify the debug rendering colours for objects? (I am using the DemoGlutApplication, based on SliderConstraintDemo)? For some reason it alternates blue/yellow, and looks nasty with overlapping objects.

(Perhaps I'll post this seperately)

thanks again,

Tim
arazaes
Posts: 2
Joined: Fri Mar 05, 2010 9:59 am

Re: growing bacteria using rigid body

Post by arazaes »

Glad my first attempt at helping was actually helpful :)

I'm not sure about using the debug renderer for anything more than debugging actually. I had some trepidation about attempting my own graphical implementation but actually it seems that for each rigid body you can get a nice transformation matrix from Bullet which you can apply to the openGL matrix before you draw it, so I guess as long as you can make a decent looking capsule in OpenGL it wouldn't be that hard. (I'm restricted to cuboids so it's even easier!)

Sorry if this is super simple and/or incorrect, like I said I'm just beginning at this stuff too, but here's my code for drawing one of my i cubes:

Code: Select all

                                btRigidBody *b;

                                b = boxes[i]->myPhysics;

                                glPushMatrix();
                                {
                                        /* Get the OpenGL Matrix version of this objects world transform */
                                        btScalar glRotMatrix[16];
                                        btTransform glRotTransform;
                                        glRotTransform = b->getCenterOfMassTransform();
                                        glRotTransform.getOpenGLMatrix(glRotMatrix);

                                        /* Apply the transform to the view */
                                        glMultMatrixf(glRotMatrix);

                                        /* Set the colour appropriately */
                                        glColor3f(boxes[i]->red, boxes[i]->green, boxes[i]->blue);

                                        /* Make the cube */
                                        cuboid(0, 0, 0, 2*boxes[i]->x_len, 2*boxes[i]->y_len, 2*boxes[i]->z_len);
                                }
                                glPopMatrix();

Hope this helps

cheers,
Stan
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: growing bacteria using rigid body

Post by sparkprime »

Just put two capsules in a compound, initially on top of each other, and move them apart. There is no need for constraints, each bacterium will be rigid and growing. Eventually you will remove the bacterium and replace it with 2 rigid bodies in the initial state. Rinse and repeat.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: growing bacteria using rigid body

Post by Erwin Coumans »

As sparkprime suggested, a changing btCompoundShape might be a good choice.

It is best to remove all contact points during the growing stage to avoid 'floating'. Try to call the following not too often, otherwise contact/stacking becomes instable/jittery:

Code: Select all

//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bacteriaRigidBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
This might also avoid the 'dancing in mid-air' that you noticed in your first attempt using scaling.

Hope this helps,
Erwin