Added btMultiBodyPoint2Point, it can be used between btMultiBody vs btMultiBody or btMultiBody vs btRigidBody
Allow picking of btMultiBody, using a btMultiBodyPoint2Point constraint, with limited strength to avoid adding too much energy to the system (= blowup) Add btMultiBodyJointMotor, it can be used in combination with joint limit (just add the joint limit after the motor, to avoid jitter)
This commit is contained in:
@@ -773,82 +773,14 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
if (rayCallback.hasHit())
|
||||
{
|
||||
|
||||
btVector3 pickPos = rayCallback.m_hitPointWorld;
|
||||
|
||||
pickObject(pickPos, rayCallback.m_collisionObject);
|
||||
|
||||
gOldPickingPos = rayTo;
|
||||
gHitPos = pickPos;
|
||||
|
||||
btRigidBody* body = (btRigidBody*)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 ((m_modifierKeys& BT_ACTIVE_SHIFT)==0)
|
||||
{
|
||||
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,true);
|
||||
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,true);
|
||||
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);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
//save mouse position for dragging
|
||||
gOldPickingPos = rayTo;
|
||||
gHitPos = pickPos;
|
||||
|
||||
gOldPickingDist = (pickPos-rayFrom).length();
|
||||
}
|
||||
}
|
||||
gOldPickingDist = (pickPos-rayFrom).length();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -867,6 +799,78 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
|
||||
}
|
||||
|
||||
void DemoApplication::pickObject(const btVector3& pickPos, const btCollisionObject* hitObj)
|
||||
{
|
||||
|
||||
btRigidBody* body = (btRigidBody*)btRigidBody::upcast(hitObj);
|
||||
if (body)
|
||||
{
|
||||
//other exclusions?
|
||||
if (!(body->isStaticObject() || body->isKinematicObject()))
|
||||
{
|
||||
pickedBody = body;
|
||||
pickedBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
|
||||
//printf("pickPos=%f,%f,%f\n",pickPos.getX(),pickPos.getY(),pickPos.getZ());
|
||||
|
||||
|
||||
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
|
||||
|
||||
if ((m_modifierKeys& BT_ACTIVE_SHIFT)==0)
|
||||
{
|
||||
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,true);
|
||||
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,true);
|
||||
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);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
//save mouse position for dragging
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DemoApplication::removePickingConstraint()
|
||||
{
|
||||
if (m_pickConstraint && m_dynamicsWorld)
|
||||
|
||||
Reference in New Issue
Block a user