Reseting dynamic object's motion?

Post Reply
suckho
Posts: 3
Joined: Wed Nov 25, 2009 9:03 pm

Reseting dynamic object's motion?

Post by suckho »

I'm very new to Bullet and I guess this is very basic (read: stupid) question, but I couldn't find the answer anywhere so here it comes..

I started integrating Bullet to my 3D engine and actually managed to do lot of things right.. My test scene consists of couple of static/kinematic 3d objects and 100 dynamic primitive shapes falling over them. These 100 falling objects are somewhere at Y=100 meters height in the beginning and then drop in free fall.

I wanted to prevent objects falling "away" so I did a check like "if (y<0) resetObject()", but couldnt get it working. My PhysObject class is derived from btMotionState and uses that for sync between gfx and phys engines. The problem is that I dont know how to reset dynamic btRigidBody's motionstate WITHOUT interpolation. I mean that when object is dropped to Y=0 level, I want it to warp back to Y=100 without interpolation and reset it's motion state (velocity, angular velocity, position, rotation, etc).

What is the proper way to do this? Let's say if I want to write a resetObject() function, what calls to btRigidBody should it include to reset everything to the state body were after creation? I want to keep the same instance, so making new object is not acceptable solution.

Thanks in advance.. I'll continue to figure this out by myself but any help is appreciated..
suckho
Posts: 3
Joined: Wed Nov 25, 2009 9:03 pm

Re: Reseting dynamic object's motion?

Post by suckho »

I think it works now, but I'm still not sure if this is done by the book.. Something missing? Something too much? Do I need to set those interpolation values?

Code: Select all

void BulletPhysObject::ResetMotionState()
{	
	btTransform t;
	Quaternion rot(geomNode->GetWorldToLocalMatrix());
	Vector4 pos=geomNode->GetLocalPosInWorldSpace(Vector4(0.0f,0.0f,0.0f,1.0f));
	t.setRotation(btQuaternion(rot.x, rot.y, rot.z, rot.w));
	t.setOrigin(btVector3(pos.x, pos.y, pos.z));
		
	body->setWorldTransform(t);
	body->setLinearVelocity(btVector3(0.0f,0.0f,0.0f));
	body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f));
	
	body->setInterpolationWorldTransform(body->getWorldTransform());
	body->setInterpolationLinearVelocity(body->getLinearVelocity());
	body->setInterpolationAngularVelocity(body->getAngularVelocity());

	body->clearForces();
	body->activate();	
}

suckho
Posts: 3
Joined: Wed Nov 25, 2009 9:03 pm

Re: Reseting dynamic object's motion?

Post by suckho »

No.. It doesnt work.. Even if I try to reset object's motion this way I keep getting "old" values through MotionState's setWorldTransform().. Any ideas how this should be done?
rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: Reseting dynamic object's motion?

Post by rrck »

Try to set transform using setCenterOfMassTransform (instead of setTransform) after resetting velocities.
Post Reply