Ver código fonte

Merge pull request #523 from blackberry-gaming/next-sgrenier

Next sgrenier
Steve Grenier 13 anos atrás
pai
commit
fe8fade270
2 arquivos alterados com 15 adições e 30 exclusões
  1. 13 27
      gameplay/src/PhysicsConstraint.cpp
  2. 2 3
      gameplay/src/PhysicsConstraint.h

+ 13 - 27
gameplay/src/PhysicsConstraint.cpp

@@ -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, &center);
-        }
-        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(&center);
-        }
+        // 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(&center);
     return center;
 }
 

+ 2 - 3
gameplay/src/PhysicsConstraint.h

@@ -2,7 +2,6 @@
 #define PHYSICSCONSTRAINT_H_
 
 #include "Base.h"
-#include "Model.h"
 #include "Vector3.h"
 
 namespace gameplay
@@ -93,9 +92,9 @@ protected:
     static btTransform getTransformOffset(const Node* node, const Vector3& origin);
     
     /**
-     * Calculates the center of mass in world space of the given model.
+     * Calculates the center of mass in world space of the given node.
      */
-    static Vector3 getWorldCenterOfMass(const Model* model);
+    static Vector3 getWorldCenterOfMass(const Node* node);
 
     /**
      * Offsets the given vector by the given node's center of mass.