mirror of
https://github.com/overte-org/overte.git
synced 2025-07-14 14:36:37 +02:00
Merge pull request #10376 from sethalves/fix-guard-against-bad-hinge
guard against bad hinge-constraint settings
This commit is contained in:
commit
ec1c99cb71
1 changed files with 18 additions and 3 deletions
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
|
|
||||||
const uint16_t ObjectConstraintHinge::constraintVersion = 1;
|
const uint16_t ObjectConstraintHinge::constraintVersion = 1;
|
||||||
|
const glm::vec3 DEFAULT_HINGE_AXIS(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
ObjectConstraintHinge::ObjectConstraintHinge(const QUuid& id, EntityItemPointer ownerEntity) :
|
ObjectConstraintHinge::ObjectConstraintHinge(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectConstraint(DYNAMIC_TYPE_HINGE, id, ownerEntity),
|
ObjectConstraint(DYNAMIC_TYPE_HINGE, id, ownerEntity),
|
||||||
_pivotInA(glm::vec3(0.0f)),
|
_axisInA(DEFAULT_HINGE_AXIS),
|
||||||
_axisInA(glm::vec3(0.0f))
|
_axisInB(DEFAULT_HINGE_AXIS)
|
||||||
{
|
{
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qCDebug(physics) << "ObjectConstraintHinge::ObjectConstraintHinge";
|
qCDebug(physics) << "ObjectConstraintHinge::ObjectConstraintHinge";
|
||||||
|
@ -104,12 +104,27 @@ btTypedConstraint* ObjectConstraintHinge::getConstraint() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glm::length(axisInA) < FLT_EPSILON) {
|
||||||
|
qCWarning(physics) << "hinge axis cannot be a zero vector";
|
||||||
|
axisInA = DEFAULT_HINGE_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInA = glm::normalize(axisInA);
|
||||||
|
}
|
||||||
|
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
// This hinge is between two entities... find the other rigid body.
|
// This hinge is between two entities... find the other rigid body.
|
||||||
btRigidBody* rigidBodyB = getOtherRigidBody(otherEntityID);
|
btRigidBody* rigidBodyB = getOtherRigidBody(otherEntityID);
|
||||||
if (!rigidBodyB) {
|
if (!rigidBodyB) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glm::length(axisInB) < FLT_EPSILON) {
|
||||||
|
qCWarning(physics) << "hinge axis cannot be a zero vector";
|
||||||
|
axisInB = DEFAULT_HINGE_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInB = glm::normalize(axisInB);
|
||||||
|
}
|
||||||
|
|
||||||
constraint = new btHingeConstraint(*rigidBodyA, *rigidBodyB,
|
constraint = new btHingeConstraint(*rigidBodyA, *rigidBodyB,
|
||||||
glmToBullet(pivotInA), glmToBullet(pivotInB),
|
glmToBullet(pivotInA), glmToBullet(pivotInB),
|
||||||
glmToBullet(axisInA), glmToBullet(axisInB),
|
glmToBullet(axisInA), glmToBullet(axisInB),
|
||||||
|
|
Loading…
Reference in a new issue