Static vs Dynamic

Calvin1602
Posts: 3
Joined: Thu Jan 28, 2010 12:40 pm

Static vs Dynamic

Post by Calvin1602 »

Hi,

I'm switching to Bullet after 3 years of Newton Dynamics and I'm having trouble setting up my scene.
All my objects move, but I don't want them to be dynamic : each frame I set their position, and the only thing I want to do is detect collisions between objects of type 0 and objects of type 1. Objects of the same type should not collide.

The choices I have to make are :

The masses : According to the doc, it's 0.
The type : I guess it's dynamic, but I couldn't make it work
The activation state : set to ACTIVE but not sure. The doc says DISABLE_DEACTIVATION but I don't understant what is does (and does not work)

Whenever I set masses of objects of one type to 0.001 everything works, but then they move by themselves (gravity) and I don't want that.

Any help would be much appreciated.
A.M.
Leezer
Posts: 22
Joined: Mon Nov 09, 2009 5:06 am

Re: Static vs Dynamic

Post by Leezer »

I don't really have the answer to this, but I too am looking for a way to keep rigid bodies still until I tell them to move (i.e. suspended in the air and not influenced by gravity).

According to the API, there are 3 types of rigid bodies:
A) Dynamic rigid bodies, with positive mass. Motion is controlled by rigid body dynamics. My comment: In order to use this kind of body, I gave my rigid body a positive mass and didn't flag it as kinematic (removed its kinematic flag). To "freeze" it in the air, I used a rather hacky method: after creating the rigid body, I called body->forceActivationState(0). Then, whenever I wanted to give the body a specified velocity, I called body->activate() followed by body->setLinearVelocity(blah). When I was done applying the velocity, I called body->forceActivationState(0) again. This hacky method worked great until I anchored some soft body ropes to the rigid body. The interaction of the ropes with the rigid body seems to override my forced activation state, and the rigid body oscillates in the air in response to being pulled back towards the rope anchors as it slowly falls to the ground (yes, it falls...). Edit: the same thing happens if I shoot a cube at the rigid body - it activates even though I don't want it to.
B) Fixed objects with zero mass. They are not moving (basically collision objects). My comment: In order to use this kind of body, I gave my rigid body a 0 mass and didn't flag it as kinematic (removed its kinematic flag). However, I had no luck with using this kind of body, since, as the description suggests, it can't be moved. Even though it ignores gravity and doesn't fall, neither body->setLinearVelocity(blah) nor body->translate(blah) have any effect on its position in space.
C) Kinematic objects, which are objects without mass, but the user can move them. There is one-way interaction, and Bullet calculates a velocity based on the timestep and previous and current world transform. Bullet automatically deactivates dynamic rigid bodies, when the velocity is below a threshold for a given time. Deactivated (sleeping) rigid bodies don't take any processing time, except a minor broadphase collision detection impact (to allow active objects to activate/wake up sleeping objects). My comment: This description is a little confusing...in order to use this kind of body (at least I think this is how), I gave my rigid body a 0 mass and flagged it as kinematic (activated its kinematic flag). However, I'm not sure why the description suggests that this kind of body can be moved, because, again, neither body->setLinearVelocity(blah) nor body->translate(blah) had any effect on the position of my kinematic rigid body. I'm probably using this type of rigid body incorrectly...

So, those are my experiences with trying to keep a dynamic object still until I want it to move. Maybe they'll help :-/

--Leezer
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Static vs Dynamic

Post by Erwin Coumans »

I'll make sure to provide some demo for Bullet 2.76 to show how to deal with those cases, sometimes next week.

Thanks,
Erwin
Calvin1602
Posts: 3
Joined: Thu Jan 28, 2010 12:40 pm

Re: Static vs Dynamic

Post by Calvin1602 »

Thank you both for your comments.

I eventually made it work, but my solution is even more weird than Leezer's.

First, a few complains (positive points follow :) ):
- I'm quite disappointed with the consistency of the API. Sometimes you need to setup a callback. Sometimes you need to override a method.
- The documentation is ... sparse.
- There is no way to create a cylinder/capsule between 2 3D points (that's no big deal for me, but I guess some users would love it, especially for ragdolls)

In a word, I found it hard to tell Bullet exactly what I needed it to do. The API seems quite straightforward in the "standard" use-case (which is good !), but harder to fine-tune.

Here is what I wanted to have :
1 - a moving but static world (i.e kinematic).
2 - a ragdoll entirely controlled by an animated squeletton (i.e. no dynamics; just move the way I tell you !)
3 - a callback when my ragdoll collides with the world
4 - turning the ragdoll into a dynamic object inside that callback.

Here is what I ended up doing :
1 - I wrote a small ObjectInfo struct. It was initially just an integer to specify the material of the body (to speak in Newton Dynamics terms), but I had to add a pointer to my physics manager, too, because I couldn't access it in the callbacks. That felt weird.
2 - I set ::gContactAddedCallback to a custom one, specifying that only collisions between objects of type World and objects of type Ragdoll should be notify (i.e. ignore Ragdoll-Ragdoll collision. I couln'd find a way to tell Newton that all my ragdoll parts were from the same entity)

that didn't work, because the broadphase NEVER returns colliding pairs of static/kinematic objects. Which I found out after MUCH investigation in the source code.

3 - m_dynamicsWorld->getPairCache()->setOverlapFilterCallback(filterCallback); , where my filter callback always return true. This is awful, but sufficient in my specific case.
4 - I overwote the needCollision of the collision dispatcher to return yes only for World - Ragdoll collision.

... which did the trick.

I can't imagine this is the recommended way of doing this. I don't have time to improve the physics anymore, so I won't change the code, but I took the time to report my user experience so that you can figure out what I did wrong, WHY, and what could be done to improve Bullet.

Thanks
Calvin1602
Posts: 3
Joined: Thu Jan 28, 2010 12:40 pm

Re: Static vs Dynamic

Post by Calvin1602 »

As a side note, Newton has a way to specify callbacks for all materials pairs ( ie I want a special behaviour for Wall<->Ghost collisions), for both broad- and corephase.
The API has serious flaws, but it's very flexible and easy to tune to one's specific needs.
Ugras
Posts: 34
Joined: Wed Dec 30, 2009 8:30 pm

Re: Static vs Dynamic

Post by Ugras »

Is there a specific example in Bullet 2.76 for the case of Calvin1602? Because my problem is similar.
Regards,
Ugras