Switching Rigid Body to a Kinematic At Runtime user control

Garibalde

27-12-2009 05:22:30

Hi

I am new to bullet. Have a bunch of objects in the simulation (using Ogre) that needs to collide with each other.
I will take control of one of these objects and drive it via Mouse and keyboard and make them collide with other
objects in the simulation. I can then change the selected object to another one in the scene at runtime by pressing
a keyboard key ("space").

I ahve all the objects loaded in the simulation the start in the air and fall to the ground. I see the effect of collision between the floor and the objects. Also between two objects on the fall (There is no user control activated here yet). Below is the code i use to setup the rigid body objects.


_cprintf("-> Creating Physics model %s.\n",(*p)->ObjectName.c_str());
BtOgre::StaticMeshToShapeConverter converter(MyEntity);
(*p)->mObjShape = converter.createBox();
(*p)->mObjShape->setLocalScaling(btVector3((*p)->AxisScaling[0],(*p)->AxisScaling[1],(*p)->AxisScaling[2]));

//Calculate inertia.
btScalar mass = 2;
btVector3 inertia;
(*p)->mObjShape->calculateLocalInertia(mass, inertia);

//Create BtOgre MotionState (connects Ogre and Bullet).
(*p)->mObjState = new BtOgre::RigidBodyState((*p)->mObjNode);


The at runtime when the object is switched i dot he following. I get the object RigidBodyState and apply the following:

ActiveToolName = ObjArray.GetObjectFromList(ActiveToolToggle);
ObjectPtr ObjData = ObjArray.GetObjectPtrGivenIndx(ActiveToolToggle);
ObjData->mObjBody->setCollisionFlags(ObjData->mObjBody->getCollisionFlags() | CollisionObject::CF_KINEMATIC_OBJECT);


When i move the keyboard and Mouse i collect the information and set the following Where cpos and Ori are the current position and orientation of the object controlled by the user.

ObjData->mObjBody->setWorldTransform(btTransform(btQuaternion(Ori.x,Ori.y,Ori.z,Ori.w),btVector3(cPos.x,cPos.y,cPos.z)));


Therefore here is the QUESTION:
It seems that the controlled pobject does not collide with the other objects in the scene and cause any physic effects. They just passthrough them!!! What am i doing wrong to enable a CONTROLLED object that can create physics effects at runtime with other righidbodies in the Simulation.

Any help you can provide woult be greatful. am lost i just need a hint of sorts to proceed. A example code would be great.

Garibalde

Garibalde

27-12-2009 06:06:31

Here are two pictures i captures from the debugdrawer in bullet/Ogre.

The first picture shows the initial configuration of the sim.

[attachment=1]image2.jpg[/attachment]

The second picture shows after i ahve moved the selected objects they are now in collision with each other there should be physics motion of the other objects the ball and the pick.

[attachment=0]image1.jpg[/attachment]

Hope this clears my post above if it wasnt clear before.

Thanks.
Garibalde

Fish

27-12-2009 12:52:08

Do you really need to convert the object to a Kinematic object? My understanding of Kinematic objects is that you have to handle all of the collisions yourself via callbacks, but that may have changed (the Bullet forums may have more info on that). Can you leave the object as a dynamic rigid body and simply update the btTransform for the user controlled object or maybe apply a force to the object in the direction of the mouse/keyboard movement instead of setting the btTransform each frame? The Bullet demos allow object picking and moving, you could read the Bullet demos to see how they handle it.

You could also search the Bullet Forums, Bullet User Manual, and Bullet Wiki.

-Fish

Garibalde

29-12-2009 16:55:44

From what i have read on the news groups etc. it seems that switching an object to kinematics will provide
collision with other rigid bodies in the simulation. However you will have to manually calculate the effect of
the collision on the kinematic body. This is what i am interested in.

However i just tried to activate the motion of the user controlled body with the use of forces and torques
This seems to work fine. But i dont want the dynamic side effects of damping, friction, interia and etc for
the controlled body.

Here is the working code for the force/torque application. It maybe usefull for someone else looking at this
type of solution. If anyone have example code for switching an object to Kinematics and still having collision
on other rigid bodies in the simulation.


Ogre::Vector3 UserForce = mDirection * 2;
Ogre::Vector3 UserTorque = mRotateval * 15;
mToolBody->setActivationState(DISABLE_DEACTIVATION);
mToolBody->applyForce(btVector3(UserForce.x,UserForce.y,UserForce.z),btVector3(0,0,0));
mToolBody->applyTorque(btVector3(UserTorque.x,UserTorque.y,UserTorque.z));
mToolState->setWorldTransform(mToolBody->getWorldTransform());


Thanks
Garibalde