Procházet zdrojové kódy

Refactors public class that inherit from Bullet classes into protected/private inner classes.
Minor fixes to SceneLoader.

Chris Culy před 13 roky
rodič
revize
ec327eb2aa

+ 1 - 3
gameplay/gameplay.vcxproj

@@ -73,7 +73,6 @@
     <ClCompile Include="src\PhysicsGenericConstraint.cpp" />
     <ClCompile Include="src\PhysicsGenericConstraint.cpp" />
     <ClCompile Include="src\PhysicsGhostObject.cpp" />
     <ClCompile Include="src\PhysicsGhostObject.cpp" />
     <ClCompile Include="src\PhysicsHingeConstraint.cpp" />
     <ClCompile Include="src\PhysicsHingeConstraint.cpp" />
-    <ClCompile Include="src\PhysicsMotionState.cpp" />
     <ClCompile Include="src\PhysicsRigidBody.cpp" />
     <ClCompile Include="src\PhysicsRigidBody.cpp" />
     <ClCompile Include="src\PhysicsSocketConstraint.cpp" />
     <ClCompile Include="src\PhysicsSocketConstraint.cpp" />
     <ClCompile Include="src\PhysicsSpringConstraint.cpp" />
     <ClCompile Include="src\PhysicsSpringConstraint.cpp" />
@@ -167,7 +166,6 @@
     <ClInclude Include="src\PhysicsGenericConstraint.h" />
     <ClInclude Include="src\PhysicsGenericConstraint.h" />
     <ClInclude Include="src\PhysicsGhostObject.h" />
     <ClInclude Include="src\PhysicsGhostObject.h" />
     <ClInclude Include="src\PhysicsHingeConstraint.h" />
     <ClInclude Include="src\PhysicsHingeConstraint.h" />
-    <ClInclude Include="src\PhysicsMotionState.h" />
     <ClInclude Include="src\PhysicsRigidBody.h" />
     <ClInclude Include="src\PhysicsRigidBody.h" />
     <ClInclude Include="src\PhysicsSocketConstraint.h" />
     <ClInclude Include="src\PhysicsSocketConstraint.h" />
     <ClInclude Include="src\PhysicsSpringConstraint.h" />
     <ClInclude Include="src\PhysicsSpringConstraint.h" />
@@ -365,4 +363,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
   </ImportGroup>
-</Project>
+</Project>

+ 1 - 7
gameplay/gameplay.vcxproj.filters

@@ -192,9 +192,6 @@
     <ClCompile Include="src\PhysicsSpringConstraint.cpp">
     <ClCompile Include="src\PhysicsSpringConstraint.cpp">
       <Filter>src</Filter>
       <Filter>src</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="src\PhysicsMotionState.cpp">
-      <Filter>src</Filter>
-    </ClCompile>
     <ClCompile Include="src\SceneLoader.cpp">
     <ClCompile Include="src\SceneLoader.cpp">
       <Filter>src</Filter>
       <Filter>src</Filter>
     </ClCompile>
     </ClCompile>
@@ -440,9 +437,6 @@
     <ClInclude Include="src\PhysicsController.h">
     <ClInclude Include="src\PhysicsController.h">
       <Filter>src</Filter>
       <Filter>src</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="src\PhysicsMotionState.h">
-      <Filter>src</Filter>
-    </ClInclude>
     <ClInclude Include="src\PhysicsRigidBody.h">
     <ClInclude Include="src\PhysicsRigidBody.h">
       <Filter>src</Filter>
       <Filter>src</Filter>
     </ClInclude>
     </ClInclude>
@@ -715,4 +709,4 @@
       <Filter>src</Filter>
       <Filter>src</Filter>
     </None>
     </None>
   </ItemGroup>
   </ItemGroup>
-</Project>
+</Project>

+ 65 - 5
gameplay/src/PhysicsCollisionObject.cpp

@@ -2,6 +2,7 @@
 #include "PhysicsCollisionObject.h"
 #include "PhysicsCollisionObject.h"
 #include "PhysicsController.h"
 #include "PhysicsController.h"
 #include "Game.h"
 #include "Game.h"
+#include "Node.h"
 
 
 namespace gameplay
 namespace gameplay
 {
 {
@@ -55,11 +56,6 @@ PhysicsCollisionShape* PhysicsCollisionObject::getCollisionShape() const
     return _collisionShape;
     return _collisionShape;
 }
 }
 
 
-PhysicsMotionState* PhysicsCollisionObject::getMotionState() const
-{
-    return _motionState;
-}
-
 bool PhysicsCollisionObject::isKinematic() const
 bool PhysicsCollisionObject::isKinematic() const
 {
 {
     switch (getType())
     switch (getType())
@@ -151,4 +147,68 @@ bool PhysicsCollisionObject::CollisionPair::operator < (const CollisionPair& col
     return false;
     return false;
 }
 }
 
 
+PhysicsCollisionObject::PhysicsMotionState::PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset) : _node(node),
+    _centerOfMassOffset(btTransform::getIdentity())
+{
+    if (centerOfMassOffset)
+    {
+        // Store the center of mass offset.
+        _centerOfMassOffset.setOrigin(BV(*centerOfMassOffset));
+    }
+
+    updateTransformFromNode();
+}
+
+PhysicsCollisionObject::PhysicsMotionState::~PhysicsMotionState()
+{
+}
+
+void PhysicsCollisionObject::PhysicsMotionState::getWorldTransform(btTransform &transform) const
+{
+    GP_ASSERT(_node);
+    if (_node->getCollisionObject() && _node->getCollisionObject()->isKinematic())
+        updateTransformFromNode();
+
+    transform = _centerOfMassOffset.inverse() * _worldTransform;
+}
+
+void PhysicsCollisionObject::PhysicsMotionState::setWorldTransform(const btTransform &transform)
+{
+    GP_ASSERT(_node);
+
+    _worldTransform = transform * _centerOfMassOffset;
+        
+    const btQuaternion& rot = _worldTransform.getRotation();
+    const btVector3& pos = _worldTransform.getOrigin();
+
+    _node->setRotation(rot.x(), rot.y(), rot.z(), rot.w());
+    _node->setTranslation(pos.x(), pos.y(), pos.z());
+}
+
+void PhysicsCollisionObject::PhysicsMotionState::updateTransformFromNode() const
+{
+    GP_ASSERT(_node);
+
+    // Store the initial world transform (minus the scale) for use by Bullet later on.
+    Quaternion rotation;
+    const Matrix& m = _node->getWorldMatrix();
+    m.getRotation(&rotation);
+
+    if (!_centerOfMassOffset.getOrigin().isZero())
+    {
+        // When there is a center of mass offset, we modify the initial world transformation
+        // so that when physics is initially applied, the object is in the correct location.
+        btTransform offset = btTransform(BQ(rotation), btVector3(0.0f, 0.0f, 0.0f)) * _centerOfMassOffset.inverse();
+
+        btVector3 origin(m.m[12] + _centerOfMassOffset.getOrigin().getX() + offset.getOrigin().getX(), 
+                         m.m[13] + _centerOfMassOffset.getOrigin().getY() + offset.getOrigin().getY(), 
+                         m.m[14] + _centerOfMassOffset.getOrigin().getZ() + offset.getOrigin().getZ());
+        _worldTransform = btTransform(BQ(rotation), origin);
+    }
+    else
+    {
+        _worldTransform = btTransform(BQ(rotation), btVector3(m.m[12], m.m[13], m.m[14]));
+    }
+}
+
 }
 }

+ 46 - 7
gameplay/src/PhysicsCollisionObject.h

@@ -211,6 +211,52 @@ public:
 
 
 protected:
 protected:
 
 
+    /**
+     * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
+     * 
+     * @see btMotionState
+     */
+    class PhysicsMotionState : public btMotionState
+    {
+        friend class PhysicsConstraint;
+
+    public:
+
+        /**
+         * Creates a physics motion state for a rigid body.
+         * 
+         * @param node The node that owns the rigid body that the motion state is being created for.
+         * @param centerOfMassOffset The translation offset to the center of mass of the rigid body.
+         */
+        PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset = NULL);
+
+        /**
+         * Destructor.
+         */
+        virtual ~PhysicsMotionState();
+
+        /**
+         * @see btMotionState#getWorldTransform
+         */
+        virtual void getWorldTransform(btTransform &transform) const;
+
+        /**
+         * @see btMotionState#setWorldTransform
+         */
+        virtual void setWorldTransform(const btTransform &transform);
+
+        /**
+         * Updates the motion state's world transform from the GamePlay Node object's world transform.
+         */
+        void updateTransformFromNode() const;
+
+    private:
+
+        Node* _node;
+        btTransform _centerOfMassOffset;
+        mutable btTransform _worldTransform;
+    };
+
     /**
     /**
      * Constructor.
      * Constructor.
      */
      */
@@ -223,13 +269,6 @@ protected:
      */
      */
     virtual btCollisionObject* getCollisionObject() const = 0;
     virtual btCollisionObject* getCollisionObject() const = 0;
 
 
-    /**
-     * Returns the physics motion state.
-     *
-     * @return The motion state object.
-     */
-    PhysicsMotionState* getMotionState() const;
-
     /**
     /**
      * Pointer to Node contained by this collision object.
      * Pointer to Node contained by this collision object.
      */ 
      */ 

+ 2 - 2
gameplay/src/PhysicsConstraint.cpp

@@ -166,8 +166,8 @@ Vector3 PhysicsConstraint::getWorldCenterOfMass(const Model* model)
 
 
 Vector3 PhysicsConstraint::offsetByCenterOfMass(const Node* node, const Vector3& v)
 Vector3 PhysicsConstraint::offsetByCenterOfMass(const Node* node, const Vector3& v)
 {
 {
-    GP_ASSERT(node && node->getCollisionObject() && node->getCollisionObject()->getMotionState());
-    btVector3 centerOfMassOffset = (node->getCollisionObject()->getMotionState())->_centerOfMassOffset.getOrigin();
+    GP_ASSERT(node && node->getCollisionObject() && node->getCollisionObject()->_motionState);
+    btVector3 centerOfMassOffset = node->getCollisionObject()->_motionState->_centerOfMassOffset.getOrigin();
     return Vector3(v.x + centerOfMassOffset.x(), v.y + centerOfMassOffset.y(), v.z + centerOfMassOffset.z());
     return Vector3(v.x + centerOfMassOffset.x(), v.y + centerOfMassOffset.y(), v.z + centerOfMassOffset.z());
 }
 }
 
 

+ 0 - 72
gameplay/src/PhysicsMotionState.cpp

@@ -1,72 +0,0 @@
-#include "Base.h"
-#include "PhysicsMotionState.h"
-#include "Node.h"
-
-namespace gameplay
-{
-
-PhysicsMotionState::PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset) : _node(node),
-    _centerOfMassOffset(btTransform::getIdentity())
-{
-    if (centerOfMassOffset)
-    {
-        // Store the center of mass offset.
-        _centerOfMassOffset.setOrigin(BV(*centerOfMassOffset));
-    }
-
-    updateTransformFromNode();
-}
-
-PhysicsMotionState::~PhysicsMotionState()
-{
-}
-
-void PhysicsMotionState::getWorldTransform(btTransform &transform) const
-{
-    GP_ASSERT(_node);
-    if (_node->getCollisionObject() && _node->getCollisionObject()->isKinematic())
-        updateTransformFromNode();
-
-    transform = _centerOfMassOffset.inverse() * _worldTransform;
-}
-
-void PhysicsMotionState::setWorldTransform(const btTransform &transform)
-{
-    GP_ASSERT(_node);
-
-    _worldTransform = transform * _centerOfMassOffset;
-        
-    const btQuaternion& rot = _worldTransform.getRotation();
-    const btVector3& pos = _worldTransform.getOrigin();
-
-    _node->setRotation(rot.x(), rot.y(), rot.z(), rot.w());
-    _node->setTranslation(pos.x(), pos.y(), pos.z());
-}
-
-void PhysicsMotionState::updateTransformFromNode() const
-{
-    GP_ASSERT(_node);
-
-    // Store the initial world transform (minus the scale) for use by Bullet later on.
-    Quaternion rotation;
-    const Matrix& m = _node->getWorldMatrix();
-    m.getRotation(&rotation);
-
-    if (!_centerOfMassOffset.getOrigin().isZero())
-    {
-        // When there is a center of mass offset, we modify the initial world transformation
-        // so that when physics is initially applied, the object is in the correct location.
-        btTransform offset = btTransform(BQ(rotation), btVector3(0.0f, 0.0f, 0.0f)) * _centerOfMassOffset.inverse();
-
-        btVector3 origin(m.m[12] + _centerOfMassOffset.getOrigin().getX() + offset.getOrigin().getX(), 
-                         m.m[13] + _centerOfMassOffset.getOrigin().getY() + offset.getOrigin().getY(), 
-                         m.m[14] + _centerOfMassOffset.getOrigin().getZ() + offset.getOrigin().getZ());
-        _worldTransform = btTransform(BQ(rotation), origin);
-    }
-    else
-    {
-        _worldTransform = btTransform(BQ(rotation), btVector3(m.m[12], m.m[13], m.m[14]));
-    }
-}
-
-}

+ 0 - 61
gameplay/src/PhysicsMotionState.h

@@ -1,61 +0,0 @@
-#ifndef PHYSICSMOTIONSTATE_H_
-#define PHYSICSMOTIONSTATE_H_
-
-#include "Vector3.h"
-
-namespace gameplay
-{
-
-class Node;
-
-/**
- * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
- * 
- * @see btMotionState
- */
-class PhysicsMotionState : public btMotionState
-{
-    friend class PhysicsCollisionObject;
-    friend class PhysicsRigidBody;
-    friend class PhysicsGhostObject;
-    friend class PhysicsCharacter;
-    friend class PhysicsConstraint;
-
-protected:
-
-    /**
-     * Creates a physics motion state for a rigid body.
-     * 
-     * @param node The node that owns the rigid body that the motion state is being created for.
-     * @param centerOfMassOffset The translation offset to the center of mass of the rigid body.
-     */
-    PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset = NULL);
-
-    /**
-     * Destructor.
-     */
-    virtual ~PhysicsMotionState();
-
-    /**
-     * @see btMotionState#getWorldTransform
-     */
-    virtual void getWorldTransform(btTransform &transform) const;
-
-    /**
-     * @see btMotionState#setWorldTransform
-     */
-    virtual void setWorldTransform(const btTransform &transform);
-
-private:
-
-    // Updates the motion state's world transform from the GamePlay Node object's world transform.
-    void updateTransformFromNode() const;
-
-    Node* _node;
-    btTransform _centerOfMassOffset;
-    mutable btTransform _worldTransform;
-};
-
-}
-
-#endif

+ 4 - 1
gameplay/src/SceneLoader.cpp

@@ -131,7 +131,7 @@ void SceneLoader::addSceneNodeProperty(SceneNode& sceneNode, SceneNodeProperty::
 
 
     // If there is a non-GPB file that needs to be loaded later, add an 
     // If there is a non-GPB file that needs to be loaded later, add an 
     // empty entry to the properties table to signify it.
     // empty entry to the properties table to signify it.
-    if (urlStr.length() > 0 && urlStr.find(".gpb") == urlStr.npos && _properties.count(urlStr) == 0)
+    if (urlStr.length() > 0 && urlStr.find(".") != urlStr.npos && urlStr.find(".gpb") == urlStr.npos && _properties.count(urlStr) == 0)
         _properties[urlStr] = NULL;
         _properties[urlStr] = NULL;
 
 
     // Add the node property to the list of node properties to be resolved later.
     // Add the node property to the list of node properties to be resolved later.
@@ -177,6 +177,9 @@ void SceneLoader::applyNodeProperty(SceneNode& sceneNode, Node* node, const Prop
             return;
             return;
         }
         }
 
 
+        // If the URL didn't specify a particular namespace within the file, pick the first one.
+        p = (strlen(p->getNamespace()) > 0) ? p : p->getNextNamespace();
+
         switch (snp._type)
         switch (snp._type)
         {
         {
         case SceneNodeProperty::AUDIO:
         case SceneNodeProperty::AUDIO: