mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
guard slider and cone-twist constraints against zero-length axisq
This commit is contained in:
parent
f8cab08b19
commit
55056e730a
2 changed files with 40 additions and 12 deletions
|
@ -17,12 +17,12 @@
|
|||
|
||||
|
||||
const uint16_t ObjectConstraintConeTwist::constraintVersion = 1;
|
||||
|
||||
const glm::vec3 DEFAULT_CONE_TWIST_AXIS(1.0f, 0.0f, 0.0f);
|
||||
|
||||
ObjectConstraintConeTwist::ObjectConstraintConeTwist(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
ObjectConstraint(DYNAMIC_TYPE_CONE_TWIST, id, ownerEntity),
|
||||
_pivotInA(glm::vec3(0.0f)),
|
||||
_axisInA(glm::vec3(0.0f))
|
||||
_axisInA(DEFAULT_CONE_TWIST_AXIS),
|
||||
_axisInB(DEFAULT_CONE_TWIST_AXIS)
|
||||
{
|
||||
#if WANT_DEBUG
|
||||
qCDebug(physics) << "ObjectConstraintConeTwist::ObjectConstraintConeTwist";
|
||||
|
@ -109,11 +109,25 @@ btTypedConstraint* ObjectConstraintConeTwist::getConstraint() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (glm::length(axisInA) < FLT_EPSILON) {
|
||||
qCWarning(physics) << "cone-twist axis cannot be a zero vector";
|
||||
axisInA = DEFAULT_CONE_TWIST_AXIS;
|
||||
} else {
|
||||
axisInA = glm::normalize(axisInA);
|
||||
}
|
||||
|
||||
if (!otherEntityID.isNull()) {
|
||||
// This coneTwist is between two entities... find the other rigid body.
|
||||
|
||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInB));
|
||||
if (glm::length(axisInB) < FLT_EPSILON) {
|
||||
qCWarning(physics) << "cone-twist axis cannot be a zero vector";
|
||||
axisInB = DEFAULT_CONE_TWIST_AXIS;
|
||||
} else {
|
||||
axisInB = glm::normalize(axisInB);
|
||||
}
|
||||
|
||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInA);
|
||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInB);
|
||||
|
||||
btTransform frameInA(glmToBullet(rotA), glmToBullet(pivotInA));
|
||||
btTransform frameInB(glmToBullet(rotB), glmToBullet(pivotInB));
|
||||
|
@ -127,7 +141,7 @@ btTypedConstraint* ObjectConstraintConeTwist::getConstraint() {
|
|||
} else {
|
||||
// This coneTwist is between an entity and the world-frame.
|
||||
|
||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInA);
|
||||
|
||||
btTransform frameInA(glmToBullet(rot), glmToBullet(pivotInA));
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
|
||||
|
||||
const uint16_t ObjectConstraintSlider::constraintVersion = 1;
|
||||
|
||||
const glm::vec3 DEFAULT_SLIDER_AXIS(1.0f, 0.0f, 0.0f);
|
||||
|
||||
ObjectConstraintSlider::ObjectConstraintSlider(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||
ObjectConstraint(DYNAMIC_TYPE_SLIDER, id, ownerEntity),
|
||||
_pointInA(glm::vec3(0.0f)),
|
||||
_axisInA(glm::vec3(0.0f))
|
||||
_axisInA(DEFAULT_SLIDER_AXIS),
|
||||
_axisInB(DEFAULT_SLIDER_AXIS)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -91,11 +91,25 @@ btTypedConstraint* ObjectConstraintSlider::getConstraint() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (glm::length(axisInA) < FLT_EPSILON) {
|
||||
qCWarning(physics) << "slider axis cannot be a zero vector";
|
||||
axisInA = DEFAULT_SLIDER_AXIS;
|
||||
} else {
|
||||
axisInA = glm::normalize(axisInA);
|
||||
}
|
||||
|
||||
if (!otherEntityID.isNull()) {
|
||||
// This slider is between two entities... find the other rigid body.
|
||||
|
||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInB));
|
||||
if (glm::length(axisInB) < FLT_EPSILON) {
|
||||
qCWarning(physics) << "slider axis cannot be a zero vector";
|
||||
axisInB = DEFAULT_SLIDER_AXIS;
|
||||
} else {
|
||||
axisInB = glm::normalize(axisInB);
|
||||
}
|
||||
|
||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInA);
|
||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInB);
|
||||
|
||||
btTransform frameInA(glmToBullet(rotA), glmToBullet(pointInA));
|
||||
btTransform frameInB(glmToBullet(rotB), glmToBullet(pointInB));
|
||||
|
@ -109,7 +123,7 @@ btTypedConstraint* ObjectConstraintSlider::getConstraint() {
|
|||
} else {
|
||||
// This slider is between an entity and the world-frame.
|
||||
|
||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), axisInA);
|
||||
|
||||
btTransform frameInA(glmToBullet(rot), glmToBullet(pointInA));
|
||||
|
||||
|
|
Loading…
Reference in a new issue