Question about static objects

sanctus2099
Posts: 2
Joined: Wed Nov 16, 2011 2:31 pm

Question about static objects

Post by sanctus2099 »

Hello,

A couple of days before I started looking at Bullet and trying to see how it works.
I have to integrate some physics in a game for some bones of a character.
Please see the attached image.

The green box represents a bone that's animated by artists and the red ones should be animated using physics.
I created rigid bodies for all the bones and made the green one static (mass = 0). On each frame I update it's position using
getMotionState()->setWorldTransform() using the transformation from the bone. The other bones are connected using Point2PointConstrains.
The problem is that the green bone won't update the position and thus the other ones won't follow it.

Has anyone tried this before and made it work? Am I doing something wrong?

Thank you
You do not have the required permissions to view the files attached to this post.
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

Re: Question about static objects

Post by marios »

Generally you shouldn't move your static body. Static bodies are predefined as non moving bodies, but if you really want to do that, I think this can help you:

dynamicsWorld->updateSingleAabb(body1);

add this line after setting world position of body1 which is static
User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Re: Question about static objects

Post by jarno »

What you're looking for is a kinematic object. They are like static objects but can be moved. You set them up the same way as static objects (0 mass), but set the collision flag to btCollisionObject::CF_KINEMATIC_OBJECT instead of CF_STATIC_OBJECT.

---JvdL---
sanctus2099
Posts: 2
Joined: Wed Nov 16, 2011 2:31 pm

Re: Question about static objects

Post by sanctus2099 »

Thank you, turning the body into a kinematic one seems to have fixed my problem :)

Now I have to create boxes out of the bones and I'm not sure if I chose the right way.
Here is how I do it now:
Let's call the bones bone0-bone2 (top-down).
I take the transformation matrix of bone0 and set the translation as the average positon between bone0 and bone1 so I get a translation that's in the middle of bone 0. I check the length from bone0 to bone1 and thus I get the length of my bone and I create the shape (box). I do this for all the bones.

Then when I create constraints I do this:
btPoint2PointConstraint* constraint = new btPoint2PointConstraint(*bone0, *bone1,btVector3(0,0,-bone0len/2.0),btVector3(0,0,bone1len/2.0));

Right now the bones are spinning aimlessly.
The size for a bone is something like 0.01,0.01,0.5 and I set the mass as 0.1 and the gravity of -10.

Could anyone help me with this?

Thank you