2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
#include "b3FixedConstraint.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3RigidBodyData.h"
|
|
|
|
#include "Bullet3Common/b3TransformUtil.h"
|
|
|
|
#include <new>
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3FixedConstraint::b3FixedConstraint(int rbA, int rbB, const b3Transform& frameInA, const b3Transform& frameInB)
|
|
|
|
: b3TypedConstraint(B3_FIXED_CONSTRAINT_TYPE, rbA, rbB)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_pivotInA = frameInA.getOrigin();
|
|
|
|
m_pivotInB = frameInB.getOrigin();
|
2019-01-03 13:26:51 +00:00
|
|
|
m_relTargetAB = frameInA.getRotation() * frameInB.getRotation().inverse();
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3FixedConstraint::~b3FixedConstraint()
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void b3FixedConstraint::getInfo1(b3ConstraintInfo1* info, const b3RigidBodyData* bodies)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
info->m_numConstraintRows = 6;
|
|
|
|
info->nub = 6;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void b3FixedConstraint::getInfo2(b3ConstraintInfo2* info, const b3RigidBodyData* bodies)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
//fix the 3 linear degrees of freedom
|
|
|
|
|
|
|
|
const b3Vector3& worldPosA = bodies[m_rbA].m_pos;
|
|
|
|
const b3Quaternion& worldOrnA = bodies[m_rbA].m_quat;
|
2019-01-03 13:26:51 +00:00
|
|
|
const b3Vector3& worldPosB = bodies[m_rbB].m_pos;
|
2017-08-01 12:30:58 +00:00
|
|
|
const b3Quaternion& worldOrnB = bodies[m_rbB].m_quat;
|
|
|
|
|
|
|
|
info->m_J1linearAxis[0] = 1;
|
2019-01-03 13:26:51 +00:00
|
|
|
info->m_J1linearAxis[info->rowskip + 1] = 1;
|
|
|
|
info->m_J1linearAxis[2 * info->rowskip + 2] = 1;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3 a1 = b3QuatRotate(worldOrnA, m_pivotInA);
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
b3Vector3* angular0 = (b3Vector3*)(info->m_J1angularAxis);
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3* angular1 = (b3Vector3*)(info->m_J1angularAxis + info->rowskip);
|
|
|
|
b3Vector3* angular2 = (b3Vector3*)(info->m_J1angularAxis + 2 * info->rowskip);
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Vector3 a1neg = -a1;
|
2019-01-03 13:26:51 +00:00
|
|
|
a1neg.getSkewSymmetricMatrix(angular0, angular1, angular2);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
if (info->m_J2linearAxis)
|
|
|
|
{
|
|
|
|
info->m_J2linearAxis[0] = -1;
|
2019-01-03 13:26:51 +00:00
|
|
|
info->m_J2linearAxis[info->rowskip + 1] = -1;
|
|
|
|
info->m_J2linearAxis[2 * info->rowskip + 2] = -1;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
b3Vector3 a2 = b3QuatRotate(worldOrnB, m_pivotInB);
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
// b3Vector3 a2n = -a2;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Vector3* angular0 = (b3Vector3*)(info->m_J2angularAxis);
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3* angular1 = (b3Vector3*)(info->m_J2angularAxis + info->rowskip);
|
|
|
|
b3Vector3* angular2 = (b3Vector3*)(info->m_J2angularAxis + 2 * info->rowskip);
|
|
|
|
a2.getSkewSymmetricMatrix(angular0, angular1, angular2);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
// set right hand side for the linear dofs
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Scalar k = info->fps * info->erp;
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3 linearError = k * (a2 + worldPosB - a1 - worldPosA);
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
info->m_constraintError[j * info->rowskip] = linearError[j];
|
2017-08-01 12:30:58 +00:00
|
|
|
//printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
//fix the 3 angular degrees of freedom
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
int start_row = 3;
|
|
|
|
int s = info->rowskip;
|
2019-01-03 13:26:51 +00:00
|
|
|
int start_index = start_row * s;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
// 3 rows to make body rotations equal
|
2017-08-01 12:30:58 +00:00
|
|
|
info->m_J1angularAxis[start_index] = 1;
|
2019-01-03 13:26:51 +00:00
|
|
|
info->m_J1angularAxis[start_index + s + 1] = 1;
|
|
|
|
info->m_J1angularAxis[start_index + s * 2 + 2] = 1;
|
|
|
|
if (info->m_J2angularAxis)
|
|
|
|
{
|
|
|
|
info->m_J2angularAxis[start_index] = -1;
|
|
|
|
info->m_J2angularAxis[start_index + s + 1] = -1;
|
|
|
|
info->m_J2angularAxis[start_index + s * 2 + 2] = -1;
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
// set right hand side for the angular dofs
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
b3Vector3 diff;
|
|
|
|
b3Scalar angle;
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Quaternion qrelCur = worldOrnA * worldOrnB.inverse();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3TransformUtil::calculateDiffAxisAngleQuaternion(m_relTargetAB, qrelCur, diff, angle);
|
|
|
|
diff *= -angle;
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
info->m_constraintError[(3 + j) * info->rowskip] = k * diff[j];
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|