I look at the Basic Demo.
I found this in DemoApplication.cpp , line 748. It creates a constraint on the picked cube and then set the constraint position under the mouse cursor, making the cube moving.
However, I do not understand what pickedBody->setActivationState(DISABLE_DEACTIVATION); and pickedBody->forceActivationState(ACTIVE_TAG); are for. I did not find documentation about the ActivationState
Somebody has explainations?
Code: Select all
{
if (state==0)
{
//add a point to point constraint for picking
if (m_dynamicsWorld)
{
btVector3 rayFrom;
if (m_ortho)
{
rayFrom = rayTo;
rayFrom.setZ(-100.f);
} else
{
rayFrom = m_cameraPosition;
}
btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom,rayTo);
m_dynamicsWorld->rayTest(rayFrom,rayTo,rayCallback);
if (rayCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
if (body)
{
//other exclusions?
if (!(body->isStaticObject() || body->isKinematicObject()))
{
pickedBody = body;
pickedBody->setActivationState(DISABLE_DEACTIVATION);
btVector3 pickPos = rayCallback.m_hitPointWorld;
printf("pickPos=%f,%f,%f\n",pickPos.getX(),pickPos.getY(),pickPos.getZ());
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
if (use6Dof)
{
btTransform tr;
tr.setIdentity();
tr.setOrigin(localPivot);
btGeneric6DofConstraint* dof6 = new btGeneric6DofConstraint(*body, tr,false);
dof6->setLinearLowerLimit(btVector3(0,0,0));
dof6->setLinearUpperLimit(btVector3(0,0,0));
dof6->setAngularLowerLimit(btVector3(0,0,0));
dof6->setAngularUpperLimit(btVector3(0,0,0));
m_dynamicsWorld->addConstraint(dof6);
m_pickConstraint = dof6;
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,0);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,1);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,2);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,3);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,4);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,5);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,0);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,1);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,2);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,3);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,4);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,5);
} else
{
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot);
m_dynamicsWorld->addConstraint(p2p);
m_pickConstraint = p2p;
p2p->m_setting.m_impulseClamp = mousePickClamping;
//very weak constraint for picking
p2p->m_setting.m_tau = 0.001f;
/*
p2p->setParam(BT_CONSTRAINT_CFM,0.8,0);
p2p->setParam(BT_CONSTRAINT_CFM,0.8,1);
p2p->setParam(BT_CONSTRAINT_CFM,0.8,2);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,0);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,1);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,2);
*/
}
use6Dof = !use6Dof;
//save mouse position for dragging
gOldPickingPos = rayTo;
gHitPos = pickPos;
gOldPickingDist = (pickPos-rayFrom).length();
}
}
}
}
} else
{
if (m_pickConstraint && m_dynamicsWorld)
{
m_dynamicsWorld->removeConstraint(m_pickConstraint);
delete m_pickConstraint;
//printf("removed constraint %i",gPickingConstraintId);
m_pickConstraint = 0;
pickedBody->forceActivationState(ACTIVE_TAG);
pickedBody->setDeactivationTime( 0.f );
pickedBody = 0;
}
}