Selaa lähdekoodia

Merge branch 'next' of https://github.com/blackberry-gaming/GamePlay into next-ablake

Adam Blake 14 vuotta sitten
vanhempi
sitoutus
7f238d232b

+ 8 - 8
gameplay/src/PhysicsController.cpp

@@ -109,7 +109,7 @@ PhysicsSpringConstraint* PhysicsController::createSpringConstraint(PhysicsRigidB
     return constraint;
     return constraint;
 }
 }
 
 
-const Vector3& PhysicsController::getGravity(const Vector3& gravity) const
+const Vector3& PhysicsController::getGravity() const
 {
 {
     return _gravity;
     return _gravity;
 }
 }
@@ -175,7 +175,7 @@ btScalar PhysicsController::addSingleResult(btManifoldPoint& cp, const btCollisi
         collisionInfo._status = 0;
         collisionInfo._status = 0;
 
 
         // Add the appropriate listeners.
         // Add the appropriate listeners.
-        PhysicsRigidBody::CollisionPair p1(pair._rbA, NULL);
+        PhysicsRigidBody::CollisionPair p1(pair.rigidBodyA, NULL);
         if (_collisionStatus.count(p1) > 0)
         if (_collisionStatus.count(p1) > 0)
         {
         {
             const CollisionInfo& ci = _collisionStatus[p1];
             const CollisionInfo& ci = _collisionStatus[p1];
@@ -185,7 +185,7 @@ btScalar PhysicsController::addSingleResult(btManifoldPoint& cp, const btCollisi
                 collisionInfo._listeners.push_back(*iter);
                 collisionInfo._listeners.push_back(*iter);
             }
             }
         }
         }
-        PhysicsRigidBody::CollisionPair p2(pair._rbB, NULL);
+        PhysicsRigidBody::CollisionPair p2(pair.rigidBodyB, NULL);
         if (_collisionStatus.count(p2) > 0)
         if (_collisionStatus.count(p2) > 0)
         {
         {
             const CollisionInfo& ci = _collisionStatus[p2];
             const CollisionInfo& ci = _collisionStatus[p2];
@@ -336,10 +336,10 @@ void PhysicsController::update(long elapsedTime)
         // of collision pairs in the status cache that we did not explicitly register for.)
         // of collision pairs in the status cache that we did not explicitly register for.)
         if ((iter->second._status & REGISTERED) != 0 && (iter->second._status & REMOVE) == 0)
         if ((iter->second._status & REGISTERED) != 0 && (iter->second._status & REMOVE) == 0)
         {
         {
-            if (iter->first._rbB)
-                _world->contactPairTest(iter->first._rbA->_body, iter->first._rbB->_body, *this);
+            if (iter->first.rigidBodyB)
+                _world->contactPairTest(iter->first.rigidBodyA->_body, iter->first.rigidBodyB->_body, *this);
             else
             else
-                _world->contactTest(iter->first._rbA->_body, *this);
+                _world->contactTest(iter->first.rigidBodyA->_body, *this);
         }
         }
     }
     }
 
 
@@ -349,7 +349,7 @@ void PhysicsController::update(long elapsedTime)
     {
     {
         if ((iter->second._status & DIRTY) != 0)
         if ((iter->second._status & DIRTY) != 0)
         {
         {
-            if ((iter->second._status & COLLISION) != 0 && iter->first._rbB)
+            if ((iter->second._status & COLLISION) != 0 && iter->first.rigidBodyB)
             {
             {
                 unsigned int size = iter->second._listeners.size();
                 unsigned int size = iter->second._listeners.size();
                 for (unsigned int i = 0; i < size; i++)
                 for (unsigned int i = 0; i < size; i++)
@@ -427,7 +427,7 @@ void PhysicsController::removeRigidBody(PhysicsRigidBody* rigidBody)
     std::map<PhysicsRigidBody::CollisionPair, CollisionInfo>::iterator iter = _collisionStatus.begin();
     std::map<PhysicsRigidBody::CollisionPair, CollisionInfo>::iterator iter = _collisionStatus.begin();
     for (; iter != _collisionStatus.end(); iter++)
     for (; iter != _collisionStatus.end(); iter++)
     {
     {
-        if (iter->first._rbA == rigidBody || iter->first._rbB == rigidBody)
+        if (iter->first.rigidBodyA == rigidBody || iter->first.rigidBodyB == rigidBody)
             iter->second._status |= REMOVE;
             iter->second._status |= REMOVE;
     }
     }
 }
 }

+ 1 - 1
gameplay/src/PhysicsController.h

@@ -173,7 +173,7 @@ public:
      * 
      * 
      * @return The gravity vector.
      * @return The gravity vector.
      */
      */
-    const Vector3& getGravity(const Vector3& gravity) const;
+    const Vector3& getGravity() const;
 
 
     /**
     /**
      * Sets the gravity vector for the simulated physics world.
      * Sets the gravity vector for the simulated physics world.

+ 2 - 2
gameplay/src/PhysicsRigidBody.cpp

@@ -561,8 +561,8 @@ void PhysicsRigidBody::transformChanged(Transform* transform, long cookie)
     _inverseIsDirty = true;
     _inverseIsDirty = true;
 }
 }
 
 
-PhysicsRigidBody::CollisionPair::CollisionPair(PhysicsRigidBody* rbA, PhysicsRigidBody* rbB)
-    : _rbA(rbA), _rbB(rbB)
+PhysicsRigidBody::CollisionPair::CollisionPair(PhysicsRigidBody* rigidBodyA, PhysicsRigidBody* rigidBodyB)
+    : rigidBodyA(rigidBodyA), rigidBodyB(rigidBodyB)
 {
 {
     // Unused
     // Unused
 }
 }

+ 5 - 5
gameplay/src/PhysicsRigidBody.h

@@ -49,21 +49,21 @@ public:
         /**
         /**
          * Constructor.
          * Constructor.
          */
          */
-        CollisionPair(PhysicsRigidBody* rbA, PhysicsRigidBody* rbB);
+        CollisionPair(PhysicsRigidBody* rigidBodyA, PhysicsRigidBody* rigidBodyB);
 
 
         /**
         /**
          * Less than operator (needed for use as a key in map).
          * Less than operator (needed for use as a key in map).
          * 
          * 
-         * @param cp The collision pair to compare.
+         * @param collisionPair The collision pair to compare.
          * @return True if this pair is "less than" the given pair; false otherwise.
          * @return True if this pair is "less than" the given pair; false otherwise.
          */
          */
-        bool operator<(const CollisionPair& cp) const;
+        bool operator<(const CollisionPair& collisionPair) const;
 
 
         /** The first rigid body in the collision. */
         /** The first rigid body in the collision. */
-        PhysicsRigidBody* _rbA;
+        PhysicsRigidBody* rigidBodyA;
 
 
         /** The second rigid body in the collision. */
         /** The second rigid body in the collision. */
-        PhysicsRigidBody* _rbB;
+        PhysicsRigidBody* rigidBodyB;
     };
     };
 
 
     /**
     /**

+ 6 - 6
gameplay/src/PhysicsRigidBody.inl

@@ -123,18 +123,18 @@ inline void PhysicsRigidBody::setRestitution(float restitution)
     _body->setRestitution(restitution);
     _body->setRestitution(restitution);
 }
 }
 
 
-inline bool PhysicsRigidBody::CollisionPair::operator<(const CollisionPair& cp) const
+inline bool PhysicsRigidBody::CollisionPair::operator<(const CollisionPair& collisionPair) const
 {
 {
     // If the pairs are equal, then return false.
     // If the pairs are equal, then return false.
-    if ((_rbA == cp._rbA && _rbB == cp._rbB) || (_rbA == cp._rbB && _rbB == cp._rbA))
+    if ((rigidBodyA == collisionPair.rigidBodyA && rigidBodyB == collisionPair.rigidBodyB) || (rigidBodyA == collisionPair.rigidBodyB && rigidBodyB == collisionPair.rigidBodyA))
         return false;
         return false;
     else
     else
     {
     {
-        // We choose to compare based on _rbA arbitrarily.
-        if (_rbA < cp._rbA)
+        // We choose to compare based on rigidBodyA arbitrarily.
+        if (rigidBodyA < collisionPair.rigidBodyA)
             return true;
             return true;
-        else if (_rbA == cp._rbA)
-            return _rbB < cp._rbB;
+        else if (rigidBodyA == collisionPair.rigidBodyA)
+            return rigidBodyB < collisionPair.rigidBodyB;
         else
         else
             return false;
             return false;
     }
     }

+ 25 - 1
gameplay/src/Ray.cpp

@@ -105,7 +105,31 @@ float Ray::intersects(const Frustum& frustum) const
 
 
 float Ray::intersects(const Plane& plane) const
 float Ray::intersects(const Plane& plane) const
 {
 {
-    return plane.intersects(*this);
+    const Vector3& normal = plane.getNormal();
+    // If the origin of the ray is on the plane then the distance is zero.
+    float m = (normal.dot(_origin) + plane.getDistance());
+    if (fabs(m) < MATH_EPSILON)
+    {
+        return 0.0f;
+    }
+
+    float dot = normal.dot(_direction);
+    
+    // If the dot product of the plane's normal and this ray's direction is zero,
+    // then the ray is parallel to the plane and does not intersect it.
+    if ( dot == 0.0f )
+    {
+        return INTERSECTS_NONE;
+    }
+    
+    // Calculate the distance along the ray's direction vector to the point where
+    // the ray intersects the plane (if it is negative the plane is behind the ray).
+    float d = -m / dot;
+    if ( d < 0.0f )
+    {
+        return INTERSECTS_NONE;
+    }
+    return d;
 }
 }
 
 
 void Ray::set(const Vector3& origin, const Vector3& direction)
 void Ray::set(const Vector3& origin, const Vector3& direction)

+ 2 - 1
gameplay/src/Ray.h

@@ -110,7 +110,8 @@ public:
     float intersects(const Frustum& frustum) const;
     float intersects(const Frustum& frustum) const;
 
 
     /**
     /**
-     * Tests whether this ray intersects the specified plane.
+     * Tests whether this ray intersects the specified plane and returns the distance
+     * from the origin of the ray to the plane.
      *
      *
      * @param plane The plane to test intersection with.
      * @param plane The plane to test intersection with.
      * 
      * 

+ 2 - 2
gameplay/src/SpriteBatch.cpp

@@ -251,8 +251,8 @@ void SpriteBatch::draw(const Vector3& position, const Vector3& right, const Vect
 {
 {
     // Calculate the vertex positions.
     // Calculate the vertex positions.
     Vector3 p[4];
     Vector3 p[4];
-    p[0] = position - 0.5f * width * right;
-    p[1] = position + 0.5f * width * right;
+    p[0] = position - 0.5f * width * right - 0.5f * height * forward;
+    p[1] = position + 0.5f * width * right - 0.5f * height * forward;
     p[2] = p[0] + height * forward;
     p[2] = p[0] + height * forward;
     p[3] = p[1] + height * forward;
     p[3] = p[1] + height * forward;
 
 

+ 1 - 1
gameplay/src/Vector2.cpp

@@ -139,7 +139,7 @@ float Vector2::distanceSquared(const Vector2& v) const
     return (dx * dx + dy * dy);
     return (dx * dx + dy * dy);
 }
 }
 
 
-float Vector2::dot(const Vector2& v)
+float Vector2::dot(const Vector2& v) const
 {
 {
     return (x * v.x + y * v.y);
     return (x * v.x + y * v.y);
 }
 }

+ 1 - 1
gameplay/src/Vector2.h

@@ -183,7 +183,7 @@ public:
      * 
      * 
      * @return The dot product.
      * @return The dot product.
      */
      */
-    float dot(const Vector2& v);
+    float dot(const Vector2& v) const;
 
 
     /**
     /**
      * Returns the dot product between the specified vectors.
      * Returns the dot product between the specified vectors.

+ 1 - 1
gameplay/src/Vector3.cpp

@@ -203,7 +203,7 @@ float Vector3::distanceSquared(const Vector3& v) const
     return (dx * dx + dy * dy + dz * dz);
     return (dx * dx + dy * dy + dz * dz);
 }
 }
 
 
-float Vector3::dot(const Vector3& v)
+float Vector3::dot(const Vector3& v) const
 {
 {
     return (x * v.x + y * v.y + z * v.z);
     return (x * v.x + y * v.y + z * v.z);
 }
 }

+ 1 - 1
gameplay/src/Vector3.h

@@ -230,7 +230,7 @@ public:
      * 
      * 
      * @return The dot product.
      * @return The dot product.
      */
      */
-    float dot(const Vector3& v);
+    float dot(const Vector3& v) const;
 
 
     /**
     /**
      * Returns the dot product between the specified vectors.
      * Returns the dot product between the specified vectors.

+ 1 - 1
gameplay/src/Vector4.cpp

@@ -204,7 +204,7 @@ float Vector4::distanceSquared(const Vector4& v) const
     return (dx * dx + dy * dy + dz * dz + dw * dw);
     return (dx * dx + dy * dy + dz * dz + dw * dw);
 }
 }
 
 
-float Vector4::dot(const Vector4& v)
+float Vector4::dot(const Vector4& v) const
 {
 {
     return (x * v.x + y * v.y + z * v.z + w * v.w);
     return (x * v.x + y * v.y + z * v.z + w * v.w);
 }
 }

+ 1 - 1
gameplay/src/Vector4.h

@@ -221,7 +221,7 @@ public:
      * 
      * 
      * @return The dot product.
      * @return The dot product.
      */
      */
-    float dot(const Vector4& v);
+    float dot(const Vector4& v) const;
 
 
     /**
     /**
      * Returns the dot product between the specified vectors.
      * Returns the dot product between the specified vectors.