Locking a dynamic object in place.

Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Locking a dynamic object in place.

Post by Zakalwe »

Hi all, I'm trying to lock a previously dynamic object in place. I still want other objects to collide with this object, but I don't want this object to move at all. I can't figure out of how to accomplish this. Anyone got any ideas?

The objects I'm trying to lock in place were previously created like this

btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world.
m_dynamicsWorld->addRigidBody(body);
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: Locking a dynamic object in place.

Post by frca »

Maybe
body->setMassProps(0, btVector3(0,0,0));
It should make the body have infinite mass (in other words joined with the static world).
Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Re: Locking a dynamic object in place.

Post by Zakalwe »

Thanks frica, that sort of works. What happens now is the object does not move. Other objects hitting this object seem to get a bit of a "kick" though.

Here's exactly what I'm doing. I have a static terrain. I drop a cube onto it. When that cube goes to ISLAND_SLEEPING, I body->setMassProps(0, btVector3(0,0,0)); I then spawn another dropping cube. The new cube if it's coming to rest against the old cube can get a bit of an impulse when it looks like should be stopping. Anyone got any suggestions?
Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Re: Locking a dynamic object in place.

Post by Zakalwe »

I've made a very small (388k/14 second) video of the problem. Please ignore the shading errors. Watch the 4th cube at around the 10-11 seconds mark. Ther's energy being injected into the simulation somehow :/


https://www.cs.tcd.ie/~fowlerc/cubes.avi
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: Locking a dynamic object in place.

Post by Ellon »

Hi,

I assume that just setting mass props to zero would not suffice because velocities (lin & ang) when object was dynamic are preserved forever and affect future collision responses.

To be certain, check your cube's lin & ang velocity when it's locked.

If it is so, try this (extending frca's suggestion):

Code: Select all

body->setMassProps(0, btVector3(0,0,0));
body->setLinearVelocity(btVector3(0,0,0));
body->setAngularVelocity(btVector3(0,0,0);
Thanks
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Locking a dynamic object in place.

Post by AlexSilverman »

What's worked for me in the past is removing the body before changing anything, then adding it afterwards.

Code: Select all

    _pSimulationWorld->removeRigidBody(obj->GetBody());
    obj->GetBody()->setMassProps(0, btVector3(0,0,0));
    _pSimulationWorld->addRigidBody(obj->GetBody());
- Alex
Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Re: Locking a dynamic object in place.

Post by Zakalwe »

Ellon wrote:Hi,

I assume that just setting mass props to zero would not suffice because velocities (lin & ang) when object was dynamic are preserved forever and affect future collision responses.

To be certain, check your cube's lin & ang velocity when it's locked.

If it is so, try this (extending frca's suggestion):

Code: Select all

body->setMassProps(0, btVector3(0,0,0));
body->setLinearVelocity(btVector3(0,0,0));
body->setAngularVelocity(btVector3(0,0,0);
Thanks

Thanks Elon, but that doesn't seem to make a difference :(
AlexSilverman wrote:What's worked for me in the past is removing the body before changing anything, then adding it afterwards.

Code: Select all

    _pSimulationWorld->removeRigidBody(obj->GetBody());
    obj->GetBody()->setMassProps(0, btVector3(0,0,0));
    _pSimulationWorld->addRigidBody(obj->GetBody());
- Alex
My problem is that I (currently) need to keep the objects in the physics engine in the same order as the objects in the rest of the engine. I might be able to work around that though. I'll try engineering this up as a solution.
Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Re: Locking a dynamic object in place.

Post by Zakalwe »

Drat :/ Remove and adding does not work. Argghh.
ideasman42
Posts: 4
Joined: Sat Jul 25, 2009 6:06 pm

Re: Locking a dynamic object in place.

Post by ideasman42 »

it more recent versions of bullet have a stronger dampening value, in Blender3D when the rotation and translation dampening are set to 1.0, the object wont move.
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: Locking a dynamic object in place.

Post by Ellon »

What I was missing is that I should call 'body->updateInertiaTensor()' after changing body's mass props.

In fact, I've figured it out today.. Sorry to bump old thread. :)
Zakalwe
Posts: 14
Joined: Mon Feb 04, 2008 5:23 pm

Re: Locking a dynamic object in place.

Post by Zakalwe »

Excellent, I was just coming back to this today! I'll give it a whirl.