accept constraint with single rigidbody

This commit is contained in:
ejcoumans
2007-01-19 03:48:54 +00:00
parent 959e4498f4
commit 7b5301bb43
2 changed files with 61 additions and 27 deletions

View File

@@ -537,8 +537,8 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
const domRigid_constraint::domRef_attachmentRef attachRefBody = rigidConstraintRef->getRef_attachment(); const domRigid_constraint::domRef_attachmentRef attachRefBody = rigidConstraintRef->getRef_attachment();
const domRigid_constraint::domAttachmentRef attachBody1 = rigidConstraintRef->getAttachment(); const domRigid_constraint::domAttachmentRef attachBody1 = rigidConstraintRef->getAttachment();
daeString orgUri0 = attachRefBody->getRigid_body().getOriginalURI(); daeString orgUri0 = attachRefBody ? attachRefBody->getRigid_body().getOriginalURI() : "";
daeString orgUri1 = attachBody1->getRigid_body().getOriginalURI(); daeString orgUri1 = attachBody1 ? attachBody1->getRigid_body().getOriginalURI() : "";
btRigidBody* body0=0,*body1=0; btRigidBody* body0=0,*body1=0;
for (int i=0;i<m_numObjects;i++) for (int i=0;i<m_numObjects;i++)
@@ -579,21 +579,30 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
{ {
btTransform attachFrameRef0; btTransform attachFrameRef0;
attachFrameRef0 = attachFrameRef0.setIdentity();
GetbtTransformFromCOLLADA_DOM
( if (attachRefBody)
emptyMatrixArray, {
attachRefBody->getRotate_array(), attachFrameRef0 =
attachRefBody->getTranslate_array()); GetbtTransformFromCOLLADA_DOM
(
emptyMatrixArray,
attachRefBody->getRotate_array(),
attachRefBody->getTranslate_array());
}
btTransform attachFrameOther; btTransform attachFrameOther;
attachFrameOther = attachFrameOther.setIdentity();
GetbtTransformFromCOLLADA_DOM if (attachBody1)
( {
emptyMatrixArray, attachFrameOther =
attachBody1->getRotate_array(), GetbtTransformFromCOLLADA_DOM
attachBody1->getTranslate_array() (
); emptyMatrixArray,
attachBody1->getRotate_array(),
attachBody1->getTranslate_array()
);
}
//convert INF / -INF into lower > upper //convert INF / -INF into lower > upper
@@ -639,18 +648,34 @@ void ColladaConverter::prepareConstraints(ConstraintInput& input)
} }
if (body0&& body1) if (body0 || body1)
{ {
createUniversalD6Constraint( //swap so that first body is non-zero
body0, if (!body0)
body1, {
attachFrameRef0, createUniversalD6Constraint(
attachFrameOther, body1,
linearLowerLimits, body0,
linearUpperLimits, attachFrameOther,
angularLowerLimits, attachFrameRef0,
angularUpperLimits linearLowerLimits,
); linearUpperLimits,
angularLowerLimits,
angularUpperLimits
);
} else
{
createUniversalD6Constraint(
body0,
body1,
attachFrameRef0,
attachFrameOther,
linearLowerLimits,
linearUpperLimits,
angularLowerLimits,
angularUpperLimits
);
}
} else } else
{ {
printf("Error: Cannot find Rigidbodies(%s,%s) for constraint %s\n",orgUri0,orgUri1,constraintName); printf("Error: Cannot find Rigidbodies(%s,%s) for constraint %s\n",orgUri0,orgUri1,constraintName);

View File

@@ -57,8 +57,17 @@ class MyColladaConverter : public ColladaConverter
const btVector3& angularMaxLimits const btVector3& angularMaxLimits
) )
{ {
if (bodyRef && bodyOther) if (bodyRef)
{ {
if (!bodyOther)
{
bodyOther = new btRigidBody(0,0,0);
bodyOther->setWorldTransform(bodyRef->getWorldTransform());
localAttachmentOther = localAttachmentFrameRef;
}
btGeneric6DofConstraint* genericConstraint = new btGeneric6DofConstraint( btGeneric6DofConstraint* genericConstraint = new btGeneric6DofConstraint(
*bodyRef,*bodyOther, *bodyRef,*bodyOther,
localAttachmentFrameRef,localAttachmentOther); localAttachmentFrameRef,localAttachmentOther);