|
|
@@ -35,8 +35,8 @@ Vector3 PhysicsConstraint::centerOfMassMidpoint(const Node* a, const Node* b)
|
|
|
a->getWorldMatrix().getTranslation(&tA);
|
|
|
b->getWorldMatrix().getTranslation(&tB);
|
|
|
|
|
|
- tA = getWorldCenterOfMass(a->getModel());
|
|
|
- tB = getWorldCenterOfMass(b->getModel());
|
|
|
+ tA = getWorldCenterOfMass(a);
|
|
|
+ tB = getWorldCenterOfMass(b);
|
|
|
|
|
|
Vector3 d(tA, tB);
|
|
|
d.scale(0.5f);
|
|
|
@@ -130,36 +130,22 @@ btTransform PhysicsConstraint::getTransformOffset(const Node* node, const Vector
|
|
|
return btTransform(BQ(r), BV(t));
|
|
|
}
|
|
|
|
|
|
-Vector3 PhysicsConstraint::getWorldCenterOfMass(const Model* model)
|
|
|
+Vector3 PhysicsConstraint::getWorldCenterOfMass(const Node* node)
|
|
|
{
|
|
|
- GP_ASSERT(model && model->getMesh() && model->getNode());
|
|
|
+ GP_ASSERT(node);
|
|
|
|
|
|
- Vector3 center;
|
|
|
- const BoundingBox& box = model->getMesh()->getBoundingBox();
|
|
|
- if (!(box.min.isZero() && box.max.isZero()))
|
|
|
- {
|
|
|
- Vector3 bMin, bMax;
|
|
|
- model->getNode()->getWorldMatrix().transformPoint(box.min, &bMin);
|
|
|
- model->getNode()->getWorldMatrix().transformPoint(box.max, &bMax);
|
|
|
- center.set(bMin, bMax);
|
|
|
- center.scale(0.5f);
|
|
|
- center.add(bMin);
|
|
|
- }
|
|
|
- else
|
|
|
+ const BoundingSphere& sphere = node->getBoundingSphere();
|
|
|
+ if (!(sphere.center.isZero() && sphere.radius == 0))
|
|
|
{
|
|
|
- const BoundingSphere& sphere = model->getMesh()->getBoundingSphere();
|
|
|
- if (!(sphere.center.isZero() && sphere.radius == 0))
|
|
|
- {
|
|
|
- model->getNode()->getWorldMatrix().transformPoint(sphere.center, ¢er);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Warn the user that the model has no bounding volume.
|
|
|
- GP_WARN("Model '%s' has no bounding volume - center of mass is defaulting to local coordinate origin.", model->getNode()->getId());
|
|
|
- model->getNode()->getWorldMatrix().transformPoint(¢er);
|
|
|
- }
|
|
|
+ // The world-space center of mass is the sphere's center.
|
|
|
+ return sphere.center;
|
|
|
}
|
|
|
|
|
|
+ // Warn the user that the node has no bounding volume.
|
|
|
+ GP_WARN("Node %s' has no bounding volume - center of mass is defaulting to local coordinate origin.", node->getId());
|
|
|
+
|
|
|
+ Vector3 center;
|
|
|
+ node->getWorldMatrix().transformPoint(¢er);
|
|
|
return center;
|
|
|
}
|
|
|
|