Browse Source

Merge pull request #62 from blackberry-gaming/next-setaylor

Next setaylor
Sean Paul Taylor 14 years ago
parent
commit
4d85438c70

+ 0 - 2
gameplay/gameplay.vcxproj

@@ -52,7 +52,6 @@
     <ClCompile Include="src\ParticleEmitter.cpp" />
     <ClCompile Include="src\PhysicsConstraint.cpp" />
     <ClCompile Include="src\PhysicsController.cpp" />
-    <ClCompile Include="src\PhysicsDebugDrawer.cpp" />
     <ClCompile Include="src\PhysicsFixedConstraint.cpp" />
     <ClCompile Include="src\PhysicsGenericConstraint.cpp" />
     <ClCompile Include="src\PhysicsHingeConstraint.cpp" />
@@ -120,7 +119,6 @@
     <ClInclude Include="src\ParticleEmitter.h" />
     <ClInclude Include="src\PhysicsConstraint.h" />
     <ClInclude Include="src\PhysicsController.h" />
-    <ClInclude Include="src\PhysicsDebugDrawer.h" />
     <ClInclude Include="src\PhysicsFixedConstraint.h" />
     <ClInclude Include="src\PhysicsGenericConstraint.h" />
     <ClInclude Include="src\PhysicsHingeConstraint.h" />

+ 0 - 6
gameplay/gameplay.vcxproj.filters

@@ -204,9 +204,6 @@
     <ClCompile Include="src\PhysicsMotionState.cpp">
       <Filter>src</Filter>
     </ClCompile>
-    <ClCompile Include="src\PhysicsDebugDrawer.cpp">
-      <Filter>src</Filter>
-    </ClCompile>
     <ClCompile Include="src\SceneLoader.cpp">
       <Filter>src</Filter>
     </ClCompile>
@@ -401,9 +398,6 @@
     <ClInclude Include="src\PhysicsSocketConstraint.h">
       <Filter>src</Filter>
     </ClInclude>
-    <ClInclude Include="src\PhysicsDebugDrawer.h">
-      <Filter>src</Filter>
-    </ClInclude>
     <ClInclude Include="src\SceneLoader.h">
       <Filter>src</Filter>
     </ClInclude>

+ 8 - 0
gameplay/gameplay.xcodeproj/project.pbxproj

@@ -9,6 +9,8 @@
 /* Begin PBXBuildFile section */
 		4220A6E8146B122B00CAEB3A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4220A6E7146B122B00CAEB3A /* QuartzCore.framework */; };
 		4234D99E14686C52003031B3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4234D99D14686C52003031B3 /* Cocoa.framework */; };
+		428390991489D6E800E2B2F5 /* SceneLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 428390971489D6E800E2B2F5 /* SceneLoader.cpp */; };
+		4283909A1489D6E800E2B2F5 /* SceneLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 428390981489D6E800E2B2F5 /* SceneLoader.h */; };
 		4299EFA9146AC94300FF4A73 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4299EFA8146AC94300FF4A73 /* OpenGL.framework */; };
 		4299EFAB146AC94B00FF4A73 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4299EFAA146AC94B00FF4A73 /* OpenAL.framework */; };
 		42CCD554146EC1DD00353661 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 42CCD553146EC1DD00353661 /* libz.dylib */; };
@@ -159,6 +161,8 @@
 		4220A6E7146B122B00CAEB3A /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; };
 		4234D99A14686C52003031B3 /* libgameplay.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libgameplay.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		4234D99D14686C52003031B3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+		428390971489D6E800E2B2F5 /* SceneLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SceneLoader.cpp; path = src/SceneLoader.cpp; sourceTree = SOURCE_ROOT; };
+		428390981489D6E800E2B2F5 /* SceneLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SceneLoader.h; path = src/SceneLoader.h; sourceTree = SOURCE_ROOT; };
 		4299EFA8146AC94300FF4A73 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; };
 		4299EFAA146AC94B00FF4A73 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework; sourceTree = DEVELOPER_DIR; };
 		42CCD553146EC1DD00353661 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = SDKs/MacOSX10.7.sdk/usr/lib/libz.dylib; sourceTree = DEVELOPER_DIR; };
@@ -488,6 +492,8 @@
 				42CD0E2C147D8FF50000361E /* RenderTarget.h */,
 				42CD0E2D147D8FF50000361E /* Scene.cpp */,
 				42CD0E2E147D8FF50000361E /* Scene.h */,
+				428390971489D6E800E2B2F5 /* SceneLoader.cpp */,
+				428390981489D6E800E2B2F5 /* SceneLoader.h */,
 				42CD0E2F147D8FF50000361E /* SpriteBatch.cpp */,
 				42CD0E30147D8FF50000361E /* SpriteBatch.h */,
 				42CD0E31147D8FF50000361E /* Technique.cpp */,
@@ -614,6 +620,7 @@
 				42CD0EC8147D8FF60000361E /* VertexAttributeBinding.h in Headers */,
 				42CD0ECA147D8FF60000361E /* VertexFormat.h in Headers */,
 				42CD0ECC147D8FF60000361E /* Viewport.h in Headers */,
+				4283909A1489D6E800E2B2F5 /* SceneLoader.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -736,6 +743,7 @@
 				42CD0EC7147D8FF60000361E /* VertexAttributeBinding.cpp in Sources */,
 				42CD0EC9147D8FF60000361E /* VertexFormat.cpp in Sources */,
 				42CD0ECB147D8FF60000361E /* Viewport.cpp in Sources */,
+				428390991489D6E800E2B2F5 /* SceneLoader.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 1
gameplay/src/AnimationClip.h

@@ -51,7 +51,7 @@ public:
         };
 
         /**
-         * Handles when a transform has changed.
+         * Handles when animation event occurs.
          */
         virtual void animationEvent(AnimationClip* clip, EventType type) = 0;
     };

+ 2 - 1
gameplay/src/ParticleEmitter.h

@@ -172,9 +172,10 @@ public:
      * Creates an uninitialized ParticleEmitter.
      *
      * @param texturePath A path to the image to use as this ParticleEmitter's texture.
+     * @param textureBlending The type of texture blending to be used for the particles emitted.
      * @param particleCountMax The maximum number of particles that can be alive at one time in this ParticleEmitter's system.
      */
-    static ParticleEmitter* create(const char* texturePath, TextureBlending blending,  unsigned int particleCountMax);
+    static ParticleEmitter* create(const char* texturePath, TextureBlending textureBlending,  unsigned int particleCountMax);
 
     /**
      * Sets the emission rate, measured in particles per second.

+ 255 - 71
gameplay/src/PhysicsController.cpp

@@ -2,18 +2,22 @@
 #include "Game.h"
 #include "MeshPart.h"
 #include "PhysicsController.h"
-#include "PhysicsDebugDrawer.h"
 #include "PhysicsMotionState.h"
 #include "SceneLoader.h"
 
+// The initial capacity of the bullet debug draw's vertex batch.
+#define INITIAL_CAPACITY 280
+
 namespace gameplay
 {
 
-// Default gravity is 9.8 along the negative Y axis.
 PhysicsController::PhysicsController()
-    : _gravity(btScalar(0.0), btScalar(-9.8), btScalar(0.0)), _collisionConfiguration(NULL), _dispatcher(NULL),
-    _overlappingPairCache(NULL), _solver(NULL), _world(NULL), _drawer(NULL), _status(Listener::DEACTIVATED), _listeners(NULL)
+  : _collisionConfiguration(NULL), _dispatcher(NULL),
+    _overlappingPairCache(NULL), _solver(NULL), _world(NULL), _debugDrawer(NULL), 
+    _status(PhysicsController::Listener::DEACTIVATED), _listeners(NULL),
+    _gravity(btScalar(0.0), btScalar(-9.8), btScalar(0.0))
 {
+    // Default gravity is 9.8 along the negative Y axis.
 }
 
 void PhysicsController::addStatusListener(Listener* listener)
@@ -23,24 +27,24 @@ void PhysicsController::addStatusListener(Listener* listener)
 
     _listeners->push_back(listener);
 }
-
+    
 PhysicsController::~PhysicsController()
 {
-    SAFE_DELETE(_drawer);
+    SAFE_DELETE(_debugDrawer);
     SAFE_DELETE(_listeners);
 }
 
 PhysicsFixedConstraint* PhysicsController::createFixedConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
 {
     PhysicsFixedConstraint* constraint = new PhysicsFixedConstraint(a, b);
-    setupConstraint(a, b, constraint);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
 PhysicsGenericConstraint* PhysicsController::createGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
 {
     PhysicsGenericConstraint* constraint = new PhysicsGenericConstraint(a, b);
-    setupConstraint(a, b, constraint);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
@@ -48,9 +52,9 @@ PhysicsGenericConstraint* PhysicsController::createGenericConstraint(PhysicsRigi
     const Quaternion& rotationOffsetA, const Vector3& translationOffsetA, PhysicsRigidBody* b,
     const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
 {
-    PhysicsGenericConstraint* constraint = new PhysicsGenericConstraint(a, rotationOffsetA, 
-        translationOffsetA, b, rotationOffsetB, translationOffsetB);
-    setupConstraint(a, b, constraint);
+    PhysicsGenericConstraint* constraint = new PhysicsGenericConstraint(a, rotationOffsetA, translationOffsetA, 
+                                                                        b, rotationOffsetB, translationOffsetB);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
@@ -58,50 +62,49 @@ PhysicsHingeConstraint* PhysicsController::createHingeConstraint(PhysicsRigidBod
     const Quaternion& rotationOffsetA, const Vector3& translationOffsetA, PhysicsRigidBody* b, 
     const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
 {
-    PhysicsHingeConstraint* constraint = new PhysicsHingeConstraint(a, rotationOffsetA, 
-        translationOffsetA, b, rotationOffsetB, translationOffsetB);
-    setupConstraint(a, b, constraint);
+    PhysicsHingeConstraint* constraint = new PhysicsHingeConstraint(a, rotationOffsetA, translationOffsetA, 
+                                                                    b, rotationOffsetB, translationOffsetB);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
 PhysicsSocketConstraint* PhysicsController::createSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
 {
     PhysicsSocketConstraint* constraint = new PhysicsSocketConstraint(a, b);
-    setupConstraint(a, b, constraint);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
 PhysicsSocketConstraint* PhysicsController::createSocketConstraint(PhysicsRigidBody* a,
     const Vector3& translationOffsetA, PhysicsRigidBody* b, const Vector3& translationOffsetB)
 {
-    PhysicsSocketConstraint* constraint = new PhysicsSocketConstraint(a,
-        translationOffsetA, b, translationOffsetB);
-    setupConstraint(a, b, constraint);
+    PhysicsSocketConstraint* constraint = new PhysicsSocketConstraint(a,translationOffsetA, 
+                                                                      b, translationOffsetB);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
 PhysicsSpringConstraint* PhysicsController::createSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
 {
     PhysicsSpringConstraint* constraint = new PhysicsSpringConstraint(a, b);
-    setupConstraint(a, b, constraint);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
-PhysicsSpringConstraint* PhysicsController::createSpringConstraint(PhysicsRigidBody* a,
-    const Quaternion& rotationOffsetA, const Vector3& translationOffsetA, PhysicsRigidBody* b, 
-    const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+PhysicsSpringConstraint* PhysicsController::createSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,           
+                                                                   PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
 {
-    PhysicsSpringConstraint* constraint = new PhysicsSpringConstraint(a, rotationOffsetA, 
-        translationOffsetA, b, rotationOffsetB, translationOffsetB);
-    setupConstraint(a, b, constraint);
+    PhysicsSpringConstraint* constraint = new PhysicsSpringConstraint(a, rotationOffsetA, translationOffsetA, 
+                                                                      b, rotationOffsetB, translationOffsetB);
+    addConstraint(a, b, constraint);
     return constraint;
 }
 
 void PhysicsController::drawDebug(const Matrix& viewProjection)
 {
-    _drawer->begin(viewProjection);
+    _debugDrawer->begin(viewProjection);
     _world->debugDrawWorld();
-    _drawer->end();
+    _debugDrawer->end();
 }
 
 const Vector3& PhysicsController::getGravity(const Vector3& gravity) const
@@ -114,9 +117,7 @@ void PhysicsController::setGravity(const Vector3& gravity)
     _gravity = gravity;
 
     if (_world)
-    {
         _world->setGravity(btVector3(_gravity.x, _gravity.y, _gravity.z));
-    }
 }
 
 void PhysicsController::initialize()
@@ -131,8 +132,8 @@ void PhysicsController::initialize()
     _world->setGravity(btVector3(_gravity.x, _gravity.y, _gravity.z));
 
     // Set up debug drawing.
-    _drawer = new PhysicsDebugDrawer();
-    _world->setDebugDrawer(_drawer);
+    _debugDrawer = new DebugDrawer();
+    _world->setDebugDrawer(_debugDrawer);
 }
 
 void PhysicsController::finalize()
@@ -204,6 +205,7 @@ void PhysicsController::update(long elapsedTime)
                 (*_listeners)[k]->statusEvent(_status);
             }
         }
+        
     }
 
     // All statuses are set with the DIRTY bit before collision processing occurs.
@@ -271,14 +273,41 @@ void PhysicsController::update(long elapsedTime)
         }
     }
 }
+    
 
 void PhysicsController::addRigidBody(PhysicsRigidBody* body)
 {
     _world->addRigidBody(body->_body);
     _bodies.push_back(body);
 }
+    
+void PhysicsController::removeRigidBody(PhysicsRigidBody* rigidBody)
+{
+    // Find the rigid body and remove it from the world.
+    for (int i = _world->getNumCollisionObjects() - 1; i >= 0 ; i--)
+    {
+        btCollisionObject* obj = _world->getCollisionObjectArray()[i];
+        if (rigidBody->_body == obj)
+        {
+            _world->removeCollisionObject(obj);
+            break;
+        }
+    }
+}
+
+PhysicsRigidBody* PhysicsController::getRigidBody(const btCollisionObject* collisionObject)
+{
+    // Find the rigid body and remove it from the world.
+    for (unsigned int i = 0; i < _bodies.size(); i++)
+    {
+        if (_bodies[i]->_body == collisionObject)
+            return _bodies[i];
+    }
+    
+    return NULL;
+}
 
-btCollisionShape* PhysicsController::getBox(const Vector3& min, const Vector3& max, const btVector3& scale)
+btCollisionShape* PhysicsController::createBox(const Vector3& min, const Vector3& max, const btVector3& scale)
 {
     btVector3 halfExtents(scale.x() * 0.5 * abs(max.x - min.x), scale.y() * 0.5 * abs(max.y - min.y), scale.z() * 0.5 * abs(max.z - min.z));
     BULLET_NEW_VARG(btBoxShape, box, halfExtents);
@@ -287,7 +316,23 @@ btCollisionShape* PhysicsController::getBox(const Vector3& min, const Vector3& m
     return box;
 }
 
-btCollisionShape* PhysicsController::getMesh(PhysicsRigidBody* body)
+btCollisionShape* PhysicsController::createSphere(float radius, const btVector3& scale)
+{
+    // Since sphere shapes depend only on the radius, the best we can do is take
+    // the largest dimension and apply that as the uniform scale to the rigid body.
+    float uniformScale = scale.x();
+    if (uniformScale < scale.y())
+        uniformScale = scale.y();
+    if (uniformScale < scale.z())
+        uniformScale = scale.z();
+    
+    BULLET_NEW_VARG(btSphereShape, sphere, uniformScale * radius);
+    _shapes.push_back(sphere);
+    
+    return sphere;
+}
+
+btCollisionShape* PhysicsController::createMesh(PhysicsRigidBody* body)
 {
     // Retrieve the mesh rigid body data from the loaded scene.
     const SceneLoader::MeshRigidBodyData* data = SceneLoader::getMeshRigidBodyData(body->_node->getId());
@@ -302,8 +347,8 @@ btCollisionShape* PhysicsController::getMesh(PhysicsRigidBody* body)
     for (unsigned int i = 0; i < vertexCount; i++)
     {
         v.set(*((float*)&data->vertexData[i * vertexStride + 0 * sizeof(float)]),
-            *((float*)&data->vertexData[i * vertexStride + 1 * sizeof(float)]),
-            *((float*)&data->vertexData[i * vertexStride + 2 * sizeof(float)]));
+              *((float*)&data->vertexData[i * vertexStride + 1 * sizeof(float)]),
+              *((float*)&data->vertexData[i * vertexStride + 2 * sizeof(float)]));
         v *= m;
         memcpy(&(body->_vertexData[i * 3]), &v, sizeof(float) * 3);
     }
@@ -387,34 +432,17 @@ btCollisionShape* PhysicsController::getMesh(PhysicsRigidBody* body)
     return shape;
 }
 
-PhysicsRigidBody* PhysicsController::getPhysicsRigidBody(const btCollisionObject* collisionObject)
+void PhysicsController::addConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
 {
-    // Find the rigid body and remove it from the world.
-    for (unsigned int i = 0; i < _bodies.size(); i++)
+    a->addConstraint(constraint);
+    if (b)
     {
-        if (_bodies[i]->_body == collisionObject)
-            return _bodies[i];
+        b->addConstraint(constraint);
     }
-
-    return NULL;
-}
-
-btCollisionShape* PhysicsController::getSphere(float radius, const btVector3& scale)
-{
-    // Since sphere shapes depend only on the radius, the best we can do is take
-    // the largest dimension and apply that as the uniform scale to the rigid body.
-    float uniformScale = scale.x();
-    if (uniformScale < scale.y())
-        uniformScale = scale.y();
-    if (uniformScale < scale.z())
-        uniformScale = scale.z();
-
-    BULLET_NEW_VARG(btSphereShape, sphere, uniformScale * radius);
-    _shapes.push_back(sphere);
-
-    return sphere;
+    
+    _world->addConstraint(constraint->_constraint);
 }
-
+    
 void PhysicsController::removeConstraint(PhysicsConstraint* constraint)
 {
     // Find the constraint and remove it from the physics world.
@@ -428,30 +456,186 @@ void PhysicsController::removeConstraint(PhysicsConstraint* constraint)
         }
     }
 }
+    
+PhysicsController::DebugDrawer::DebugDrawer()
+    : _mode(btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawConstraintLimits | btIDebugDraw::DBG_DrawConstraints | 
+       btIDebugDraw::DBG_DrawContactPoints | btIDebugDraw::DBG_DrawWireframe), _program(0), _positionAttrib(0),
+       _colorAttrib(0), _viewProjectionMatrixUniform(0), _viewProjection(NULL), _vertexData(NULL), _vertexCount(0), _vertexDataSize(0)
+{
+    // Unused
+}
 
-void PhysicsController::removeRigidBody(PhysicsRigidBody* rigidBody)
+PhysicsController::DebugDrawer::~DebugDrawer()
 {
-    // Find the rigid body and remove it from the world.
-    for (int i = _world->getNumCollisionObjects() - 1; i >= 0 ; i--)
+    SAFE_DELETE_ARRAY(_vertexData);
+}
+
+void PhysicsController::DebugDrawer::begin(const Matrix& viewProjection)
+{
+    _viewProjection = &viewProjection;
+    _vertexCount = 0;
+}
+
+void PhysicsController::DebugDrawer::end()
+{
+    // Lazy load the shader program for drawing.
+    if (!_program)
     {
-        btCollisionObject* obj = _world->getCollisionObjectArray()[i];
-        if (rigidBody->_body == obj)
+        // Vertex shader for drawing colored lines.
+        const char* vs_str = 
         {
-            _world->removeCollisionObject(obj);
-            break;
+            "uniform mat4 u_viewProjectionMatrix;\n"
+            "attribute vec4 a_position;\n"
+            "attribute vec4 a_color;\n"
+            "varying vec4 v_color;\n"
+            "void main(void) {\n"
+            "    v_color = a_color;\n"
+            "    gl_Position = u_viewProjectionMatrix * a_position;\n"
+            "}"
+        };
+        
+        // Fragment shader for drawing colored lines.
+        const char* fs_str = 
+        {
+        #ifdef OPENGL_ES
+            "precision highp float;\n"
+        #endif
+            "varying vec4 v_color;\n"
+            "void main(void) {\n"
+            "   gl_FragColor = v_color;\n"
+            "}"
+        };
+        
+        // Load the vertex shader.
+        GLuint vs;
+        GL_ASSERT( vs = glCreateShader(GL_VERTEX_SHADER) );
+        GLint shader_str_len = strlen(vs_str);
+        GL_ASSERT( glShaderSource(vs, 1, &vs_str, &shader_str_len) );
+        GL_ASSERT( glCompileShader(vs) );
+        GLint status;
+        GL_ASSERT( glGetShaderiv(vs, GL_COMPILE_STATUS, &status) );
+        if (status == GL_FALSE)
+        {
+            GLchar errorMessage[512];
+            GL_ASSERT( glGetShaderInfoLog(vs, sizeof(errorMessage), 0, errorMessage) );
+            WARN_VARG("Physics debug drawing will not work; vertex shader failed to compile with error: '%s'", errorMessage);
+            return;
+        }
+        
+        // Load the fragment shader.
+        GLuint fs;
+        GL_ASSERT( fs = glCreateShader(GL_FRAGMENT_SHADER) );
+        shader_str_len = strlen(fs_str);
+        GL_ASSERT( glShaderSource(fs, 1, &fs_str, &shader_str_len) );
+        GL_ASSERT( glCompileShader(fs) );
+        GL_ASSERT( glGetShaderiv(fs, GL_COMPILE_STATUS, &status) );
+        if (status == GL_FALSE)
+        {
+            GLchar errorMessage[512];
+            GL_ASSERT( glGetShaderInfoLog(fs, sizeof(errorMessage), 0, errorMessage) );
+            WARN_VARG("Physics debug drawing will not work; fragment shader failed to compile with error: '%s'", errorMessage);
+            return;
         }
+        
+        // Create the shader program and link it.
+        GL_ASSERT( _program = glCreateProgram() );
+        GL_ASSERT( glAttachShader(_program, vs) );
+        GL_ASSERT( glAttachShader(_program, fs) );
+        GL_ASSERT( glLinkProgram(_program) );
+        GL_ASSERT( glGetProgramiv(_program, GL_LINK_STATUS, &status) );
+        if (status == GL_FALSE)
+        {
+            GLchar errorMessage[512];
+            GL_ASSERT( glGetProgramInfoLog(_program, sizeof(errorMessage), 0, errorMessage) );
+            WARN_VARG("Physics debug drawing will not work; shader program failed to link with error: '%s'", errorMessage);
+            return;
+        }
+        
+        // Get the attribute and uniform locations.
+        GL_ASSERT( glUseProgram(_program) );
+        GL_ASSERT( _positionAttrib = glGetAttribLocation(_program, "a_position") );
+        GL_ASSERT( _colorAttrib = glGetAttribLocation(_program, "a_color") );
+        GL_ASSERT( _viewProjectionMatrixUniform = glGetUniformLocation(_program, "u_viewProjectionMatrix") );
     }
+    
+    // Set the shader program and vertex attributes.
+    GL_ASSERT( glUseProgram(_program) );
+    GL_ASSERT( glEnableVertexAttribArray(_positionAttrib) );
+    GL_ASSERT( glEnableVertexAttribArray(_colorAttrib) );
+    GL_ASSERT( glVertexAttribPointer(_positionAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 7, _vertexData) );
+    GL_ASSERT( glVertexAttribPointer(_colorAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 7, &_vertexData[3]) );
+    
+    // Set the camera's view projection matrix and draw.
+    GL_ASSERT( glUniformMatrix4fv(_viewProjectionMatrixUniform, 1, GL_FALSE, _viewProjection->m) );
+    GL_ASSERT( glDrawArrays(GL_LINES, 0, _vertexCount / 7) );
+    
+    // Reset shader state.
+    GL_ASSERT( glDisableVertexAttribArray(_positionAttrib) );
+    GL_ASSERT( glDisableVertexAttribArray(_colorAttrib) );
+    GL_ASSERT( glUseProgram(0) );
 }
 
-void PhysicsController::setupConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
+void PhysicsController::DebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
 {
-    a->addConstraint(constraint);
-    if (b)
+    // Allocate extra space in the vertex data batch if it is needed.
+    if (_vertexDataSize - _vertexCount < 14)
     {
-        b->addConstraint(constraint);
+        if (_vertexDataSize > 0)
+        {
+            unsigned int newVertexDataSize = _vertexDataSize * 2;
+            float* newVertexData = new float[newVertexDataSize];
+            memcpy(newVertexData, _vertexData, _vertexDataSize * sizeof(float));
+            SAFE_DELETE_ARRAY(_vertexData);
+            _vertexData = newVertexData;
+            _vertexDataSize = newVertexDataSize;
+        }
+        else
+        {
+            _vertexDataSize = INITIAL_CAPACITY;
+            _vertexData = new float[_vertexDataSize];
+        }
     }
+    
+    // Create the vertex data for the line and copy it into the batch.
+    float vertexData[] = 
+    {
+        from.getX(), from.getY(), from.getZ(), 
+        fromColor.getX(), fromColor.getY(), fromColor.getZ(), 1.0f,
+        to.getX(), to.getY(), to.getZ(),
+        toColor.getX(), toColor.getY(), toColor.getZ(), 1.0f
+    };
+    memcpy(&_vertexData[_vertexCount], vertexData, sizeof(float) * 14);
+    _vertexCount += 14;
+}
 
-    _world->addConstraint(constraint->_constraint);
+void PhysicsController::DebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
+{
+    drawLine(from, to, color, color);
+}
+
+void PhysicsController::DebugDrawer::drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color)
+{
+    drawLine(pointOnB, pointOnB + normalOnB, color);
+}
+
+void PhysicsController::DebugDrawer::reportErrorWarning(const char* warningString)
+{
+    WARN(warningString);
+}
+
+void PhysicsController::DebugDrawer::draw3dText(const btVector3& location, const char* textString)
+{
+    WARN("Physics debug drawing: 3D text is not supported.");
+}
+
+void PhysicsController::DebugDrawer::setDebugMode(int mode)
+{
+    _mode = mode;
+}
+
+int	PhysicsController::DebugDrawer::getDebugMode() const
+{
+    return _mode;
 }
 
 }

+ 73 - 39
gameplay/src/PhysicsController.h

@@ -2,7 +2,6 @@
 #define PHYSICSCONTROLLER_H_
 
 #include "PhysicsConstraint.h"
-#include "PhysicsDebugDrawer.h"
 #include "PhysicsFixedConstraint.h"
 #include "PhysicsGenericConstraint.h"
 #include "PhysicsHingeConstraint.h"
@@ -48,17 +47,17 @@ public:
         };
 
         /**
-         * Handles when the physics world status changes.
+         * Handles when the physics world status event occurs.
          */
         virtual void statusEvent(EventType type) = 0;
     };
 
     /**
-     * Adds a status listener.
+     * Adds a listener to the physics controller.
      * 
      * @param listener The listener to add.
      */
-    void addStatusListener(Listener* listener);
+    void addStatusListener(PhysicsController::Listener* listener);
 
     /**
      * Creates a fixed constraint.
@@ -94,10 +93,8 @@ public:
      * @param translationOffsetB The translation offset for the second rigid body
      *      (in its local space) with respect to the constraint joint (optional).
      */
-    PhysicsGenericConstraint* createGenericConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, 
-                                                     const Vector3& translationOffsetA, PhysicsRigidBody* b = NULL, 
-                                                     const Quaternion& rotationOffsetB = Quaternion(), 
-                                                     const Vector3& translationOffsetB = Vector3());
+    PhysicsGenericConstraint* createGenericConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA, 
+                                                      PhysicsRigidBody* b = NULL, const Quaternion& rotationOffsetB = Quaternion(), const Vector3& translationOffsetB = Vector3());
 
     /**
      * Creates a hinge constraint.
@@ -114,10 +111,8 @@ public:
      * @param translationOffsetB The translation offset for the second rigid body
      *      (in its local space) with respect to the constraint joint (optional).
      */
-    PhysicsHingeConstraint* createHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, 
-                                                  const Vector3& translationOffsetA, PhysicsRigidBody* b = NULL, 
-                                                  const Quaternion& rotationOffsetB = Quaternion(), 
-                                                  const Vector3& translationOffsetB = Vector3());
+    PhysicsHingeConstraint* createHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+                                                  PhysicsRigidBody* b = NULL, const Quaternion& rotationOffsetB = Quaternion(), const Vector3& translationOffsetB = Vector3());
 
     /**
      * Creates a socket constraint so that the rigid body (or bodies) is
@@ -170,16 +165,8 @@ public:
      * @param translationOffsetB The translation offset for the second rigid body
      *      (in its local space) with respect to the constraint joint (optional).
      */
-    PhysicsSpringConstraint* createSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, 
-                                                    const Vector3& translationOffsetA, PhysicsRigidBody* b, 
-                                                    const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
-
-    /**
-     * Draws debugging information (rigid body outlines, etc.) using the given view projection matrix.
-     * 
-     * @param viewProjection The view projection matrix to use when drawing.
-     */
-    void drawDebug(const Matrix& viewProjection);
+    PhysicsSpringConstraint* createSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,          
+                                                    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
 
     /**
      * Gets the gravity vector for the simulated physics world.
@@ -194,6 +181,13 @@ public:
      * @param gravity The gravity vector.
      */
     void setGravity(const Vector3& gravity);
+    
+    /**
+     * Draws debugging information (rigid body outlines, etc.) using the given view projection matrix.
+     * 
+     * @param viewProjection The view projection matrix to use when drawing.
+     */
+    void drawDebug(const Matrix& viewProjection);
 
 private:
 
@@ -234,39 +228,79 @@ private:
 
     // Adds the given rigid body to the world.
     void addRigidBody(PhysicsRigidBody* body);
-
-    // Creates a box collision shape to be used in the creation of a rigid body.
-    btCollisionShape* getBox(const Vector3& min, const Vector3& max, const btVector3& scale);
-
-    // Creates a triangle mesh collision shape to be used in the creation of a rigid body.
-    btCollisionShape* getMesh(PhysicsRigidBody* body);
-
+    
+    // Removes the given rigid body from the simulated physics world.
+    void removeRigidBody(PhysicsRigidBody* rigidBody);
+    
     // Gets the corresponding GamePlay object for the given Bullet object.
-    PhysicsRigidBody* getPhysicsRigidBody(const btCollisionObject* collisionObject);
+    PhysicsRigidBody* getRigidBody(const btCollisionObject* collisionObject);
+    
+    // Creates a box collision shape to be used in the creation of a rigid body.
+    btCollisionShape* createBox(const Vector3& min, const Vector3& max, const btVector3& scale);
 
     // Creates a sphere collision shape to be used in the creation of a rigid body.
-    btCollisionShape* getSphere(float radius, const btVector3& scale);
+    btCollisionShape* createSphere(float radius, const btVector3& scale);
+
+    // Creates a triangle mesh collision shape to be used in the creation of a rigid body.
+    btCollisionShape* createMesh(PhysicsRigidBody* body);
 
+    // Sets up the given constraint for the given two rigid bodies.
+    void addConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint);
+    
     // Removes the given constraint from the simulated physics world.
     void removeConstraint(PhysicsConstraint* constraint);
+    
+    // Draws bullet debug information
+    class DebugDrawer : public btIDebugDraw
+    {
+    public:
 
-    // Removes the given rigid body from the simulated physics world.
-    void removeRigidBody(PhysicsRigidBody* rigidBody);
-
-    // Sets up the given constraint for the given two rigid bodies.
-    void setupConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint);
+        DebugDrawer();
+        
+        ~DebugDrawer();
+        
+        void begin(const Matrix& viewProjection);
+        
+        void end();
+
+        void drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor);
+        
+        void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
+        
+        void drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);
+        
+        void reportErrorWarning(const char* warningString);
+        
+        void draw3dText(const btVector3& location, const char* textString);
+        
+        void setDebugMode(int mode);
+        
+        int	getDebugMode() const;
+        
+    private:
+        
+        int _mode;
+        GLuint _program;
+        GLuint _positionAttrib;
+        GLuint _colorAttrib;
+        GLuint _viewProjectionMatrixUniform;
+        const Matrix* _viewProjection;
+        float* _vertexData;
+        unsigned int _vertexCount;
+        unsigned int _vertexDataSize;
+    };
     
-    Vector3 _gravity;
     btDefaultCollisionConfiguration* _collisionConfiguration;
     btCollisionDispatcher* _dispatcher;
     btBroadphaseInterface* _overlappingPairCache;
     btSequentialImpulseConstraintSolver* _solver;
     btDynamicsWorld* _world;
     btAlignedObjectArray<btCollisionShape*> _shapes;
-    PhysicsDebugDrawer* _drawer;
+    DebugDrawer* _debugDrawer;
     Listener::EventType _status;
-    std::vector<PhysicsRigidBody*> _bodies;
     std::vector<Listener*>* _listeners;
+    std::vector<PhysicsRigidBody*> _bodies;
+    Vector3 _gravity;
 };
 
 }

+ 0 - 187
gameplay/src/PhysicsDebugDrawer.cpp

@@ -1,187 +0,0 @@
-#include "PhysicsDebugDrawer.h"
-
-namespace gameplay
-{
-
-// The initial capacity of the debug drawer's vertex batch.
-#define INITIAL_CAPACITY 280
-
-PhysicsDebugDrawer::PhysicsDebugDrawer()
-    : _mode(btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawConstraintLimits | btIDebugDraw::DBG_DrawConstraints | 
-    btIDebugDraw::DBG_DrawContactPoints | btIDebugDraw::DBG_DrawWireframe), _program(0), _positionAttrib(0),
-    _colorAttrib(0), _viewProjectionMatrixUniform(0), _viewProjection(NULL), _vertexData(NULL), _vertexCount(0), _vertexDataSize(0)
-{
-    // Unused
-}
-
-PhysicsDebugDrawer::~PhysicsDebugDrawer()
-{
-    SAFE_DELETE_ARRAY(_vertexData);
-}
-
-void PhysicsDebugDrawer::begin(const Matrix& viewProjection)
-{
-    _viewProjection = &viewProjection;
-    _vertexCount = 0;
-}
-
-void PhysicsDebugDrawer::end()
-{
-    // Lazy load the shader program for drawing.
-    if (!_program)
-    {
-        // Vertex shader for drawing colored lines.
-        const char* vs_str = {
-            "uniform mat4 u_viewProjectionMatrix;\n"
-            "attribute vec4 a_position;\n"
-            "attribute vec4 a_color;\n"
-            "varying vec4 v_color;\n"
-            "void main(void) {\n"
-            "    v_color = a_color;\n"
-            "    gl_Position = u_viewProjectionMatrix * a_position;\n"
-            "}"
-        };
-
-        // Fragment shader for drawing colored lines.
-        const char* fs_str = {
-#ifdef OPENGL_ES
-            "precision highp float;\n"
-#endif
-            "varying vec4 v_color;\n"
-            "void main(void) {\n"
-            "   gl_FragColor = v_color;"
-            "}"
-        };
-
-        // Load the vertex shader.
-        GLuint vs;
-        GL_ASSERT( vs = glCreateShader(GL_VERTEX_SHADER) );
-        GLint shader_str_len = strlen(vs_str);
-        GL_ASSERT( glShaderSource(vs, 1, &vs_str, &shader_str_len) );
-        GL_ASSERT( glCompileShader(vs) );
-        GLint status;
-        GL_ASSERT( glGetShaderiv(vs, GL_COMPILE_STATUS, &status) );
-        if (status == GL_FALSE)
-        {
-            GLchar errorMessage[512];
-            GL_ASSERT( glGetShaderInfoLog(vs, sizeof(errorMessage), 0, errorMessage) );
-            WARN_VARG("Physics debug drawing will not work; vertex shader failed to compile with error: '%s'", errorMessage);
-            return;
-        }
-
-        // Load the fragment shader.
-        GLuint fs;
-        GL_ASSERT( fs = glCreateShader(GL_FRAGMENT_SHADER) );
-        shader_str_len = strlen(fs_str);
-        GL_ASSERT( glShaderSource(fs, 1, &fs_str, &shader_str_len) );
-        GL_ASSERT( glCompileShader(fs) );
-        GL_ASSERT( glGetShaderiv(fs, GL_COMPILE_STATUS, &status) );
-        if (status == GL_FALSE)
-        {
-            GLchar errorMessage[512];
-            GL_ASSERT( glGetShaderInfoLog(fs, sizeof(errorMessage), 0, errorMessage) );
-            WARN_VARG("Physics debug drawing will not work; fragment shader failed to compile with error: '%s'", errorMessage);
-            return;
-        }
-
-        // Create the shader program and link it.
-        GL_ASSERT( _program = glCreateProgram() );
-        GL_ASSERT( glAttachShader(_program, vs) );
-        GL_ASSERT( glAttachShader(_program, fs) );
-        GL_ASSERT( glLinkProgram(_program) );
-        GL_ASSERT( glGetProgramiv(_program, GL_LINK_STATUS, &status) );
-        if (status == GL_FALSE)
-        {
-            GLchar errorMessage[512];
-            GL_ASSERT( glGetProgramInfoLog(_program, sizeof(errorMessage), 0, errorMessage) );
-            WARN_VARG("Physics debug drawing will not work; shader program failed to link with error: '%s'", errorMessage);
-            return;
-        }
-
-        // Get the attribute and uniform locations.
-        GL_ASSERT( glUseProgram(_program) );
-        GL_ASSERT( _positionAttrib = glGetAttribLocation(_program, "a_position") );
-        GL_ASSERT( _colorAttrib = glGetAttribLocation(_program, "a_color") );
-        GL_ASSERT( _viewProjectionMatrixUniform = glGetUniformLocation(_program, "u_viewProjectionMatrix") );
-    }
-
-    // Set the shader program and vertex attributes.
-    GL_ASSERT( glUseProgram(_program) );
-    GL_ASSERT( glEnableVertexAttribArray(_positionAttrib) );
-    GL_ASSERT( glEnableVertexAttribArray(_colorAttrib) );
-    GL_ASSERT( glVertexAttribPointer(_positionAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 7, _vertexData) );
-    GL_ASSERT( glVertexAttribPointer(_colorAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 7, &_vertexData[3]) );
-    
-    // Set the camera's view projection matrix and draw.
-    GL_ASSERT( glUniformMatrix4fv(_viewProjectionMatrixUniform, 1, GL_FALSE, _viewProjection->m) );
-    GL_ASSERT( glDrawArrays(GL_LINES, 0, _vertexCount / 7) );
-
-    // Reset shader state.
-    GL_ASSERT( glDisableVertexAttribArray(_positionAttrib) );
-    GL_ASSERT( glDisableVertexAttribArray(_colorAttrib) );
-    GL_ASSERT( glUseProgram(0) );
-}
-
-void PhysicsDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
-{
-    // Allocate extra space in the vertex data batch if it is needed.
-    if (_vertexDataSize - _vertexCount < 14)
-    {
-        if (_vertexDataSize > 0)
-        {
-            unsigned int newVertexDataSize = _vertexDataSize * 2;
-            float* newVertexData = new float[newVertexDataSize];
-            memcpy(newVertexData, _vertexData, _vertexDataSize * sizeof(float));
-            SAFE_DELETE_ARRAY(_vertexData);
-            _vertexData = newVertexData;
-            _vertexDataSize = newVertexDataSize;
-        }
-        else
-        {
-            _vertexDataSize = INITIAL_CAPACITY;
-            _vertexData = new float[_vertexDataSize];
-        }
-    }
-    
-    // Create the vertex data for the line and copy it into the batch.
-    float vertexData[] = {
-        from.getX(), from.getY(), from.getZ(), 
-        fromColor.getX(), fromColor.getY(), fromColor.getZ(), 1.0f,
-        to.getX(), to.getY(), to.getZ(),
-        toColor.getX(), toColor.getY(), toColor.getZ(), 1.0f
-    };
-    memcpy(&_vertexData[_vertexCount], vertexData, sizeof(float) * 14);
-    _vertexCount += 14;
-}
-
-void PhysicsDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
-{
-    drawLine(from, to, color, color);
-}
-
-void PhysicsDebugDrawer::drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color)
-{
-    drawLine(pointOnB, pointOnB + normalOnB, color);
-}
-
-void PhysicsDebugDrawer::reportErrorWarning(const char* warningString)
-{
-    WARN(warningString);
-}
-
-void PhysicsDebugDrawer::draw3dText(const btVector3& location, const char* textString)
-{
-    WARN("Physics debug drawing: 3D text is not supported.");
-}
-
-void PhysicsDebugDrawer::setDebugMode(int mode)
-{
-    _mode = mode;
-}
-
-int	PhysicsDebugDrawer::getDebugMode() const
-{
-    return _mode;
-}
-
-}

+ 0 - 61
gameplay/src/PhysicsDebugDrawer.h

@@ -1,61 +0,0 @@
-#ifndef PHYSICSDEBUGDRAWER_H_
-#define PHYSICSDEBUGDRAWER_H_
-
-#include "Base.h"
-#include "Camera.h"
-
-namespace gameplay
-{
-
-/**
- * Enables debug drawing for the physics system.
- */
-class PhysicsDebugDrawer : public btIDebugDraw
-{
-public:
-    /**
-     * Constructor.
-     */
-	PhysicsDebugDrawer();
-
-    /**
-     * Destructor.
-     */
-    ~PhysicsDebugDrawer();
-
-    /**
-     * Begins drawing a frame.
-     * 
-     * @param viewProjection The view projection matrix to use when drawing.
-     */
-    void begin(const Matrix& viewProjection);
-
-    /**
-     * Finishes drawing a frame.
-     */
-    void end();
-
-    // Overriden functions from btIDebugDraw.
-    void drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor);
-	void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
-	void drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);
-    void reportErrorWarning(const char* warningString);
-    void draw3dText(const btVector3& location, const char* textString);
-    void setDebugMode(int mode);
-    int	getDebugMode() const;
-
-private:
-    int _mode;
-    GLuint _program;
-    GLuint _positionAttrib;
-    GLuint _colorAttrib;
-    GLuint _viewProjectionMatrixUniform;
-    const Matrix* _viewProjection;
-    float* _vertexData;
-    unsigned int _vertexCount;
-    unsigned int _vertexDataSize;
-};
-
-}
-
-#endif

+ 20 - 17
gameplay/src/PhysicsRigidBody.cpp

@@ -7,12 +7,12 @@
 namespace gameplay
 {
 
-const int PhysicsRigidBody::Listener::DIRTY = 0x01;
-const int PhysicsRigidBody::Listener::COLLISION = 0x02;
-const int PhysicsRigidBody::Listener::REGISTERED = 0x04;
+const int PhysicsRigidBody::Listener::DIRTY         = 0x01;
+const int PhysicsRigidBody::Listener::COLLISION     = 0x02;
+const int PhysicsRigidBody::Listener::REGISTERED    = 0x04;
 
 // Internal value used for creating mesh rigid bodies.
-#define SHAPE_MESH ((gameplay::PhysicsRigidBody::Type)(PhysicsRigidBody::SHAPE_NONE + 1))
+#define SHAPE_MESH ((PhysicsRigidBody::Type)(PhysicsRigidBody::SHAPE_NONE + 1))
 
 PhysicsRigidBody::PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, float mass, 
         float friction, float restitution, float linearDamping, float angularDamping)
@@ -25,18 +25,18 @@ PhysicsRigidBody::PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, floa
         case SHAPE_BOX:
         {
             const BoundingBox& box = node->getModel()->getMesh()->getBoundingBox();
-            _shape = Game::getInstance()->getPhysicsController()->getBox(box.min, box.max, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+            _shape = Game::getInstance()->getPhysicsController()->createBox(box.min, box.max, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
             break;
         }
         case SHAPE_SPHERE:
         {
             const BoundingSphere& sphere = node->getModel()->getMesh()->getBoundingSphere();
-            _shape = Game::getInstance()->getPhysicsController()->getSphere(sphere.radius, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+            _shape = Game::getInstance()->getPhysicsController()->createSphere(sphere.radius, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
             break;
         }
         case SHAPE_MESH:
         {
-            _shape = Game::getInstance()->getPhysicsController()->getMesh(this);
+            _shape = Game::getInstance()->getPhysicsController()->createMesh(this);
             break;
         }
     }
@@ -47,9 +47,9 @@ PhysicsRigidBody::PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, floa
 
     // Create the Bullet rigid body.
     if (c.lengthSquared() > MATH_EPSILON)
-        _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping, &c);
+        _body = createRigidBodyInternal(_shape, mass, node, friction, restitution, linearDamping, angularDamping, &c);
     else
-        _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
+        _body = createRigidBodyInternal(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
 
     // Add the rigid body to the physics world.
     Game::getInstance()->getPhysicsController()->addRigidBody(this);
@@ -299,8 +299,9 @@ PhysicsRigidBody* PhysicsRigidBody::create(Node* node, Properties* properties)
     return body;
 }
 
-btRigidBody* PhysicsRigidBody::createBulletRigidBody(btCollisionShape* shape, float mass, Node* node,
-    float friction, float restitution, float linearDamping, float angularDamping, const Vector3* centerOfMassOffset)
+btRigidBody* PhysicsRigidBody::createRigidBodyInternal(btCollisionShape* shape, float mass, Node* node,
+                                                       float friction, float restitution, float linearDamping, float angularDamping, 
+                                                       const Vector3* centerOfMassOffset)
 {
     // If the mass is non-zero, then the object is dynamic so we calculate the local 
     // inertia. However, if the collision shape is a triangle mesh, we don't calculate 
@@ -349,12 +350,13 @@ PhysicsRigidBody::Listener::~Listener()
     // Unused
 }
 
-btScalar PhysicsRigidBody::Listener::addSingleResult(btManifoldPoint& cp, const btCollisionObject* a,
-    int partIdA, int indexA, const btCollisionObject* b, int partIdB, int indexB)
+btScalar PhysicsRigidBody::Listener::addSingleResult(btManifoldPoint& cp, 
+                                                     const btCollisionObject* a, int partIdA, int indexA, 
+                                                     const btCollisionObject* b, int partIdB, int indexB)
 {
     // Get pointers to the PhysicsRigidBody objects.
-    PhysicsRigidBody* rbA = Game::getInstance()->getPhysicsController()->getPhysicsRigidBody(a);
-    PhysicsRigidBody* rbB = Game::getInstance()->getPhysicsController()->getPhysicsRigidBody(b);
+    PhysicsRigidBody* rbA = Game::getInstance()->getPhysicsController()->getRigidBody(a);
+    PhysicsRigidBody* rbB = Game::getInstance()->getPhysicsController()->getRigidBody(b);
     
     // If the given rigid body pair has collided in the past, then
     // we notify the listener only if the pair was not colliding
@@ -378,8 +380,9 @@ btScalar PhysicsRigidBody::Listener::addSingleResult(btManifoldPoint& cp, const
     return 0.0f;
 }
 
-btScalar PhysicsRigidBody::CollidesWithCallback::addSingleResult(btManifoldPoint& cp, const btCollisionObject* a, int partIdA,
-            int indexA, const btCollisionObject* b, int partIdB, int indexB)
+btScalar PhysicsRigidBody::CollidesWithCallback::addSingleResult(btManifoldPoint& cp, 
+                                                                 const btCollisionObject* a, int partIdA, int indexA, 
+                                                                 const btCollisionObject* b, int partIdB, int indexB)
 {
     result = true;
     return 0.0f;

+ 11 - 13
gameplay/src/PhysicsRigidBody.h

@@ -86,20 +86,18 @@ public:
          * @param contactPoint The point (in world space) where the collision occurred.
          */
         virtual void collisionEvent(const CollisionPair& collisionPair, const Vector3& contactPoint) = 0;
-
-        /**
-         * Internal function used for Bullet integration (do not use or override).
-         */
-        btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* a, int partIdA,
-            int indexA, const btCollisionObject* b, int partIdB, int indexB);
         
     protected:
-
-        /** 
-         * Holds the collision status for each pair of rigid bodies. 
+        
+        /**
+         * Internal function used for Bullet integration (do not use or override).
          */
-        std::map<CollisionPair, int> _collisionStatus;
+        btScalar addSingleResult(btManifoldPoint& cp, 
+                                 const btCollisionObject* a, int partIdA, int indexA, 
+                                 const btCollisionObject* b, int partIdB, int indexB);
 
+        std::map<CollisionPair, int> _collisionStatus;  // Holds the collision status for each pair of rigid bodies. 
+        
     private:
 
         // Internal constant.
@@ -334,9 +332,9 @@ private:
 
     // Creates the underlying Bullet Physics rigid body object
     // for a PhysicsRigidBody object using the given parameters.
-    static btRigidBody* createBulletRigidBody(btCollisionShape* shape, float mass, Node* node,
-                                              float friction, float restitution, float linearDamping, float angularDamping,
-                                              const Vector3* centerOfMassOffset = NULL);
+    static btRigidBody* createRigidBodyInternal(btCollisionShape* shape, float mass, Node* node,
+                                                float friction, float restitution, float linearDamping, float angularDamping,
+                                                const Vector3* centerOfMassOffset = NULL);
 
     // Adds a constraint to this rigid body.
     void addConstraint(PhysicsConstraint* constraint);

+ 5 - 3
gameplay/src/gameplay.h

@@ -57,12 +57,14 @@
 #include "AnimationClip.h"
 
 // Physics
-#include "PhysicsConstraint.h"
 #include "PhysicsController.h"
+#include "PhysicsConstraint.h"
 #include "PhysicsFixedConstraint.h"
 #include "PhysicsGenericConstraint.h"
 #include "PhysicsHingeConstraint.h"
-#include "PhysicsMotionState.h"
-#include "PhysicsRigidBody.h"
 #include "PhysicsSocketConstraint.h"
 #include "PhysicsSpringConstraint.h"
+#include "PhysicsRigidBody.h"
+#include "PhysicsMotionState.h"
+
+