Parcourir la source

Merge pull request #30 from blackberry-gaming/next-cculy

Physics Support
Steve Grenier il y a 14 ans
Parent
commit
a68241e355
45 fichiers modifiés avec 3135 ajouts et 42 suppressions
  1. 18 3
      .gitignore
  2. 13 0
      gameplay.sln
  3. 17 8
      gameplay/.cproject
  4. 28 3
      gameplay/gameplay.vcxproj
  5. 71 0
      gameplay/gameplay.vcxproj.filters
  6. 26 0
      gameplay/src/Base.h
  7. 18 5
      gameplay/src/Game.cpp
  8. 10 0
      gameplay/src/Game.h
  9. 25 6
      gameplay/src/Joint.cpp
  10. 16 0
      gameplay/src/Joint.h
  11. 4 4
      gameplay/src/Material.cpp
  12. 1 1
      gameplay/src/MaterialParameter.h
  13. 1 1
      gameplay/src/Matrix.h
  14. 2 1
      gameplay/src/MeshSkin.cpp
  15. 3 0
      gameplay/src/MeshSkin.h
  16. 2 1
      gameplay/src/Model.cpp
  17. 3 3
      gameplay/src/Model.h
  18. 18 3
      gameplay/src/Node.cpp
  19. 28 1
      gameplay/src/Node.h
  20. 166 0
      gameplay/src/PhysicsConstraint.cpp
  21. 117 0
      gameplay/src/PhysicsConstraint.h
  22. 30 0
      gameplay/src/PhysicsConstraint.inl
  23. 346 0
      gameplay/src/PhysicsController.cpp
  24. 261 0
      gameplay/src/PhysicsController.h
  25. 24 0
      gameplay/src/PhysicsFixedConstraint.cpp
  26. 64 0
      gameplay/src/PhysicsFixedConstraint.h
  27. 30 0
      gameplay/src/PhysicsFixedConstraint.inl
  28. 71 0
      gameplay/src/PhysicsGenericConstraint.cpp
  29. 167 0
      gameplay/src/PhysicsGenericConstraint.h
  30. 90 0
      gameplay/src/PhysicsGenericConstraint.inl
  31. 51 0
      gameplay/src/PhysicsHingeConstraint.cpp
  32. 66 0
      gameplay/src/PhysicsHingeConstraint.h
  33. 71 0
      gameplay/src/PhysicsMotionState.cpp
  34. 59 0
      gameplay/src/PhysicsMotionState.h
  35. 258 0
      gameplay/src/PhysicsRigidBody.cpp
  36. 348 0
      gameplay/src/PhysicsRigidBody.h
  37. 146 0
      gameplay/src/PhysicsRigidBody.inl
  38. 58 0
      gameplay/src/PhysicsSocketConstraint.cpp
  39. 58 0
      gameplay/src/PhysicsSocketConstraint.h
  40. 67 0
      gameplay/src/PhysicsSpringConstraint.cpp
  41. 196 0
      gameplay/src/PhysicsSpringConstraint.h
  42. 70 0
      gameplay/src/PhysicsSpringConstraint.inl
  43. 4 0
      gameplay/src/PlatformWin32.cpp
  44. 2 2
      gameplay/src/Technique.cpp
  45. 11 0
      gameplay/src/gameplay.h

+ 18 - 3
.gitignore

@@ -14,6 +14,7 @@
 /Device-Profile
 /Device-Release
 /gameplay/Debug
+/gameplay/DebugMem
 /gameplay/Release
 /gameplay/Simulator
 /gameplay/Simulator-Coverage
@@ -25,7 +26,8 @@
 /gameplay-encoder/Debug
 /gameplay-encoder/Release
 /gameplay-samples/sample00-mesh/Debug
-/gameplay-samples/sample00-mesh//Release
+/gameplay-samples/sample00-mesh/DebugMem
+/gameplay-samples/sample00-mesh/Release
 /gameplay-samples/sample00-mesh/Simulator
 /gameplay-samples/sample00-mesh/Simulator-Coverage
 /gameplay-samples/sample00-mesh/Simulator-Profile
@@ -34,7 +36,8 @@
 /gameplay-samples/sample00-mesh/Device-Profile
 /gameplay-samples/sample00-mesh/Device-Release
 /gameplay-samples/sample01-longboard/Debug
-/gameplay-samples/sample01-longboard//Release
+/gameplay-samples/sample01-longboard/DebugMem
+/gameplay-samples/sample01-longboard/Release
 /gameplay-samples/sample01-longboard/Simulator
 /gameplay-samples/sample01-longboard/Simulator-Coverage
 /gameplay-samples/sample01-longboard/Simulator-Profile
@@ -43,6 +46,7 @@
 /gameplay-samples/sample01-longboard/Device-Profile
 /gameplay-samples/sample01-longboard/Device-Release
 /gameplay-samples/sample02-spaceship/Debug
+/gameplay-samples/sample02-spaceship/DebugMem
 /gameplay-samples/sample02-spaceship/Release
 /gameplay-samples/sample02-spaceship/Simulator
 /gameplay-samples/sample02-spaceship/Simulator-Coverage
@@ -52,6 +56,7 @@
 /gameplay-samples/sample02-spaceship/Device-Profile
 /gameplay-samples/sample02-spaceship/Device-Release
 /gameplay-samples/sample03-character/Debug
+/gameplay-samples/sample03-character/DebugMem
 /gameplay-samples/sample03-character/Release
 /gameplay-samples/sample03-character/Simulator
 /gameplay-samples/sample03-character/Simulator-Coverage
@@ -59,4 +64,14 @@
 /gameplay-samples/sample03-character/Device-Debug
 /gameplay-samples/sample03-character/Device-Coverage
 /gameplay-samples/sample03-character/Device-Profile
-/gameplay-samples/sample03-character/Device-Release
+/gameplay-samples/sample03-character/Device-Release
+/gameplay-samples/sample04-sandbox/Debug
+/gameplay-samples/sample04-sandbox/DebugMem
+/gameplay-samples/sample04-sandbox/Release
+/gameplay-samples/sample04-sandbox/Simulator
+/gameplay-samples/sample04-sandbox/Simulator-Coverage
+/gameplay-samples/sample04-sandbox/Simulator-Profile
+/gameplay-samples/sample04-sandbox/Device-Debug
+/gameplay-samples/sample04-sandbox/Device-Coverage
+/gameplay-samples/sample04-sandbox/Device-Profile
+/gameplay-samples/sample04-sandbox/Device-Release

+ 13 - 0
gameplay.sln

@@ -25,6 +25,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample03-character", "gamep
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gameplay-encoder", "gameplay-encoder\gameplay-encoder.vcxproj", "{9D69B743-4872-4DD1-8E30-0087C64298D7}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D3CA8AE2-3ED6-458B-963A-EDA671E6F51C}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample04-sandbox", "gameplay-samples\sample04-sandbox\sample04-sandbox.vcxproj", "{FA260001-5B2E-41B7-86DD-C7F26DF3A485}"
+	ProjectSection(ProjectDependencies) = postProject
+		{1032BA4B-57EB-4348-9E03-29DD63E80E4A} = {1032BA4B-57EB-4348-9E03-29DD63E80E4A}
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
@@ -68,6 +75,12 @@ Global
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.DebugMem|Win32.Build.0 = Debug|Win32
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.Release|Win32.ActiveCfg = Release|Win32
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.Release|Win32.Build.0 = Release|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.Debug|Win32.ActiveCfg = Debug|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.Debug|Win32.Build.0 = Debug|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.DebugMem|Win32.ActiveCfg = DebugMem|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.DebugMem|Win32.Build.0 = DebugMem|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.Release|Win32.ActiveCfg = Release|Win32
+		{FA260001-5B2E-41B7-86DD-C7F26DF3A485}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 17 - 8
gameplay/.cproject

@@ -19,7 +19,7 @@
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.debug.1686166742" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<option id="com.qnx.qcc.option.cpu.545743487" name="Target CPU:" superClass="com.qnx.qcc.option.cpu" value="com.qnx.qcc.option.gen.cpu.armle-v7" valueType="enumerated"/>
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.158841187" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Device-Debug}" id="cdt.managedbuild.target.gnu.builder.base.2098111998" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Device-Debug}" id="cdt.managedbuild.target.gnu.builder.base.2098111998" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.96907942" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1765481355" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.security.311918799" name="Enhanced Security (-fstack-protector-all)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
@@ -27,6 +27,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.2133604142" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.997142816" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -70,7 +71,7 @@
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.release.11990035" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<option id="com.qnx.qcc.option.cpu.33079389" name="Target CPU:" superClass="com.qnx.qcc.option.cpu" value="com.qnx.qcc.option.gen.cpu.armle-v7" valueType="enumerated"/>
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.1117051584" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Device-Release}" id="cdt.managedbuild.target.gnu.builder.base.1199322737" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Device-Release}" id="cdt.managedbuild.target.gnu.builder.base.1199322737" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.1345567866" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compiler.optlevel.1056793982" name="Optimization Level" superClass="com.qnx.qcc.option.compiler.optlevel" value="com.qnx.qcc.option.compiler.optlevel.2" valueType="enumerated"/>
 								<option id="com.qnx.qcc.option.compiler.security.324540233" name="Enhanced Security (-fstack-protector-all)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
@@ -78,6 +79,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1670164593" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.1380846613" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -119,7 +121,7 @@
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.profile.1494216018" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<option id="com.qnx.qcc.option.cpu.1727548796" name="Target CPU:" superClass="com.qnx.qcc.option.cpu" value="com.qnx.qcc.option.gen.cpu.armle-v7" valueType="enumerated"/>
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.1288889025" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Device-Profile}" id="cdt.managedbuild.target.gnu.builder.base.831558871" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Device-Profile}" id="cdt.managedbuild.target.gnu.builder.base.831558871" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.1281156842" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.626405189" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.1207899085" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
@@ -128,6 +130,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1503059677" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.81809638" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -172,7 +175,7 @@
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.coverage.1939228131" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<option id="com.qnx.qcc.option.cpu.832672244" name="Target CPU:" superClass="com.qnx.qcc.option.cpu" value="com.qnx.qcc.option.gen.cpu.armle-v7" valueType="enumerated"/>
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.987519072" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Device-Coverage}" id="cdt.managedbuild.target.gnu.builder.base.121802503" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Device-Coverage}" id="cdt.managedbuild.target.gnu.builder.base.121802503" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.306557636" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.168813234" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1032644527" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
@@ -181,6 +184,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1769677874" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.2007171407" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -224,7 +228,7 @@
 					<folderInfo id="com.qnx.qcc.configuration.staticLib.debug.559445444." name="/" resourcePath="">
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.debug.1260117207" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.795462400" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Simulator}" id="cdt.managedbuild.target.gnu.builder.base.10075032" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Simulator}" id="cdt.managedbuild.target.gnu.builder.base.10075032" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.1004416224" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1122485646" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.security.1671403331" name="Enhanced Security (-fstack-protector-all)" superClass="com.qnx.qcc.option.compiler.security" value="true" valueType="boolean"/>
@@ -232,6 +236,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.847642559" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.1038720310" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -274,7 +279,7 @@
 					<folderInfo id="com.qnx.qcc.configuration.staticLib.profile.191203500." name="/" resourcePath="">
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.profile.1691673400" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.1730932164" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Simulator-Profile}" id="cdt.managedbuild.target.gnu.builder.base.854227640" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Simulator-Profile}" id="cdt.managedbuild.target.gnu.builder.base.854227640" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.417488704" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1290366598" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.profile2.216911941" name="Build for Profiling (Function Instrumentation) (-finstrument-functions)" superClass="com.qnx.qcc.option.compiler.profile2" value="true" valueType="boolean"/>
@@ -283,6 +288,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.513622172" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.1961855927" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -326,7 +332,7 @@
 					<folderInfo id="com.qnx.qcc.configuration.staticLib.coverage.796584174." name="/" resourcePath="">
 						<toolChain id="com.qnx.qcc.toolChain.staticLib.coverage.349788538" name="QNX QCC" superClass="com.qnx.qcc.toolChain">
 							<targetPlatform archList="all" binaryParser="com.qnx.tools.ide.qde.core.QDEBynaryParser" id="com.qnx.qcc.targetPlatform.1819308065" osList="all" superClass="com.qnx.qcc.targetPlatform"/>
-							<builder buildPath="${workspace_loc:/gameplay/Simulator-Coverage}" id="cdt.managedbuild.target.gnu.builder.base.66192685" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/gameplay/Simulator-Coverage}" id="cdt.managedbuild.target.gnu.builder.base.66192685" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
 							<tool id="com.qnx.qcc.tool.compiler.563072865" name="QCC Compiler" superClass="com.qnx.qcc.tool.compiler">
 								<option id="com.qnx.qcc.option.compile.debug.1789973550" name="Debug (-g)" superClass="com.qnx.qcc.option.compile.debug" value="true" valueType="boolean"/>
 								<option id="com.qnx.qcc.option.compiler.coverage.1289221781" name="Build for Code Coverage (-Wc,-ftest-coverage -Wc,-fprofile-arcs)" superClass="com.qnx.qcc.option.compiler.coverage" value="true" valueType="boolean"/>
@@ -335,6 +341,7 @@
 									<listOptionValue builtIn="false" value="_FORTIFY_SOURCE=2"/>
 								</option>
 								<option id="com.qnx.qcc.option.compiler.includePath.1685994750" name="Include Directories (-I)" superClass="com.qnx.qcc.option.compiler.includePath" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}\..\external-deps\bullet\include&quot;"/>
 									<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
 								</option>
 								<inputType id="com.qnx.qcc.inputType.compiler.1658185881" superClass="com.qnx.qcc.inputType.compiler"/>
@@ -391,6 +398,8 @@
 			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/>
 		</scannerConfigBuildInfo>
 	</storageModule>
-	<storageModule moduleId="refreshScope"/>
+	<storageModule moduleId="refreshScope" versionNumber="1">
+		<resource resourceType="PROJECT" workspacePath="/gameplay"/>
+	</storageModule>
 	<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
 </cproject>

+ 28 - 3
gameplay/gameplay.vcxproj

@@ -50,6 +50,15 @@
     <ClCompile Include="src\Node.cpp" />
     <ClCompile Include="src\Package.cpp" />
     <ClCompile Include="src\ParticleEmitter.cpp" />
+    <ClCompile Include="src\PhysicsConstraint.cpp" />
+    <ClCompile Include="src\PhysicsController.cpp" />
+    <ClCompile Include="src\PhysicsFixedConstraint.cpp" />
+    <ClCompile Include="src\PhysicsGenericConstraint.cpp" />
+    <ClCompile Include="src\PhysicsHingeConstraint.cpp" />
+    <ClCompile Include="src\PhysicsMotionState.cpp" />
+    <ClCompile Include="src\PhysicsRigidBody.cpp" />
+    <ClCompile Include="src\PhysicsSocketConstraint.cpp" />
+    <ClCompile Include="src\PhysicsSpringConstraint.cpp" />
     <ClCompile Include="src\Plane.cpp" />
     <ClCompile Include="src\PlatformQNX.cpp" />
     <ClCompile Include="src\PlatformWin32.cpp" />
@@ -107,6 +116,15 @@
     <ClInclude Include="src\Node.h" />
     <ClInclude Include="src\Package.h" />
     <ClInclude Include="src\ParticleEmitter.h" />
+    <ClInclude Include="src\PhysicsConstraint.h" />
+    <ClInclude Include="src\PhysicsController.h" />
+    <ClInclude Include="src\PhysicsFixedConstraint.h" />
+    <ClInclude Include="src\PhysicsGenericConstraint.h" />
+    <ClInclude Include="src\PhysicsHingeConstraint.h" />
+    <ClInclude Include="src\PhysicsMotionState.h" />
+    <ClInclude Include="src\PhysicsRigidBody.h" />
+    <ClInclude Include="src\PhysicsSocketConstraint.h" />
+    <ClInclude Include="src\PhysicsSpringConstraint.h" />
     <ClInclude Include="src\Plane.h" />
     <ClInclude Include="src\Platform.h" />
     <ClInclude Include="src\Properties.h" />
@@ -159,6 +177,13 @@
     <None Include="src\Vector3.inl" />
     <None Include="src\Vector4.inl" />
   </ItemGroup>
+  <ItemGroup>
+    <None Include="src\PhysicsConstraint.inl" />
+    <None Include="src\PhysicsFixedConstraint.inl" />
+    <None Include="src\PhysicsGenericConstraint.inl" />
+    <None Include="src\PhysicsRigidBody.inl" />
+    <None Include="src\PhysicsSpringConstraint.inl" />
+  </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{1032BA4B-57EB-4348-9E03-29DD63E80E4A}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
@@ -219,7 +244,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\external-deps\bullet\include;..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <RuntimeTypeInfo>
       </RuntimeTypeInfo>
     </ClCompile>
@@ -235,7 +260,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;GAMEPLAY_MEM_LEAK_DETECTION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\external-deps\bullet\include;..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <RuntimeTypeInfo>true</RuntimeTypeInfo>
     </ClCompile>
     <Link>
@@ -256,7 +281,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\external-deps\bullet\include;..\external-deps\openal\include\AL;..\external-deps\alut\include\AL;..\external-deps\glew\include;..\external-deps\libpng\include;..\external-deps\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>

+ 71 - 0
gameplay/gameplay.vcxproj.filters

@@ -177,6 +177,33 @@
     <ClCompile Include="src\DebugNew.cpp">
 		<Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="src\PhysicsController.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsRigidBody.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsHingeConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsFixedConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsGenericConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsSocketConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsSpringConstraint.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
+    <ClCompile Include="src\PhysicsMotionState.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">
@@ -341,6 +368,33 @@
     <ClInclude Include="src\DebugNew.h">
       <Filter>src</Filter>
     </ClInclude>
+    <ClInclude Include="src\PhysicsController.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsMotionState.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsRigidBody.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsSpringConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsFixedConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsGenericConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsHingeConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsSocketConstraint.h">
+      <Filter>src</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="res\shaders\bumped-specular.vsh">
@@ -403,18 +457,32 @@
     <None Include="res\shaders\bumped-specular.fsh">
       <Filter>res\shaders</Filter>
     </None>
+  </ItemGroup>
+  <ItemGroup>
     <None Include="src\gameplay-main-macosx.mm">
       <Filter>src</Filter>
     </None>
+    <None Include="src\PhysicsFixedConstraint.inl">
+      <Filter>src</Filter>
+    </None>
     <None Include="src\BoundingBox.inl">
       <Filter>src</Filter>
     </None>
+    <None Include="src\PhysicsGenericConstraint.inl">
+      <Filter>src</Filter>
+    </None>
     <None Include="src\BoundingSphere.inl">
       <Filter>src</Filter>
     </None>
+    <None Include="src\PhysicsSpringConstraint.inl">
+      <Filter>src</Filter>
+    </None>
     <None Include="src\Matrix.inl">
       <Filter>src</Filter>
     </None>
+    <None Include="src\PhysicsRigidBody.inl">
+      <Filter>src</Filter>
+    </None>
     <None Include="src\Plane.inl">
       <Filter>src</Filter>
     </None>
@@ -433,5 +501,8 @@
     <None Include="src\Vector4.inl">
       <Filter>src</Filter>
     </None>
+    <None Include="src\PhysicsConstraint.inl">
+      <Filter>src</Filter>
+    </None>
   </ItemGroup>
 </Project>

+ 26 - 0
gameplay/src/Base.h

@@ -63,6 +63,32 @@ extern void printError(const char* format, ...);
 #define WARN(x) printError(x)
 #define WARN_VARG(x, ...) printError(x, __VA_ARGS__)
 
+// Bullet Physics
+#include <btBulletDynamicsCommon.h>
+
+// Since Bullet overrides new, we have to allocate objects manually using its
+// aligned allocation function when we turn on memory leak detection in GamePlay.
+#ifdef GAMEPLAY_MEM_LEAK_DETECTION
+#define BULLET_NEW(type, name, ...) \
+    type* name = (type*)btAlignedAlloc(sizeof(type), 16); \
+    type __##name##_tmp (__VA_ARGS__); \
+    memcpy(name, &__##name##_tmp, sizeof(type))
+
+#define BULLET_DELETE(name) \
+    if (name) \
+    { \
+        btAlignedFree(name); \
+        name = NULL; \
+    }
+
+#else
+#define BULLET_NEW(type, name, ...) \
+    type* name = new type(__VA_ARGS__)
+
+#define BULLET_DELETE(name) SAFE_DELETE(name)
+#endif
+
+
 // Debug new for memory leak detection
 #ifdef GAMEPLAY_MEM_LEAK_DETECTION
 #include "DebugNew.h"

+ 18 - 5
gameplay/src/Game.cpp

@@ -107,6 +107,9 @@ bool Game::startup()
     _audioController = new AudioController();
     _audioController->initialize();
 
+    _physicsController = new PhysicsController();
+    _physicsController->initialize();
+
     // Call user initialization.
     initialize();
     _state = RUNNING;
@@ -122,12 +125,13 @@ void Game::shutdown()
         finalize();
 
         _animationController->finalize();
-        delete _animationController;
-        _animationController = NULL;
+        SAFE_DELETE(_animationController);
 
         _audioController->finalize();
-        delete _audioController;
-        _audioController = NULL;
+        SAFE_DELETE(_audioController);
+
+        _physicsController->finalize();
+        SAFE_DELETE(_physicsController);
 
         RenderState::finalize();
     }
@@ -143,6 +147,7 @@ void Game::pause()
         _pausedTimeLast = Platform::getAbsoluteTime();
         _animationController->pause();
         _audioController->pause();
+        _physicsController->pause();
     }
 }
 
@@ -154,6 +159,7 @@ void Game::resume()
         _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
         _animationController->resume();
         _audioController->resume();
+        _physicsController->resume();
     }
 }
 
@@ -173,8 +179,10 @@ void Game::frame()
     long elapsedTime = (frameTime - lastFrameTime);
     lastFrameTime = frameTime;
 
-    // Update the schedule and running animations.
+    // Update the scheduled and running animations.
     _animationController->update(elapsedTime);
+    // Update the physics.
+    _physicsController->update(elapsedTime);
     // Application Update.
     update(elapsedTime);
 
@@ -251,6 +259,11 @@ const AudioController* Game::getAudioController() const
     return _audioController;
 }
 
+PhysicsController* Game::getPhysicsController()
+{
+    return _physicsController;
+}
+
 void Game::menu()
 {
 }

+ 10 - 0
gameplay/src/Game.h

@@ -8,6 +8,7 @@
 #include "Input.h"
 #include "AudioController.h"
 #include "AnimationController.h"
+#include "PhysicsController.h"
 #include "Vector4.h"
 
 namespace gameplay
@@ -174,6 +175,14 @@ public:
      */
     AnimationController* getAnimationController();
 
+    /**
+     * Gets the physics controller for managing control of physics
+     * associated with the game.
+     * 
+     * @return The physics controller for this game.
+     */
+    PhysicsController* getPhysicsController();
+
     /**
      * Menu callback on menu events.
      */
@@ -277,6 +286,7 @@ private:
     int _clearStencil;                          // The clear stencil value last used for clearing the stencil buffer.
     AnimationController* _animationController;  // Controls the scheduling and running of animations.
     AudioController* _audioController;          // Controls audio sources that are playing in the game.
+    PhysicsController* _physicsController;      // Controls the simulation of a physics scene and entities.
 };
 
 }

+ 25 - 6
gameplay/src/Joint.cpp

@@ -9,7 +9,7 @@ namespace gameplay
 {
 
 Joint::Joint(const char* id)
-    : Node(id), _jointMatrixDirty(true)
+    : Node(id), _jointMatrixDirty(true), _skin(NULL)
 {
 }
 
@@ -43,12 +43,8 @@ void Joint::updateJointMatrix(const Matrix& bindShape, Vector4* matrixPalette)
     {
         _jointMatrixDirty = false;
 
-        float r = (float)rand( ) / (float)RAND_MAX;
-        Matrix w = getWorldMatrix();
-        w.translate(r, r, r);
-
         Matrix t;
-        Matrix::multiply(getWorldMatrix(), getInverseBindPose(), &t);
+        Matrix::multiply(getJointMatrix(), getInverseBindPose(), &t);
         Matrix::multiply(t, bindShape, &t);
 
         matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
@@ -68,4 +64,27 @@ void Joint::setInverseBindPose(const Matrix& m)
     _jointMatrixDirty = true;
 }
 
+const Matrix& Joint::getWorldMatrix() const
+{
+    // If this is the root joint, then we 
+    // also apply the transform of the model
+    // that the skin is attached to to get the
+    // actual world matrix.
+    if (_parent == NULL && _skin != NULL)
+    {
+        Matrix::multiply(_skin->_model->getNode()->getWorldMatrix(), Node::getWorldMatrix(), &_jointWorld);
+    }
+    else
+    {
+        memcpy((void*)_jointWorld.m, Node::getWorldMatrix().m, sizeof(float) * 16);
+    }
+
+    return _jointWorld;
+}
+
+const Matrix& Joint::getJointMatrix() const
+{
+    return Node::getWorldMatrix();
+}
+
 }

+ 16 - 0
gameplay/src/Joint.h

@@ -35,6 +35,20 @@ public:
      */
     const Matrix& getInverseBindPose() const;
 
+    /**
+     * Gets the world matrix corresponding to this node.
+     *
+     * @return The world matrix of this node.
+     */
+    const Matrix& getWorldMatrix() const;
+
+    /**
+     * Gets the matrix corresponding to this joint.
+     *
+     * @return The matrix of this joint.
+     */
+    const Matrix& getJointMatrix() const;
+
 protected:
 
     /**
@@ -69,6 +83,8 @@ protected:
 
     Matrix _bindPose;
     bool _jointMatrixDirty;
+    MeshSkin* _skin;
+    mutable Matrix _jointWorld;
 };
 
 }

+ 4 - 4
gameplay/src/Material.cpp

@@ -24,7 +24,7 @@ Material::Material(const Material& m)
 
 Material::~Material()
 {
-	// Destroy all the techniques.
+    // Destroy all the techniques.
     for (unsigned int i = 0, count = _techniques.size(); i < count; ++i)
     {
         Technique* technique = _techniques[i];
@@ -59,7 +59,7 @@ Material* Material::create(const char* materialPath)
     // Create new material from the file passed in.
     Material* material = new Material();
 
-	// Go through all the material properties and create techniques under this material.
+    // Go through all the material properties and create techniques under this material.
     Properties* techniqueProperties = NULL;
     while ((techniqueProperties = materialProperties->getNextNamespace()))
     {
@@ -195,7 +195,7 @@ bool Material::loadTechnique(Material* material, Properties* techniqueProperties
     // Create a new technique
     Technique* technique = new Technique(techniqueProperties->getId(), material);
 
-	// Go through all the properties and create passes under this technique.
+    // Go through all the properties and create passes under this technique.
     techniqueProperties->rewind();
     Properties* passProperties = NULL;
     while ((passProperties = techniqueProperties->getNextNamespace()))
@@ -203,7 +203,7 @@ bool Material::loadTechnique(Material* material, Properties* techniqueProperties
         if (strcmp(passProperties->getNamespace(), "pass") == 0)
         {
             // Create and load passes.
-		    if (!loadPass(technique, passProperties))
+            if (!loadPass(technique, passProperties))
             {
                 SAFE_RELEASE(technique);
                 return false;

+ 1 - 1
gameplay/src/MaterialParameter.h

@@ -37,7 +37,7 @@ class MaterialParameter : public AnimationTarget
 
 public:
 
-     /**
+    /**
      * Animates the uniform.
      */
     static const int ANIMATE_UNIFORM = 1;

+ 1 - 1
gameplay/src/Matrix.h

@@ -235,7 +235,7 @@ public:
 //     * @param plane The Plane about which to create a reflection.
 //     * @param dst A matrix to store the result in.
 //     */
-//    static void createRefelction(const Plane& plane, Matrix* dst);
+//    static void createReflection(const Plane& plane, Matrix* dst);
 
     /**
      * Creates a scale matrix.

+ 2 - 1
gameplay/src/MeshSkin.cpp

@@ -12,7 +12,7 @@
 namespace gameplay
 {
 
-MeshSkin::MeshSkin() : _matrixPalette(NULL)
+MeshSkin::MeshSkin() : _matrixPalette(NULL), _model(NULL)
 {
 }
 
@@ -81,6 +81,7 @@ void MeshSkin::setJoint(Joint* joint, unsigned int index)
     assert(index < _joints.size());
 
     _joints[index] = joint;
+    _joints[index]->_skin = this;
 }
 
 Vector4* MeshSkin::getMatrixPalette() const

+ 3 - 0
gameplay/src/MeshSkin.h

@@ -11,6 +11,7 @@ namespace gameplay
 {
 
 class Package;
+class Model;
 class Joint;
 
 /**
@@ -20,6 +21,7 @@ class MeshSkin
 {
     friend class Package;
     friend class Model;
+    friend class Joint;
 
 public:
 
@@ -112,6 +114,7 @@ private:
     // Each 4x3 row-wise matrix is represented as 3 Vector4's.
     // The number of Vector4's is (_joints.size() * 3).
     Vector4* _matrixPalette;
+    Model* _model;
 };
 
 }

+ 2 - 1
gameplay/src/Model.cpp

@@ -42,7 +42,7 @@ Model* Model::create(Mesh* mesh)
     return new Model(mesh);
 }
 
-Mesh* Model::getMesh()
+Mesh* Model::getMesh() const
 {
     return _mesh;
 }
@@ -187,6 +187,7 @@ void Model::setSkin(MeshSkin* skin)
 
         // Assign the new skin
         _skin = skin;
+        _skin->_model = this;
     }
 }
 

+ 3 - 3
gameplay/src/Model.h

@@ -38,7 +38,7 @@ public:
      * 
      * @return The Mesh for this Model.
      */
-    Mesh* getMesh();
+    Mesh* getMesh() const;
 
     /**
      * Returns the number of parts in the Mesh for this Model.
@@ -150,13 +150,13 @@ private:
      * Destructor. Hidden use release() instead.
      */
     ~Model();
-
+
     /**
      * Sets the MeshSkin for this model.
      * 
      * @param skin The MeshSkin for this model.
      */
-    void setSkin(MeshSkin* skin);
+    void setSkin(MeshSkin* skin);
 
     /**
      * Sets the node that is associated with this model.

+ 18 - 3
gameplay/src/Node.cpp

@@ -15,8 +15,8 @@ namespace gameplay
 
 Node::Node(const char* id)
     : _scene(NULL), _firstChild(NULL), _nextSibling(NULL), _prevSibling(NULL), _parent(NULL), _childCount(NULL),
-    _camera(NULL), _light(NULL), _model(NULL), _audioSource(NULL), _particleEmitter(NULL), _dirtyBits(NODE_DIRTY_ALL),
-    _notifyHierarchyChanged(true), _boundsType(NONE)
+    _camera(NULL), _light(NULL), _model(NULL), _audioSource(NULL), _particleEmitter(NULL), _physicsRigidBody(NULL), 
+    _dirtyBits(NODE_DIRTY_ALL), _notifyHierarchyChanged(true), _boundsType(NONE)
 {
     if (id)
     {
@@ -51,6 +51,7 @@ Node::~Node()
     SAFE_RELEASE(_model);
     SAFE_RELEASE(_audioSource);
     SAFE_RELEASE(_particleEmitter);
+    SAFE_DELETE(_physicsRigidBody);
 }
 
 Node* Node::create(const char* id)
@@ -300,7 +301,7 @@ const Matrix& Node::getWorldMatrix() const
         // If we have a parent, multiply our parent world transform by our local
         // transform to obtain our final resolved world transform.
         Node* parent = getParent();
-        if (parent)
+        if (parent && !_physicsRigidBody)
         {
             Matrix::multiply(parent->getWorldMatrix(), getMatrix(), &_world);
         }
@@ -800,4 +801,18 @@ void Node::setParticleEmitter(ParticleEmitter* emitter)
     }
 }
 
+PhysicsRigidBody* Node::getPhysicsRigidBody() const
+{
+    return _physicsRigidBody;
+}
+
+void Node::setPhysicsRigidBody(PhysicsRigidBody::Type type, float mass, float friction,
+        float restitution, float linearDamping, float angularDamping)
+{
+    SAFE_DELETE(_physicsRigidBody);
+    
+    if (type != PhysicsRigidBody::SHAPE_NONE)
+        _physicsRigidBody = new PhysicsRigidBody(this, type, mass, friction, restitution, linearDamping, angularDamping);
+}
+
 }

+ 28 - 1
gameplay/src/Node.h

@@ -11,6 +11,7 @@
 #include "Model.h"
 #include "AudioSource.h"
 #include "ParticleEmitter.h"
+#include "PhysicsRigidBody.h"
 #include "BoundingBox.h"
 
 namespace gameplay
@@ -174,7 +175,7 @@ public:
      *
      * @return The world matrix of this node.
      */
-    const Matrix& getWorldMatrix() const;
+    virtual const Matrix& getWorldMatrix() const;
 
     /**
      * Gets the world view matrix corresponding to this node.
@@ -356,6 +357,31 @@ public:
      */
     void setParticleEmitter(ParticleEmitter* emitter);
 
+    /**
+     * Returns the pointer to this node's physics rigid body or NULL.
+     *
+     * @return The pointer to this node's physics rigid body or NULL.
+     */
+    PhysicsRigidBody* getPhysicsRigidBody() const;
+
+    /**
+     * Sets (or disables) the physics rigid body for this node.
+     * 
+     * Note: This is only allowed for nodes that have a model attached to them.
+     *
+     * @param type The type of rigid body to set; to disable the physics rigid
+     *      body, pass PhysicsRigidBody#SHAPE_NONE.
+     * @param mass The mass of the rigid body, in kilograms.
+     * @param friction The friction of the rigid body (between 0.0 and 1.0, where 0.0 is
+     *      minimal friction and 1.0 is maximal friction).
+     * @param restitution The restitution of the rigid body (this controls the bounciness of
+     *      the rigid body; between 0.0 and 1.0, where 0.0 is minimal bounciness and 1.0 is maximal bounciness).
+     * @param linearDamping The percentage of linear velocity lost per second (between 0.0 and 1.0).
+     * @param angularDamping The percentage of angular velocity lost per second (between 0.0 and 1.0).
+     */
+    void setPhysicsRigidBody(PhysicsRigidBody::Type type, float mass = 0.0f, float friction = 0.5f,
+        float restitution = 0.0f, float linearDamping = 0.0f, float angularDamping = 0.0f);
+
     /**
      * Returns the bounding box for the Node, in world space.
      *
@@ -430,6 +456,7 @@ protected:
     Model* _model;
     AudioSource* _audioSource;
     ParticleEmitter* _particleEmitter;
+    PhysicsRigidBody* _physicsRigidBody;
     mutable Matrix _world;
     mutable int _dirtyBits;
     bool _notifyHierarchyChanged;

+ 166 - 0
gameplay/src/PhysicsConstraint.cpp

@@ -0,0 +1,166 @@
+/*
+ * PhysicsConstraint.cpp
+ */
+
+#include "PhysicsConstraint.h"
+
+#include "Game.h"
+#include "Node.h"
+#include "PhysicsMotionState.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsConstraint::PhysicsConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+    : _a(a), _b(b), _constraint(NULL)
+{
+}
+
+PhysicsConstraint::~PhysicsConstraint()
+{
+    // Remove the physics rigid bodies' references to this constraint.
+    if (_a)
+        _a->removeConstraint(this);
+    if (_b)
+        _b->removeConstraint(this);
+
+    // Remove the constraint from the physics world and delete the Bullet object.
+    Game::getInstance()->getPhysicsController()->removeConstraint(this);
+    SAFE_DELETE(_constraint);
+}
+
+Vector3 PhysicsConstraint::centerOfMassMidpoint(const Node* a, const Node* b)
+{
+    Vector3 tA, tB;
+    a->getWorldMatrix().getTranslation(&tA);
+    b->getWorldMatrix().getTranslation(&tB);
+
+    tA = getWorldCenterOfMass(a->getModel());
+    tB = getWorldCenterOfMass(b->getModel());
+    
+    Vector3 d(tA, tB);
+    d.scale(0.5f);
+    Vector3 c(tA);
+    c.add(d);
+
+    return c;
+}
+
+Quaternion PhysicsConstraint::getRotationOffset(const Node* node, const Vector3& point)
+{
+    // Create a translation matrix that translates to the given origin.
+    Matrix m;
+    Matrix::createTranslation(point, &m);
+
+    // Calculate the rotation offset to the rigid body by transforming 
+    // the translation matrix above into the rigid body's local space 
+    // (multiply by the inverse world matrix) and extracting the rotation.
+    Matrix mi;
+    node->getWorldMatrix().invert(&mi);
+    mi.multiply(m);
+    
+    Quaternion r;
+    mi.getRotation(&r);
+
+    return r;
+}
+
+Vector3 PhysicsConstraint::getTranslationOffset(const Node* node, const Vector3& point)
+{
+    // Create a translation matrix that translates to the given origin.
+    Matrix m;
+    Matrix::createTranslation(point, &m);
+
+    // Calculate the translation offset to the rigid body by transforming 
+    // the translation matrix above into the rigid body's local space 
+    // (multiply by the inverse world matrix) and extracting the translation.
+    Matrix mi;
+    node->getWorldMatrix().invert(&mi);
+    mi.multiply(m);
+    
+    Vector3 t;
+    mi.getTranslation(&t);
+
+    Vector3 s;
+    node->getWorldMatrix().getScale(&s);
+
+    t.x *= s.x;
+    t.y *= s.y;
+    t.z *= s.z;
+    
+    t = offsetByCenterOfMass(node, t);
+
+    return t;
+}
+
+btTransform PhysicsConstraint::getTransformOffset(const Node* node, const Vector3& origin)
+{
+    // Create a translation matrix that translates to the given origin.
+    Matrix m;
+    Matrix::createTranslation(origin, &m);
+
+    // Calculate the translation and rotation offset to the rigid body
+    // by transforming the translation matrix above into the rigid body's
+    // local space (multiply by the inverse world matrix and extract components).
+    Matrix mi;
+    node->getWorldMatrix().invert(&mi);
+    mi.multiply(m);
+
+    Quaternion r;
+    mi.getRotation(&r);
+    
+    Vector3 t;
+    mi.getTranslation(&t);
+
+    Vector3 s;
+    node->getWorldMatrix().getScale(&s);
+
+    t.x *= s.x;
+    t.y *= s.y;
+    t.z *= s.z;
+    
+    t = offsetByCenterOfMass(node, t);
+
+    return btTransform(btQuaternion(r.x, r.y, r.z, r.w), btVector3(t.x, t.y, t.z));
+}
+
+Vector3 PhysicsConstraint::getWorldCenterOfMass(const Model* model)
+{
+    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 = 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.
+            WARN_VARG("Model \'%s\' has no bounding volume - center of mass is defaulting to local coordinate origin.", model->getNode()->getId());
+            model->getNode()->getWorldMatrix().transformPoint(&center);
+        }
+    }
+
+    return center;
+}
+
+Vector3 PhysicsConstraint::offsetByCenterOfMass(const Node* node, const Vector3& v)
+{
+    btVector3 centerOfMassOffset = ((PhysicsMotionState*)node->getPhysicsRigidBody()->_body->getMotionState())->_centerOfMassOffset.getOrigin();
+    return Vector3(v.x + centerOfMassOffset.x(), v.y + centerOfMassOffset.y(), v.z + centerOfMassOffset.z());
+}
+
+}

+ 117 - 0
gameplay/src/PhysicsConstraint.h

@@ -0,0 +1,117 @@
+/*
+ * PhysicsConstraint.h
+ */
+
+#ifndef PHYSICSCONSTRAINT_H_
+#define PHYSICSCONSTRAINT_H_
+
+#include "Base.h"
+#include "Model.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+    class Node;
+    class PhysicsRigidBody;
+
+/**
+ * Base class for physics constraints.
+ */
+class PhysicsConstraint
+{
+    friend class PhysicsController;
+    friend class PhysicsRigidBody;
+
+public:
+    /**
+     * Gets the impulse needed to break the constraint.
+     * 
+     * @return The impulse needed to break the constraint.
+     */
+    inline float getBreakingImpulse() const;
+
+    /**
+     * Sets the impulse needed to break the constraint
+     * (if an impulse greater than or equal to the given
+     * value is applied to the constraint, the constraint
+     * will be broken).
+     * 
+     * @param impulse The impulse needed to break the constraint.
+     */
+    inline void setBreakingImpulse(float impulse);
+
+    /**
+     * Gets whether the constraint is enabled or not.
+     * 
+     * @return Whether the constraint is enabled or not.
+     */
+    inline bool isEnabled() const;
+
+    /**
+     * Sets whether the constraint is enabled or not.
+     * 
+     * @param enabled Whether the constraint is enabled or not.
+     */
+    inline void setEnabled(bool enabled);
+
+    /**
+     * Calculates the midpoint between the given nodes' centers of mass.
+     * 
+     * @param a The first node.
+     * @param b The second node.
+     */
+    static Vector3 centerOfMassMidpoint(const Node* a, const Node* b);
+
+    /**
+     * Calculates the rotation offset to the given point in the given node's local space.
+     * 
+     * @param node The node to calculate a rotation offset for.
+     * @param point The point to calculate the rotation offset to.
+     */
+    static Quaternion getRotationOffset(const Node* node, const Vector3& point);
+
+    /**
+     * Calculates the translation offset to the given point in the given node's local space.
+     * 
+     * @param node The node to calculate a translation offset for.
+     * @param point The point to calculate the translation offset to.
+     */
+    static Vector3 getTranslationOffset(const Node* node, const Vector3& point);
+
+protected:
+    /**
+     * Constructor.
+     */
+    PhysicsConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Destructor.
+     */
+    virtual ~PhysicsConstraint();
+
+    /**
+     * Calculates the transform to be used as the offset (i.e. "frame in" 
+     * parameter in Bullet terms) to the given constraint origin.
+     */
+    static btTransform getTransformOffset(const Node* node, const Vector3& origin);
+    
+    /**
+     * Calculates the center of mass in world space of the given model.
+     */
+    static Vector3 getWorldCenterOfMass(const Model* model);
+
+    /**
+     * Offsets the given vector by the given node's center of mass.
+     */
+    static Vector3 offsetByCenterOfMass(const Node* node, const Vector3& v);
+
+    PhysicsRigidBody* _a;
+    PhysicsRigidBody* _b;
+    btTypedConstraint* _constraint;
+};
+
+}
+
+#include "PhysicsConstraint.inl"
+
+#endif

+ 30 - 0
gameplay/src/PhysicsConstraint.inl

@@ -0,0 +1,30 @@
+/*
+ * PhysicsConstraint.inl
+ */
+
+#include "PhysicsConstraint.h"
+
+namespace gameplay
+{
+
+inline float PhysicsConstraint::getBreakingImpulse() const
+{
+    return _constraint->getBreakingImpulseThreshold();
+}
+
+inline void PhysicsConstraint::setBreakingImpulse(float impulse)
+{
+    _constraint->setBreakingImpulseThreshold(impulse);
+}
+
+inline bool PhysicsConstraint::isEnabled() const
+{
+    return _constraint->isEnabled();
+}
+
+inline void PhysicsConstraint::setEnabled(bool enabled)
+{
+    _constraint->setEnabled(enabled);
+}
+
+}

+ 346 - 0
gameplay/src/PhysicsController.cpp

@@ -0,0 +1,346 @@
+/*
+ * PhysicsController.cpp
+ */
+
+#include "Base.h"
+#include "Game.h"
+#include "PhysicsController.h"
+#include "PhysicsMotionState.h"
+
+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), _status(Listener::DEACTIVATED), _listeners(NULL)
+{
+}
+
+void PhysicsController::addStatusListener(Listener* listener)
+{
+    if (!_listeners)
+        _listeners = new std::vector<Listener*>();
+
+    _listeners->push_back(listener);
+}
+
+PhysicsController::~PhysicsController()
+{
+    SAFE_DELETE(_listeners);
+}
+
+PhysicsFixedConstraint* PhysicsController::createFixedConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    PhysicsFixedConstraint* constraint = new PhysicsFixedConstraint(a, b);
+    setupConstraint(a, b, constraint);
+    return constraint;
+}
+
+PhysicsGenericConstraint* PhysicsController::createGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    PhysicsGenericConstraint* constraint = new PhysicsGenericConstraint(a, b);
+    setupConstraint(a, b, constraint);
+    return constraint;
+}
+
+PhysicsGenericConstraint* PhysicsController::createGenericConstraint(PhysicsRigidBody* a,
+    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);
+    return constraint;
+}
+
+PhysicsHingeConstraint* PhysicsController::createHingeConstraint(PhysicsRigidBody* a,
+    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);
+    return constraint;
+}
+
+PhysicsSocketConstraint* PhysicsController::createSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    PhysicsSocketConstraint* constraint = new PhysicsSocketConstraint(a, b);
+    setupConstraint(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);
+    return constraint;
+}
+
+PhysicsSpringConstraint* PhysicsController::createSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    PhysicsSpringConstraint* constraint = new PhysicsSpringConstraint(a, b);
+    setupConstraint(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* constraint = new PhysicsSpringConstraint(a, rotationOffsetA, 
+        translationOffsetA, b, rotationOffsetB, translationOffsetB);
+    setupConstraint(a, b, constraint);
+    return constraint;
+}
+
+const Vector3& PhysicsController::getGravity(const Vector3& gravity) const
+{
+    return _gravity;
+}
+
+void PhysicsController::setGravity(const Vector3& gravity)
+{
+    _gravity = gravity;
+
+    if (_world)
+    {
+        _world->setGravity(btVector3(_gravity.x, _gravity.y, _gravity.z));
+    }
+}
+
+void PhysicsController::initialize()
+{
+    _collisionConfiguration = new btDefaultCollisionConfiguration();
+    _dispatcher = new btCollisionDispatcher(_collisionConfiguration);
+    _overlappingPairCache = new btDbvtBroadphase();
+    _solver = new btSequentialImpulseConstraintSolver();
+
+    // Create the world.
+    _world = new btDiscreteDynamicsWorld(_dispatcher, _overlappingPairCache, _solver, _collisionConfiguration);
+    _world->setGravity(btVector3(_gravity.x, _gravity.y, _gravity.z));
+}
+
+void PhysicsController::finalize()
+{
+    // Clean up the world and its various components.
+    SAFE_DELETE(_world);
+    SAFE_DELETE(_solver);
+    SAFE_DELETE(_overlappingPairCache);
+    SAFE_DELETE(_dispatcher);
+    SAFE_DELETE(_collisionConfiguration);
+}
+
+void PhysicsController::pause()
+{
+    // DUMMY FUNCTION
+}
+
+void PhysicsController::resume()
+{
+    // DUMMY FUNCTION
+}
+
+void PhysicsController::update(long elapsedTime)
+{
+    // Update the physics simulation, with a maximum
+    // of 10 simulation steps being performed in a given frame.
+    //
+    // Note that stepSimulation takes elapsed time in seconds
+    // so we divide by 1000 to convert from milliseconds.
+    _world->stepSimulation((float)elapsedTime * 0.001, 10);
+
+    // If we have status listeners, then check if our status has changed.
+    if (_listeners)
+    {
+        Listener::EventType oldStatus = _status;
+
+        if (_status = Listener::DEACTIVATED)
+        {
+            for (int i = 0; i < _world->getNumCollisionObjects(); i++)
+            {
+                if (_world->getCollisionObjectArray()[i]->isActive())
+                {
+                    _status = Listener::ACTIVATED;
+                    break;
+                }
+            }
+        }
+        else
+        {
+            bool allInactive = true;
+            for (int i = 0; i < _world->getNumCollisionObjects(); i++)
+            {
+                if (_world->getCollisionObjectArray()[i]->isActive())
+                {
+                    allInactive = false;
+                    break;
+                }
+            }
+
+            if (allInactive)
+                _status = Listener::DEACTIVATED;
+        }
+
+        // If the status has changed, notify our listeners.
+        if (oldStatus != _status)
+        {
+            for (unsigned int k = 0; k < _listeners->size(); k++)
+            {
+                (*_listeners)[k]->statusEvent(_status);
+            }
+        }
+    }
+
+    // All statuses are set with the DIRTY bit before collision processing occurs.
+    // During collision processing, if a collision occurs, the status is 
+    // set to COLLISION and the DIRTY bit is cleared. Then, after collision processing 
+    // is finished, if a given status is still dirty, the COLLISION bit is cleared.
+
+    // Dirty all the collision listeners' collision status caches.
+    for (unsigned int i = 0; i < _bodies.size(); i++)
+    {
+        if (_bodies[i]->_listeners)
+        {
+            for (unsigned int k = 0; k < _bodies[i]->_listeners->size(); k++)
+            {
+                std::map<PhysicsRigidBody::CollisionPair, int>::iterator iter = (*_bodies[i]->_listeners)[k]->_collisionStatus.begin();
+                for (; iter != (*_bodies[i]->_listeners)[k]->_collisionStatus.end(); iter++)
+                {
+                    iter->second |= PhysicsRigidBody::Listener::DIRTY;
+                }
+            }
+        }
+    }
+
+    // Go through the physics rigid bodies and update the collision listeners.
+    for (unsigned int i = 0; i < _bodies.size(); i++)
+    {
+        if (_bodies[i]->_listeners)
+        {
+            for (unsigned int k = 0; k < _bodies[i]->_listeners->size(); k++)
+            {
+                std::map<PhysicsRigidBody::CollisionPair, int>::iterator iter = (*_bodies[i]->_listeners)[k]->_collisionStatus.begin();
+                for (; iter != (*_bodies[i]->_listeners)[k]->_collisionStatus.end(); iter++)
+                {
+                    // If this collision pair was one that was registered for listening, then perform the collision test.
+                    // (In the case where we register for all collisions with a rigid body, there will be a lot
+                    // of collision pairs in the status cache that we did not explicitly register for.)
+                    if ((iter->second & PhysicsRigidBody::Listener::REGISTERED) != 0)
+                    {
+                        if (iter->first._rbB)
+                            Game::getInstance()->getPhysicsController()->_world->contactPairTest(iter->first._rbA->_body, iter->first._rbB->_body, *(*_bodies[i]->_listeners)[k]);
+                        else
+                            Game::getInstance()->getPhysicsController()->_world->contactTest(iter->first._rbA->_body, *(*_bodies[i]->_listeners)[k]);
+                    }
+                }   
+            }
+        }
+    }
+
+    // Go through all the collision listeners and update their collision status caches.
+    for (unsigned int i = 0; i < _bodies.size(); i++)
+    {
+        if (_bodies[i]->_listeners)
+        {
+            for (unsigned int k = 0; k < _bodies[i]->_listeners->size(); k++)
+            {
+                std::map<PhysicsRigidBody::CollisionPair, int>::iterator iter = (*_bodies[i]->_listeners)[k]->_collisionStatus.begin();
+                for (; iter != (*_bodies[i]->_listeners)[k]->_collisionStatus.end(); iter++)
+                {
+                    if ((iter->second & PhysicsRigidBody::Listener::DIRTY) != 0)
+                    {
+                        iter->second &= ~PhysicsRigidBody::Listener::COLLISION;
+                    }
+                }
+            }
+        }
+    }
+}
+
+void PhysicsController::addRigidBody(PhysicsRigidBody* body)
+{
+    _world->addRigidBody(body->_body);
+    _bodies.push_back(body);
+}
+
+btCollisionShape* PhysicsController::getBox(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(btBoxShape, box, halfExtents);
+    _shapes.push_back(box);
+
+    return box;
+}
+
+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(btSphereShape, sphere, uniformScale * radius);
+    _shapes.push_back(sphere);
+
+    return sphere;
+}
+
+PhysicsRigidBody* PhysicsController::getPhysicsRigidBody(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;
+}
+
+void PhysicsController::removeConstraint(PhysicsConstraint* constraint)
+{
+    // Find the constraint and remove it from the physics world.
+    for (int i = _world->getNumConstraints() - 1; i >= 0; i--)
+    {
+        btTypedConstraint* currentConstraint = _world->getConstraint(i);
+        if (constraint->_constraint == currentConstraint)
+        {
+            _world->removeConstraint(currentConstraint);
+            break;
+        }
+    }
+}
+
+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;
+        }
+    }
+}
+
+void PhysicsController::setupConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
+{
+    a->addConstraint(constraint);
+    if (b)
+    {
+        b->addConstraint(constraint);
+    }
+
+    _world->addConstraint(constraint->_constraint);
+}
+
+}

+ 261 - 0
gameplay/src/PhysicsController.h

@@ -0,0 +1,261 @@
+/*
+ * PhysicsController.h
+ */
+
+#ifndef PHYSICSCONTROLLER_H_
+#define PHYSICSCONTROLLER_H_
+
+#include "PhysicsConstraint.h"
+#include "PhysicsFixedConstraint.h"
+#include "PhysicsGenericConstraint.h"
+#include "PhysicsHingeConstraint.h"
+#include "PhysicsSocketConstraint.h"
+#include "PhysicsSpringConstraint.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+    
+/**
+ * Defines a class for controlling game physics.
+ */
+class PhysicsController
+{
+    friend class Game;
+    friend class PhysicsConstraint;
+    friend class PhysicsRigidBody;
+
+public:
+    /**
+     * Status listener interface.
+     */
+    class Listener
+    {
+    public:
+
+        /**
+         * The type of physics status event.
+         */
+        enum EventType 
+        {
+            /**
+             * Event fired when there were no active physics objects and at least one is now active.
+             */
+            ACTIVATED,
+
+            /**
+             * Event fired when there are no more active physics objects in the world.
+             */
+            DEACTIVATED
+        };
+
+        /**
+         * Handles when the physics world status changes.
+         */
+        virtual void statusEvent(EventType type) = 0;
+    };
+
+    /**
+     * Adds a status listener.
+     * 
+     * @param listener The listener to add.
+     */
+    void addStatusListener(Listener* listener);
+
+    /**
+     * Creates a fixed constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsFixedConstraint* createFixedConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b = NULL);
+
+    /**
+     * Creates a generic constraint so that the rigid body (or bodies) is
+     * (are) constrained to its (their) current world position(s).
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsGenericConstraint* createGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b = NULL);
+
+    /**
+     * Creates a generic constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @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());
+
+    /**
+     * Creates a hinge constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @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());
+
+    /**
+     * Creates a socket constraint so that the rigid body (or bodies) is
+     * (are) constrained using its (their) current world position(s) for
+     * the translation offset(s) to the constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsSocketConstraint* createSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b = NULL);
+
+    /**
+     * Creates a socket constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param translationOffsetB The translation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     */
+    PhysicsSocketConstraint* createSocketConstraint(PhysicsRigidBody* a, const Vector3& translationOffsetA,
+        PhysicsRigidBody* b = NULL, const Vector3& translationOffsetB = Vector3());
+
+    /**
+     * Creates a spring constraint so that the rigid body (or bodies) is
+     * (are) constrained using its (their) current world position(s) for
+     * the translation offset(s) to the constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsSpringConstraint* createSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Creates a spring constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @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);
+
+    /**
+     * Gets the gravity vector for the simulated physics world.
+     * 
+     * @return The gravity vector.
+     */
+    const Vector3& getGravity(const Vector3& gravity) const;
+
+    /**
+     * Sets the gravity vector for the simulated physics world.
+     * 
+     * @param gravity The gravity vector.
+     */
+    void setGravity(const Vector3& gravity);
+
+private:
+    /**
+     * Constructor.
+     */
+    PhysicsController();
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsController();
+
+    /**
+     * Controller initialize.
+     */
+    void initialize();
+
+    /**
+     * Controller finalize.
+     */
+    void finalize();
+
+    /**
+     * Controller pause.
+     */
+    void pause();
+
+    /**
+     * Controller resume.
+     */
+    void resume();
+
+    /**
+     * Controller update.
+     */
+    void update(long elapsedTime);
+
+    // 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);
+
+    // Gets the corresponding GamePlay object for the given Bullet object.
+    PhysicsRigidBody* getPhysicsRigidBody(const btCollisionObject* collisionObject);
+
+    // Creates a sphere collision shape to be used in the creation of a rigid body.
+    btCollisionShape* getSphere(float radius, const btVector3& scale);
+
+    // Removes the given constraint from the simulated physics world.
+    void removeConstraint(PhysicsConstraint* constraint);
+
+    // 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);
+    
+    Vector3 _gravity;
+    btDefaultCollisionConfiguration* _collisionConfiguration;
+    btCollisionDispatcher* _dispatcher;
+    btBroadphaseInterface* _overlappingPairCache;
+    btSequentialImpulseConstraintSolver* _solver;
+    btDynamicsWorld* _world;
+    btAlignedObjectArray<btCollisionShape*> _shapes;
+    Listener::EventType _status;
+    std::vector<PhysicsRigidBody*> _bodies;
+    std::vector<Listener*>* _listeners;
+};
+
+}
+
+#endif

+ 24 - 0
gameplay/src/PhysicsFixedConstraint.cpp

@@ -0,0 +1,24 @@
+/**
+ * PhysicsFixedConstraint.cpp
+ */
+
+#include "PhysicsFixedConstraint.h"
+
+namespace gameplay
+{
+
+PhysicsFixedConstraint::PhysicsFixedConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+    : PhysicsGenericConstraint(a, b)
+{
+    PhysicsGenericConstraint::setAngularLowerLimit(Vector3(0.0f, 0.0f, 0.0f));
+    PhysicsGenericConstraint::setAngularUpperLimit(Vector3(0.0f, 0.0f, 0.0f));
+    PhysicsGenericConstraint::setLinearLowerLimit(Vector3(0.0f, 0.0f, 0.0f));
+    PhysicsGenericConstraint::setLinearUpperLimit(Vector3(0.0f, 0.0f, 0.0f));
+}
+
+PhysicsFixedConstraint::~PhysicsFixedConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+}

+ 64 - 0
gameplay/src/PhysicsFixedConstraint.h

@@ -0,0 +1,64 @@
+/*
+ * PhysicsFixedConstraint.h
+ */
+
+#ifndef PHYSICSFIXEDCONSTRAINT_H_
+#define PHYSICSFIXEDCONSTRAINT_H_
+
+#include "PhysicsGenericConstraint.h"
+
+namespace gameplay
+{
+
+/**
+ * Represents a constraint where two rigid bodies 
+ * (or one rigid body and the world) are bound together.
+ *
+ * (This is similar in concept to parenting one node to another,
+ * but can be used in specific situations for a more appropriate effect
+ * (e.g. for implementing sticky projectiles, etc.).)
+ */
+class PhysicsFixedConstraint : public PhysicsGenericConstraint
+{
+    friend class PhysicsController;
+
+protected:
+    /**
+     * @see PhysicsGenericConstraint
+     */
+    PhysicsFixedConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsFixedConstraint();
+
+    // Note: We make these functions protected to prevent usage
+    // (these are public in the base class, PhysicsGenericConstraint).
+
+    /**
+     * Protected to prevent usage.
+     */
+    inline void setAngularLowerLimit(const Vector3& limit);
+    
+    /**
+     * Protected to prevent usage.
+     */
+    inline void setAngularUpperLimit(const Vector3& limit);
+    
+    /**
+     * Protected to prevent usage.
+     */
+    inline void setLinearLowerLimit(const Vector3& limit);
+    
+    /**
+     * Protected to prevent usage.
+     */
+    inline void setLinearUpperLimit(const Vector3& limit);
+};
+
+}
+
+#include "PhysicsFixedConstraint.inl"
+
+#endif

+ 30 - 0
gameplay/src/PhysicsFixedConstraint.inl

@@ -0,0 +1,30 @@
+/**
+ * PhysicsFixedConstraint.inl
+ */
+
+#include "PhysicsFixedConstraint.h"
+
+namespace gameplay
+{
+
+inline void PhysicsFixedConstraint::setAngularLowerLimit(const Vector3& limit)
+{
+    PhysicsGenericConstraint::setAngularLowerLimit(limit);
+}
+
+inline void PhysicsFixedConstraint::setAngularUpperLimit(const Vector3& limit)
+{
+    PhysicsGenericConstraint::setAngularUpperLimit(limit);
+}
+
+inline void PhysicsFixedConstraint::setLinearLowerLimit(const Vector3& limit)
+{
+    PhysicsGenericConstraint::setLinearLowerLimit(limit);
+}
+
+inline void PhysicsFixedConstraint::setLinearUpperLimit(const Vector3& limit)
+{
+    PhysicsGenericConstraint::setLinearUpperLimit(limit);
+}
+
+}

+ 71 - 0
gameplay/src/PhysicsGenericConstraint.cpp

@@ -0,0 +1,71 @@
+/**
+ * PhysicsGenericConstraint.cpp
+ */
+
+#include "PhysicsGenericConstraint.h"
+
+#include "Node.h"
+#include "PhysicsMotionState.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsGenericConstraint::PhysicsGenericConstraint()
+    : PhysicsConstraint(NULL, NULL), _rotationOffsetA(NULL), _rotationOffsetB(NULL),
+    _translationOffsetA(NULL), _translationOffsetB(NULL)
+{
+    // DUMMY FUNCTION
+}
+
+PhysicsGenericConstraint::PhysicsGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+    : PhysicsConstraint(a, b), _rotationOffsetA(NULL), _rotationOffsetB(NULL),
+    _translationOffsetA(NULL), _translationOffsetB(NULL)
+{
+    if (b)
+    {
+        Vector3 origin = centerOfMassMidpoint(a->getNode(), b->getNode());
+        _constraint = new btGeneric6DofConstraint(*a->_body, *b->_body, getTransformOffset(a->getNode(), origin), getTransformOffset(b->getNode(), origin), true);
+    }
+    else
+    {
+        _constraint = new btGeneric6DofConstraint(*a->_body, btTransform::getIdentity(), true);
+    }
+}
+
+PhysicsGenericConstraint::PhysicsGenericConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+    : PhysicsConstraint(a, b), _rotationOffsetA(NULL), _rotationOffsetB(NULL), _translationOffsetA(NULL), _translationOffsetB(NULL)
+{
+    // Take scale into account for the first node's translation offset.
+    Vector3 sA;
+    a->getNode()->getWorldMatrix().getScale(&sA);
+    Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
+
+    if (b)
+    {
+        // Take scale into account for the second node's translation offset.
+        Vector3 sB;
+        b->getNode()->getWorldMatrix().getScale(&sB);
+        Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
+
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), btVector3(tA.x, tA.y, tA.z));
+        btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), btVector3(tB.x, tB.y, tB.z));
+        _constraint = new btGeneric6DofConstraint(*a->_body, *b->_body, frameInA, frameInB, true);
+    }
+    else
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), btVector3(tA.x, tA.y, tA.z));
+        _constraint = new btGeneric6DofConstraint(*a->_body, frameInA, true);
+    }
+}
+
+PhysicsGenericConstraint::~PhysicsGenericConstraint()
+{
+    SAFE_DELETE(_rotationOffsetA);
+    SAFE_DELETE(_rotationOffsetB);
+    SAFE_DELETE(_translationOffsetA);
+    SAFE_DELETE(_translationOffsetB);
+}
+
+}

+ 167 - 0
gameplay/src/PhysicsGenericConstraint.h

@@ -0,0 +1,167 @@
+/*
+ * PhysicsGenericConstraint.h
+ */
+
+#ifndef PHYSICSGENERICCONSTRAINT_H_
+#define PHYSICSGENERICCONSTRAINT_H_
+
+#include "PhysicsConstraint.h"
+#include "Quaternion.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+    class PhysicsRigidBody;
+
+/**
+ * Represents a completely generic constraint between two
+ * rigid bodies (or one rigid body and the world) where the
+ * limits for all six degrees of freedom can be set individually.
+ */
+class PhysicsGenericConstraint : public PhysicsConstraint
+{
+    friend class PhysicsController;
+
+public:
+    /**
+     * Gets the rotation offset for the first rigid body in the constraint.
+     * 
+     * @return The rotation offset.
+     */
+    inline const Quaternion& getRotationOffsetA() const;
+
+    /**
+     * Gets the rotation offset for the second rigid body in the constraint.
+     * 
+     * @return The rotation offset.
+     */
+    inline const Quaternion& getRotationOffsetB() const;
+
+    /**
+     * Gets the translation offset for the first rigid body in the constraint.
+     * 
+     * @return The translation offset.
+     */
+    inline const Vector3& getTranslationOffsetA() const;
+
+    /**
+     * Gets the translation offset for the second rigid body in the constraint.
+     * 
+     * @return The translation offset.
+     */
+    inline const Vector3& getTranslationOffsetB() const;
+
+    /**
+     * Sets the lower angular limits (as Euler angle limits) along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The lower angular limits (as Euler angle limits) along the local X, Y, and Z axes.
+     */
+    inline void setAngularLowerLimit(const Vector3& limits);
+
+    /**
+     * Sets the upper angular limits (as Euler angle limits) along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The upper angular limits (as Euler angle limits) along the local X, Y, and Z axes.
+     */
+    inline void setAngularUpperLimit(const Vector3& limits);
+    
+    /**
+     * Sets the lower linear limits along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The lower linear limits along the local X, Y, and Z axes.
+     */
+    inline void setLinearLowerLimit(const Vector3& limits);
+    
+    /**
+     * Sets the upper linear limits along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The upper linear limits along the local X, Y, and Z axes.
+     */
+    inline void setLinearUpperLimit(const Vector3& limits);
+
+    /**
+     * Sets the rotation offset for the first rigid body in the constraint.
+     * 
+     * @param rotationOffset The rotation offset.
+     */
+    inline void setRotationOffsetA(const Quaternion& rotationOffset);
+
+    /**
+     * Sets the rotation offset for the second rigid body in the constraint.
+     * 
+     * @param rotationOffset The rotation offset.
+     */
+    inline void setRotationOffsetB(const Quaternion& rotationOffset);
+
+    /**
+     * Sets the translation offset for the first rigid body in the constraint.
+     * 
+     * @param translationOffset The translation offset.
+     */
+    inline void setTranslationOffsetA(const Vector3& translationOffset);
+
+    /**
+     * Sets the translation offset for the second rigid body in the constraint.
+     * 
+     * @param translationOffset The translation offset.
+     */
+    inline void setTranslationOffsetB(const Vector3& translationOffset);
+
+protected:
+    /**
+     * Constructor.
+     *
+     * Note: This should only used by subclasses that do not want
+     * the _constraint member variable to be initialized.
+     */
+    PhysicsGenericConstraint();
+
+    /**
+     * Creates a generic constraint so that the rigid body (or bodies) is
+     * (are) constrained to its (their) current world position(s).
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Creates a generic constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @param translationOffsetB The translation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     */
+    PhysicsGenericConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+        PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
+
+    /**
+     * Destructor.
+     */
+    virtual ~PhysicsGenericConstraint();
+
+private:
+    mutable Quaternion* _rotationOffsetA;
+    mutable Quaternion* _rotationOffsetB;
+    mutable Vector3* _translationOffsetA;
+    mutable Vector3* _translationOffsetB;
+};
+
+}
+
+#include "PhysicsGenericConstraint.inl"
+
+#endif

+ 90 - 0
gameplay/src/PhysicsGenericConstraint.inl

@@ -0,0 +1,90 @@
+/**
+ * PhysicsGenericConstraint.inl
+ */
+
+#include "PhysicsGenericConstraint.h"
+
+namespace gameplay
+{
+
+inline const Quaternion& PhysicsGenericConstraint::getRotationOffsetA() const
+{
+    if (!_rotationOffsetA)
+        _rotationOffsetA = new Quaternion();
+
+    btQuaternion ro = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().getRotation();
+    _rotationOffsetA->set(ro.x(), ro.y(), ro.z(), ro.w());
+    return *_rotationOffsetA;
+}
+
+inline const Quaternion& PhysicsGenericConstraint::getRotationOffsetB() const
+{
+    if (!_rotationOffsetB)
+        _rotationOffsetB = new Quaternion();
+
+    btQuaternion ro = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().getRotation();
+    _rotationOffsetB->set(ro.x(), ro.y(), ro.z(), ro.w());
+    return *_rotationOffsetB;
+}
+
+inline const Vector3& PhysicsGenericConstraint::getTranslationOffsetA() const
+{
+    if (!_translationOffsetA)
+        _translationOffsetA = new Vector3();
+
+    btVector3 to = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().getOrigin();
+    _translationOffsetA->set(to.x(), to.y(), to.z());
+    return *_translationOffsetA;
+}
+
+inline const Vector3& PhysicsGenericConstraint::getTranslationOffsetB() const
+{
+    if (!_translationOffsetB)
+        _translationOffsetB = new Vector3();
+
+    btVector3 to = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().getOrigin();
+    _translationOffsetB->set(to.x(), to.y(), to.z());
+    return *_translationOffsetB;
+}
+
+inline void PhysicsGenericConstraint::setAngularLowerLimit(const Vector3& limits)
+{
+    ((btGeneric6DofConstraint*)_constraint)->setAngularLowerLimit(btVector3(limits.x, limits.y, limits.z));
+}
+
+inline void PhysicsGenericConstraint::setAngularUpperLimit(const Vector3& limits)
+{
+    ((btGeneric6DofConstraint*)_constraint)->setAngularUpperLimit(btVector3(limits.x, limits.y, limits.z));
+}
+
+inline void PhysicsGenericConstraint::setLinearLowerLimit(const Vector3& limits)
+{
+    ((btGeneric6DofConstraint*)_constraint)->setLinearLowerLimit(btVector3(limits.x, limits.y, limits.z));
+}
+    
+inline void PhysicsGenericConstraint::setLinearUpperLimit(const Vector3& limits)
+{
+    ((btGeneric6DofConstraint*)_constraint)->setLinearUpperLimit(btVector3(limits.x, limits.y, limits.z));
+}
+
+inline void PhysicsGenericConstraint::setRotationOffsetA(const Quaternion& rotationOffset)
+{
+    static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().setRotation(btQuaternion(rotationOffset.x, rotationOffset.y, rotationOffset.z, rotationOffset.w));
+}
+
+inline void PhysicsGenericConstraint::setRotationOffsetB(const Quaternion& rotationOffset)
+{
+    static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().setRotation(btQuaternion(rotationOffset.x, rotationOffset.y, rotationOffset.z, rotationOffset.w));
+}
+
+inline void PhysicsGenericConstraint::setTranslationOffsetA(const Vector3& translationOffset)
+{
+    static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().setOrigin(btVector3(translationOffset.x, translationOffset.y, translationOffset.z));
+}
+
+inline void PhysicsGenericConstraint::setTranslationOffsetB(const Vector3& translationOffset)
+{
+    static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().setOrigin(btVector3(translationOffset.x, translationOffset.y, translationOffset.z));
+}
+
+}

+ 51 - 0
gameplay/src/PhysicsHingeConstraint.cpp

@@ -0,0 +1,51 @@
+/*
+ * PhysicsHingeConstraint.cpp
+ */
+
+#include "PhysicsHingeConstraint.h"
+
+#include "Node.h"
+
+namespace gameplay
+{
+
+void PhysicsHingeConstraint::setLimits(float minAngle, float maxAngle, float bounciness)
+{
+    // Use the defaults for softness (0.9) and biasFactor (0.3).
+    ((btHingeConstraint*)_constraint)->setLimit(minAngle, maxAngle, 0.9f, 0.3f, bounciness);
+}
+
+PhysicsHingeConstraint::PhysicsHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+    : PhysicsConstraint(a, b)
+{
+    // Take scale into account for the first node's translation offset.
+    Vector3 sA;
+    a->getNode()->getWorldMatrix().getScale(&sA);
+    Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
+
+    if (b)
+    {
+        // Take scale into account for the second node's translation offset.
+        Vector3 sB;
+        b->getNode()->getWorldMatrix().getScale(&sB);
+        Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
+
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), btVector3(tA.x, tA.y, tA.z));
+        btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), btVector3(tB.x, tB.y, tB.z));
+        _constraint = new btHingeConstraint(*a->_body, *b->_body, frameInA, frameInB);
+    }
+    else
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), btVector3(tA.x, tA.y, tA.z));
+        _constraint = new btHingeConstraint(*a->_body, frameInA);
+    }
+}
+
+    
+PhysicsHingeConstraint::~PhysicsHingeConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+}

+ 66 - 0
gameplay/src/PhysicsHingeConstraint.h

@@ -0,0 +1,66 @@
+/*
+ * PhysicsHingeConstraint.h
+ */
+
+#ifndef PHYSICSHINGECONSTRAINT_H_
+#define PHYSICSHINGECONSTRAINT_H_
+
+#include "PhysicsConstraint.h"
+#include "PhysicsRigidBody.h"
+#include "Quaternion.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+
+/**
+ * Represents a hinge constraint between two rigid bodies
+ * (or one rigid body and the world) where movement is
+ * restricted to rotation about one axis.
+ */
+class PhysicsHingeConstraint : public PhysicsConstraint
+{
+    friend class PhysicsController;
+
+public:
+    /**
+     * Sets the limits (and optionally, some properties) for the hinge.
+     * 
+     * @param minAngle The minimum angle for the hinge.
+     * @param maxAngle The maximum angle for the hinge.
+     * @param bounciness The bounciness of the hinge (this is applied as
+     *      a factor to the incoming velocity when a hinge limit is met in
+     *      order to calculate the outgoing velocity-for example, 0.0 corresponds
+     *      to no bounce and 1.0 corresponds to an outgoing velocity that is equal
+     *      in magnitude to the incoming velocity).
+     */
+    void setLimits(float minAngle, float maxAngle, float bounciness = 1.0f);
+
+private:
+    /**
+     * Creates a hinge constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @param translationOffsetB The translation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     */
+    PhysicsHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+        PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsHingeConstraint();
+};
+
+}
+
+#endif

+ 71 - 0
gameplay/src/PhysicsMotionState.cpp

@@ -0,0 +1,71 @@
+/**
+ * PhysicsMotionState.cpp
+ */
+
+#include "PhysicsMotionState.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(btVector3(centerOfMassOffset->x, centerOfMassOffset->y, centerOfMassOffset->z));
+    }
+
+    updateTransformFromNode();
+}
+
+PhysicsMotionState::~PhysicsMotionState()
+{
+}
+
+void PhysicsMotionState::getWorldTransform(btTransform &transform) const
+{
+    if (_node->getPhysicsRigidBody() && _node->getPhysicsRigidBody()->isKinematic())
+        updateTransformFromNode();
+
+    transform = _centerOfMassOffset.inverse() * _worldTransform;
+}
+
+void PhysicsMotionState::setWorldTransform(const btTransform &transform)
+{
+    _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
+{
+    // 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.
+        btQuaternion orientation(rotation.x, rotation.y, rotation.z, rotation.w);
+        btTransform offset = btTransform(orientation, 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(orientation, origin);
+    }
+    else
+    {
+        _worldTransform = btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w), 
+            btVector3(m.m[12], m.m[13], m.m[14]));
+    }
+}
+
+}

+ 59 - 0
gameplay/src/PhysicsMotionState.h

@@ -0,0 +1,59 @@
+/*
+ * PhysicsMotionState.h
+ */
+
+#ifndef PHYSICSMOTIONSTATE_H_
+#define PHYSICSMOTIONSTATE_H_
+
+#include "Node.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+/**
+ * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
+ * 
+ * @see btMotionState
+ */
+class PhysicsMotionState : public btMotionState
+{
+    friend class PhysicsRigidBody;
+    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

+ 258 - 0
gameplay/src/PhysicsRigidBody.cpp

@@ -0,0 +1,258 @@
+/*
+ * PhysicsRigidBody.cpp
+ */
+
+#include "Base.h"
+#include "Game.h"
+#include "PhysicsController.h"
+#include "PhysicsMotionState.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+const int PhysicsRigidBody::Listener::DIRTY = 0x01;
+const int PhysicsRigidBody::Listener::COLLISION = 0x02;
+const int PhysicsRigidBody::Listener::REGISTERED = 0x04;
+
+PhysicsRigidBody::PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, float mass, 
+        float friction, float restitution, float linearDamping, float angularDamping)
+        : _shape(NULL), _body(NULL), _node(node), _listeners(NULL), _angularVelocity(NULL),
+        _anisotropicFriction(NULL), _gravity(NULL), _linearVelocity(NULL)
+{
+    switch (type)
+    {
+        case PhysicsRigidBody::SHAPE_BOX:
+        {
+            const BoundingBox& box = node->getModel()->getMesh()->getBoundingBox();
+
+            PhysicsController* physics = Game::getInstance()->getPhysicsController();
+            _shape = physics->getBox(box.min, box.max, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+            
+            // Use the center of the bounding box as the center of mass offset.
+            Vector3 c(box.min, box.max);
+            c.scale(0.5f);
+            c.add(box.min);
+            c.negate();
+
+            if (c.lengthSquared() > MATH_EPSILON)
+                _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping, &c);
+            else
+                _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
+
+            break;
+        }
+        case PhysicsRigidBody::SHAPE_SPHERE:
+        {
+            const BoundingSphere& sphere = node->getModel()->getMesh()->getBoundingSphere();
+
+            PhysicsController* physics = Game::getInstance()->getPhysicsController();
+            _shape = physics->getSphere(sphere.radius, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+
+            // Use the center of the bounding sphere as the center of mass offset.
+            Vector3 c(sphere.center);
+            c.negate();
+
+            if (c.lengthSquared() > MATH_EPSILON)
+                _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping, &c);
+            else
+                _body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
+
+            break;
+        }
+    }
+
+    // Add the rigid body to the physics world.
+    Game::getInstance()->getPhysicsController()->addRigidBody(this);
+}
+
+PhysicsRigidBody::~PhysicsRigidBody()
+{
+    // Clean up all constraints linked to this rigid body.
+    PhysicsConstraint* ptr = NULL;
+    while (_constraints.size() > 0)
+    {
+        ptr = _constraints.back();
+        _constraints.pop_back();
+        SAFE_DELETE(ptr);
+    }
+
+    // Clean up the rigid body and its related objects.
+    if (_body)
+    {
+        if (_body->getMotionState())
+            delete _body->getMotionState();
+
+        if (_shape)
+            BULLET_DELETE(_shape);
+
+        Game::getInstance()->getPhysicsController()->removeRigidBody(this);
+        BULLET_DELETE(_body);
+    }
+
+    SAFE_DELETE(_listeners);
+    SAFE_DELETE(_angularVelocity);
+    SAFE_DELETE(_anisotropicFriction);
+    SAFE_DELETE(_gravity);
+    SAFE_DELETE(_linearVelocity);
+}
+
+void PhysicsRigidBody::addCollisionListener(Listener* listener, PhysicsRigidBody* body)
+{
+    if (!_listeners)
+        _listeners = new std::vector<Listener*>();
+
+    CollisionPair pair(this, body);
+    listener->_collisionStatus[pair] = PhysicsRigidBody::Listener::REGISTERED;
+
+    _listeners->push_back(listener);
+}
+
+void PhysicsRigidBody::applyForce(const Vector3& force, const Vector3* relativePosition)
+{
+    // If the force is significant enough, activate the rigid body 
+    // to make sure that it isn't sleeping and apply the force.
+    if (force.lengthSquared() > MATH_EPSILON)
+    {
+        _body->activate();
+        if (relativePosition)
+            _body->applyForce(btVector3(force.x, force.y, force.z), btVector3(relativePosition->x, relativePosition->y, relativePosition->z));
+        else
+            _body->applyCentralForce(btVector3(force.x, force.y, force.z));
+    }
+}
+
+void PhysicsRigidBody::applyImpulse(const Vector3& impulse, const Vector3* relativePosition)
+{
+    // If the impulse is significant enough, activate the rigid body 
+    // to make sure that it isn't sleeping and apply the impulse.
+    if (impulse.lengthSquared() > MATH_EPSILON)
+    {
+        _body->activate();
+
+        if (relativePosition)
+        {
+            _body->applyImpulse(btVector3(impulse.x, impulse.y, impulse.z), btVector3(relativePosition->x, relativePosition->y, relativePosition->z));
+        }
+        else
+            _body->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
+    }
+}
+
+void PhysicsRigidBody::applyTorque(const Vector3& torque)
+{
+    // If the torque is significant enough, activate the rigid body 
+    // to make sure that it isn't sleeping and apply the torque.
+    if (torque.lengthSquared() > MATH_EPSILON)
+    {
+        _body->activate();
+        _body->applyTorque(btVector3(torque.x, torque.y, torque.z));
+    }
+}
+
+void PhysicsRigidBody::applyTorqueImpulse(const Vector3& torque)
+{
+    // If the torque impulse is significant enough, activate the rigid body 
+    // to make sure that it isn't sleeping and apply the torque impulse.
+    if (torque.lengthSquared() > MATH_EPSILON)
+    {
+        _body->activate();
+        _body->applyTorqueImpulse(btVector3(torque.x, torque.y, torque.z));
+    }
+}
+
+bool PhysicsRigidBody::collidesWith(PhysicsRigidBody* body)
+{
+    static CollidesWithCallback callback;
+
+    callback.result = false;
+    Game::getInstance()->getPhysicsController()->_world->contactPairTest(_body, body->_body, callback);
+    return callback.result;
+}
+
+btRigidBody* PhysicsRigidBody::createBulletRigidBody(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
+    // and we need to calculate the local inertia.
+    btVector3 localInertia(0.0, 0.0, 0.0);
+    if (mass != 0.0)
+        shape->calculateLocalInertia(mass, localInertia);
+
+    // Create the Bullet physics rigid body object.
+    PhysicsMotionState* motionState = new PhysicsMotionState(node, centerOfMassOffset);
+    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, shape, localInertia);
+    rbInfo.m_friction = friction;
+    rbInfo.m_restitution = restitution;
+    rbInfo.m_linearDamping = linearDamping;
+    rbInfo.m_angularDamping = angularDamping;
+    BULLET_NEW(btRigidBody, body, rbInfo);
+
+    return body;
+}
+
+void PhysicsRigidBody::addConstraint(PhysicsConstraint* constraint)
+{
+    _constraints.push_back(constraint);
+}
+
+void PhysicsRigidBody::removeConstraint(PhysicsConstraint* constraint)
+{
+    for (unsigned int i = 0; i < _constraints.size(); i++)
+    {
+        if (_constraints[i] == constraint)
+        {
+            _constraints.erase(_constraints.begin() + i);
+            break;
+        }
+    }
+}
+
+PhysicsRigidBody::CollisionPair::CollisionPair(PhysicsRigidBody* rbA, PhysicsRigidBody* rbB)
+    : _rbA(rbA), _rbB(rbB)
+{
+    // DUMMY FUNCTION
+}
+
+PhysicsRigidBody::Listener::~Listener()
+{
+    // DUMMY FUNCTION
+}
+
+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);
+    
+    // If the given rigid body pair has collided in the past, then
+    // we notify the listener only if the pair was not colliding
+    // during the previous frame. Otherwise, it's a new pair, so notify the listener.
+    CollisionPair pair(rbA, rbB);
+    if (_collisionStatus.count(pair) > 0)
+    {
+        if ((_collisionStatus[pair] & COLLISION) == 0)
+            collisionEvent(pair, Vector3(cp.getPositionWorldOnA().x(), cp.getPositionWorldOnA().y(), cp.getPositionWorldOnA().z()));
+    }
+    else
+    {
+        collisionEvent(pair, Vector3(cp.getPositionWorldOnA().x(), cp.getPositionWorldOnA().y(), cp.getPositionWorldOnA().z()));
+    }
+
+    // Update the collision status cache (we remove the dirty bit
+    // set in the controller's update so that this particular collision pair's
+    // status is not reset to 'no collision' when the controller's update completes).
+    _collisionStatus[pair] &= ~DIRTY;
+    _collisionStatus[pair] |= COLLISION;
+    return 0.0f;
+}
+
+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;
+}
+
+}

+ 348 - 0
gameplay/src/PhysicsRigidBody.h

@@ -0,0 +1,348 @@
+/*
+ * PhysicsRigidBody.h
+ */
+
+#ifndef PHYSICSRIGIDBODY_H_
+#define PHYSICSRIGIDBODY_H_
+
+#include "Mesh.h"
+#include "PhysicsConstraint.h"
+#include "Transform.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+
+class Node;
+class PhysicsConstraint;
+
+/**
+ * Defines a class for physics rigid bodies.
+ */
+class PhysicsRigidBody
+{
+    friend class Node;
+    friend class PhysicsConstraint;
+    friend class PhysicsController;
+    friend class PhysicsFixedConstraint;
+    friend class PhysicsGenericConstraint;
+    friend class PhysicsHingeConstraint;
+    friend class PhysicsSocketConstraint;
+    friend class PhysicsSpringConstraint;
+
+public:
+    /**
+     * Represents the different types of rigid bodies.
+     */
+    enum Type
+    {
+        SHAPE_BOX,
+        SHAPE_SPHERE,
+        SHAPE_NONE
+    };
+
+    /** 
+     * Defines a pair of rigid bodies that collided (or may collide).
+     */
+    class CollisionPair
+    {
+    public:
+        /**
+         * Constructor.
+         */
+        CollisionPair(PhysicsRigidBody* rbA, PhysicsRigidBody* rbB);
+
+        /**
+         * Less than operator (needed for use as a key in std::map).
+         * 
+         * @param cp The collision pair to compare.
+         * @return True if this pair is "less than" the given pair; false otherwise.
+         */
+        bool operator<(const CollisionPair& cp) const;
+
+        /** The first rigid body in the collision. */
+        PhysicsRigidBody* _rbA;
+
+        /** The second rigid body in the collision. */
+        PhysicsRigidBody* _rbB;
+    };
+
+    /**
+     * Collision listener interface.
+     */
+    class Listener : public btCollisionWorld::ContactResultCallback
+    {
+        friend class PhysicsRigidBody;
+        friend class PhysicsController;
+
+    public:
+        /**
+         * Destructor.
+         */
+        virtual ~Listener();
+
+        /**
+         * Handles when a collision occurs for the rigid body where this listener is registered.
+         * 
+         * @param collisionPair The two rigid bodies involved in the collision.
+         * @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. */
+        std::map<CollisionPair, int> _collisionStatus;
+
+    private:
+        // Internal constant.
+        static const int DIRTY;
+        // Internal constant.
+        static const int COLLISION;
+        // Internal constant.
+        static const int REGISTERED;
+    };
+
+    /**
+     * Adds a collision listener for this rigid body.
+     * 
+     * @param listener The listener to add.
+     * @param body Specifies that only collisions with the given rigid body should trigger a notification.
+     */
+    void addCollisionListener(Listener* listener, PhysicsRigidBody* body = NULL);
+
+    /**
+     * Applies the given force to the rigid body (optionally, from the given relative position).
+     * 
+     * @param force The force to be applied.
+     * @param relativePosition The relative position from which to apply the force.
+     */
+    void applyForce(const Vector3& force, const Vector3* relativePosition = NULL);
+
+    /**
+     * Applies the given force impulse to the rigid body (optionally, from the given relative position).
+     * 
+     * @param impulse The force impulse to be applied.
+     * @param relativePosition The relative position from which to apply the force.
+     */
+    void applyImpulse(const Vector3& impulse, const Vector3* relativePosition = NULL);
+
+    /**
+     * Applies the given torque to the rigid body.
+     * 
+     * @param torque The torque to be applied.
+     */
+    void applyTorque(const Vector3& torque);
+
+    /**
+     * Applies the given torque impulse to the rigid body.
+     * 
+     * @param torque The torque impulse to be applied.
+     */
+    void applyTorqueImpulse(const Vector3& torque);
+    
+    /**
+     * Checks if this rigid body collides with the given rigid body.
+     * 
+     * @param body The rigid body to test collision with.
+     * @return True if this rigid body collides with the given rigid body; false otherwise.
+     */
+    bool collidesWith(PhysicsRigidBody* body);
+
+    /**
+     * Gets the rigid body's angular damping.
+     * 
+     * @return The angular damping.
+     */
+    inline float getAngularDamping() const;
+
+    /**
+     * Gets the rigid body's angular velocity.
+     * 
+     * @return The angular velocity.
+     */
+    inline const Vector3& getAngularVelocity() const;
+
+    /**
+     * Gets the rigid body's anisotropic friction.
+     * 
+     * @return The anisotropic friction.
+     */
+    inline const Vector3& getAnisotropicFriction() const;
+
+    /**
+     * Gets the rigid body's friction.
+     * 
+     * @return The friction.
+     */
+    inline float getFriction() const;
+
+    /**
+     * Gets the gravity that affects the rigid body (this can
+     * be different from the global gravity; @see #setGravity).
+     * 
+     * @return The gravity.
+     */
+    inline const Vector3& getGravity() const;
+
+    /**
+     * Gets the rigid body's linear damping.
+     * 
+     * @return The linear damping.
+     */
+    inline float getLinearDamping() const;
+
+    /**
+     * Gets the rigid body's linear velocity.
+     * 
+     * @return The linear velocity.
+     */
+    inline const Vector3& getLinearVelocity() const;
+
+    /**
+     * Gets the node that the rigid body is attached to.
+     * 
+     * @return The node.
+     */
+    inline const Node* getNode() const;
+
+    /**
+     * Gets the rigid body's restitution.
+     * 
+     * @return The restitution.
+     */
+    inline float getRestitution() const;
+
+    /**
+     * Gets whether the rigid body is a kinematic rigid body or not.
+     * 
+     * @return Whether the rigid body is kinematic or not.
+     */
+    inline bool isKinematic() const;
+
+    /**
+     * Sets the rigid body's angular velocity.
+     * 
+     * @param velocity The angular velocity.
+     */
+    inline void setAngularVelocity(const Vector3& velocity);
+
+    /**
+     * Sets the rigid body's anisotropic friction.
+     * 
+     * @param friction The anisotropic friction.
+     */
+    inline void setAnisotropicFriction(const Vector3& friction);
+
+    /**
+     * Sets the rigid body's linear and angular damping.
+     * 
+     * @param linearDamping The linear damping; between 0.0 (minimum) and 1.0 (maximum).
+     * @param angularDamping The angular damping; between 0.0 (minimum) and 1.0 (maximum).
+     */
+    inline void setDamping(float linearDamping, float angularDamping);
+
+    /**
+     * Sets the rigid body's friction.
+     * 
+     * @param friction The friction.
+     */
+    inline void setFriction(float friction);
+
+    /**
+     * Sets the rigid body's gravity (this overrides the global gravity for this rigid body).
+     * 
+     * @param gravity The gravity.
+     */
+    inline void setGravity(const Vector3& gravity);
+
+    /**
+     * Sets whether the rigid body is a kinematic rigid body or not.
+     * 
+     * @param kinematic Whether the rigid body is kinematic or not.
+     */
+    inline void setKinematic(bool kinematic);
+
+    /**
+     * Sets the rigid body's linear velocity.
+     * 
+     * @param velocity The linear velocity.
+     */
+    inline void setLinearVelocity(const Vector3& velocity);
+
+    /**
+     * Sets the rigid body's restitution (or bounciness).
+     * 
+     * @param restitution The restitution.
+     */
+    inline void setRestitution(float restitution);
+
+private:
+    /**
+     * Creates a rigid body.
+     * 
+     * @param node The node to create a rigid body for; note that the node must have
+     *      a model attached to it prior to creating a rigid body for it.
+     * @param type The type of rigid body to set.
+     * @param mass The mass of the rigid body, in kilograms.
+     * @param friction The friction of the rigid body (non-zero values give best simulation results).
+     * @param restitution The restitution of the rigid body (this controls the bounciness of
+     *      the rigid body; use zero for best simulation results).
+     * @param linearDamping The percentage of linear velocity lost per second (between 0.0 and 1.0).
+     * @param angularDamping The percentage of angular velocity lost per second (between 0.0 and 1.0).
+     */
+    PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, float mass, float friction = 0.5,
+        float restitution = 0.0, float linearDamping = 0.0, float angularDamping = 0.0);
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsRigidBody();
+
+    /**
+     * Private copy constructor to disallow copying.
+     */
+    PhysicsRigidBody(const PhysicsRigidBody& body);
+
+    // 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);
+
+    // Adds a constraint to this rigid body.
+    void addConstraint(PhysicsConstraint* constraint);
+
+    // Removes a constraint from this rigid body (used by the constraint destructor).
+    void removeConstraint(PhysicsConstraint* constraint);
+
+    // Internal class used to implement the collidesWith(PhysicsRigidBody*) function.
+    struct CollidesWithCallback : public btCollisionWorld::ContactResultCallback
+    {
+        btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* a, int partIdA,
+            int indexA, const btCollisionObject* b, int partIdB, int indexB);
+
+        bool result;
+    };
+
+    btCollisionShape* _shape;
+    btRigidBody* _body;
+    Node* _node;
+    std::vector<PhysicsConstraint*> _constraints;
+    std::vector<Listener*>* _listeners;
+    mutable Vector3* _angularVelocity;
+    mutable Vector3* _anisotropicFriction;
+    mutable Vector3* _gravity;
+    mutable Vector3* _linearVelocity;
+};
+
+}
+
+#include "PhysicsRigidBody.inl"
+
+#endif

+ 146 - 0
gameplay/src/PhysicsRigidBody.inl

@@ -0,0 +1,146 @@
+/**
+ * PhysicsRigidBody.inl
+ */
+
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+inline float PhysicsRigidBody::getAngularDamping() const
+{
+    return _body->getAngularDamping();
+}
+
+inline const Vector3& PhysicsRigidBody::getAngularVelocity() const
+{
+    if (!_angularVelocity)
+        _angularVelocity = new Vector3();
+
+    const btVector3& v = _body->getAngularVelocity();
+    _angularVelocity->set(v.x(), v.y(), v.z());
+    return *_angularVelocity;
+}
+
+inline const Vector3& PhysicsRigidBody::getAnisotropicFriction() const
+{
+    if (!_anisotropicFriction)
+        _anisotropicFriction = new Vector3();
+
+    const btVector3& af = _body->getAnisotropicFriction();
+    _anisotropicFriction->set(af.x(), af.y(), af.z());
+    return *_anisotropicFriction;
+}
+
+inline float PhysicsRigidBody::getFriction() const
+{
+    return _body->getFriction();
+}
+
+inline const Vector3& PhysicsRigidBody::getGravity() const
+{
+    if (!_gravity)
+        _gravity = new Vector3();
+
+    const btVector3& g = _body->getGravity();
+    _gravity->set(g.x(), g.y(), g.z());
+    return *_gravity;
+}
+
+inline float PhysicsRigidBody::getLinearDamping() const
+{
+    return _body->getLinearDamping();
+}
+
+inline const Vector3& PhysicsRigidBody::getLinearVelocity() const
+{
+    if (!_linearVelocity)
+        _linearVelocity = new Vector3();
+
+    const btVector3& v = _body->getLinearVelocity();
+    _linearVelocity->set(v.x(), v.y(), v.z());
+    return *_linearVelocity;
+}
+
+inline const Node* PhysicsRigidBody::getNode() const
+{
+    return _node;
+}
+
+inline float PhysicsRigidBody::getRestitution() const
+{
+    return _body->getRestitution();
+}
+
+inline bool PhysicsRigidBody::isKinematic() const
+{
+    return (_body->getCollisionFlags() & btCollisionObject::CF_KINEMATIC_OBJECT) != 0;
+}
+
+inline void PhysicsRigidBody::setAngularVelocity(const Vector3& velocity)
+{
+    _body->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z));
+}
+
+inline void PhysicsRigidBody::setAnisotropicFriction(const Vector3& friction)
+{
+    _body->setAnisotropicFriction(btVector3(friction.x, friction.y, friction.z));
+}
+
+inline void PhysicsRigidBody::setDamping(float linearDamping, float angularDamping)
+{
+    _body->setDamping(linearDamping, angularDamping);
+}
+
+inline void PhysicsRigidBody::setFriction(float friction)
+{
+    _body->setFriction(friction);
+}
+
+inline void PhysicsRigidBody::setGravity(const Vector3& gravity)
+{
+    _body->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
+}
+
+inline void PhysicsRigidBody::setKinematic(bool kinematic)
+{
+    if (kinematic)
+    {
+        _body->setCollisionFlags(_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+        _body->setActivationState(DISABLE_DEACTIVATION);
+    }
+    else
+    {
+        _body->setCollisionFlags(_body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
+        _body->setActivationState(ACTIVE_TAG);
+    }
+}
+
+inline void PhysicsRigidBody::setLinearVelocity(const Vector3& velocity)
+{
+    _body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
+}
+
+inline void PhysicsRigidBody::setRestitution(float restitution)
+{
+    _body->setRestitution(restitution);
+}
+
+inline bool PhysicsRigidBody::CollisionPair::operator<(const CollisionPair& cp) const
+{
+    // If the pairs are equal, then return false.
+    if ((_rbA == cp._rbA && _rbB == cp._rbB) || (_rbA == cp._rbB && _rbB == cp._rbA))
+        return false;
+    else
+    {
+        // We choose to compare based on _rbA arbitrarily.
+        if (_rbA < cp._rbA)
+            return true;
+        else if (_rbA == cp._rbA)
+            return _rbB < cp._rbB;
+        else
+            return false;
+    }
+}
+
+}

+ 58 - 0
gameplay/src/PhysicsSocketConstraint.cpp

@@ -0,0 +1,58 @@
+/**
+ * PhysicsSocketConstraint.cpp
+ */
+
+#include "PhysicsSocketConstraint.h"
+
+#include "Node.h"
+
+namespace gameplay
+{
+
+PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+    : PhysicsConstraint(a, b)
+{
+    if (b)
+    {
+        Vector3 origin = centerOfMassMidpoint(a->getNode(), b->getNode());
+        btTransform frameInA = getTransformOffset(a->getNode(), origin);
+        btTransform frameInB = getTransformOffset(b->getNode(), origin);
+
+        _constraint = new btPoint2PointConstraint(*a->_body, *b->_body, frameInA.getOrigin(), frameInB.getOrigin());
+    }
+    else
+    {
+        _constraint = new btPoint2PointConstraint(*a->_body, btVector3(0.0f, 0.0f, 0.0f));
+    }
+}
+
+PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, const Vector3& translationOffsetA, 
+    PhysicsRigidBody* b, const Vector3& translationOffsetB)
+    : PhysicsConstraint(a, b)
+{
+    // Take scale into account for the first node's translation offset.
+    Vector3 sA;
+    a->getNode()->getWorldMatrix().getScale(&sA);
+    Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
+
+    if (b)
+    {
+        // Take scale into account for the second node's translation offset.
+        Vector3 sB;
+        b->getNode()->getWorldMatrix().getScale(&sB);
+        Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
+
+        _constraint = new btPoint2PointConstraint(*a->_body, *b->_body, btVector3(tA.x, tA.y, tA.z), btVector3(tB.x, tB.y, tB.z));
+    }
+    else
+    {
+        _constraint = new btPoint2PointConstraint(*a->_body, btVector3(tA.x, tA.y, tA.z));
+    }
+}
+
+PhysicsSocketConstraint::~PhysicsSocketConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+}

+ 58 - 0
gameplay/src/PhysicsSocketConstraint.h

@@ -0,0 +1,58 @@
+/*
+ * PhysicsSocketConstraint.h
+ */
+
+#ifndef PHYSICSSOCKETCONSTRAINT_H_
+#define PHYSICSSOCKETCONSTRAINT_H_
+
+#include "PhysicsConstraint.h"
+#include "PhysicsRigidBody.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+
+/**
+ * Represents a ball-socket or point-to-point constraint
+ * between two rigid bodies (or one rigid body and the world)
+ * where rotation is unrestricted about the constraint joint (pivot point).
+ */
+class PhysicsSocketConstraint : public PhysicsConstraint
+{
+    friend class PhysicsController;
+
+private:
+    /**
+     * Creates a socket constraint so that the rigid body (or bodies) is
+     * (are) constrained using its (their) current world position(s) for
+     * the translation offset(s) to the constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Creates a socket constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param translationOffsetB The translation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     */
+    PhysicsSocketConstraint(PhysicsRigidBody* a, const Vector3& translationOffsetA, 
+        PhysicsRigidBody* b, const Vector3& translationOffsetB);
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsSocketConstraint();
+};
+
+}
+
+#endif

+ 67 - 0
gameplay/src/PhysicsSpringConstraint.cpp

@@ -0,0 +1,67 @@
+/**
+ * PhysicsSpringConstraint.cpp
+ */
+
+#include "PhysicsSpringConstraint.h"
+
+#include "Node.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsSpringConstraint::PhysicsSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    // Initialize the physics rigid body references since we don't call the PhysicsConstraint constructor that does it properly automatically.
+    _a = a;
+    _b = b;
+
+    Vector3 origin = centerOfMassMidpoint(a->getNode(), b->getNode());
+    _constraint = new btGeneric6DofSpringConstraint(*a->_body, *b->_body, getTransformOffset(a->getNode(), origin), getTransformOffset(b->getNode(), origin), true);
+}
+
+PhysicsSpringConstraint::PhysicsSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+{
+    // Initialize the physics rigid body references since we don't call the PhysicsConstraint constructor that does it properly automatically.
+    _a = a;
+    _b = b;
+
+    // Take scale into account for the translation offsets.
+    Vector3 sA;
+    a->getNode()->getWorldMatrix().getScale(&sA);
+    Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
+
+    Vector3 sB;
+    b->getNode()->getWorldMatrix().getScale(&sB);
+    Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
+
+    btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), btVector3(tA.x, tA.y, tA.z));
+    btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), btVector3(tB.x, tB.y, tB.z));
+    _constraint = new btGeneric6DofSpringConstraint(*a->_body, *b->_body, frameInA, frameInB, true);
+}
+
+PhysicsSpringConstraint::~PhysicsSpringConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+void PhysicsSpringConstraint::setStrength(SpringProperty property, float strength)
+{
+    if (strength < MATH_EPSILON)
+        ((btGeneric6DofSpringConstraint*)_constraint)->enableSpring(property, false);
+    else
+    {
+        ((btGeneric6DofSpringConstraint*)_constraint)->enableSpring(property, true);
+        ((btGeneric6DofSpringConstraint*)_constraint)->setStiffness(property, strength);
+        ((btGeneric6DofSpringConstraint*)_constraint)->setEquilibriumPoint(property);
+    }
+}
+
+void PhysicsSpringConstraint::setDamping(SpringProperty property, float damping)
+{
+    ((btGeneric6DofSpringConstraint*)_constraint)->setDamping(property, damping);
+    ((btGeneric6DofSpringConstraint*)_constraint)->setEquilibriumPoint(property);
+}
+
+}

+ 196 - 0
gameplay/src/PhysicsSpringConstraint.h

@@ -0,0 +1,196 @@
+/*
+ * PhysicsSpringConstraint.h
+ */
+
+#ifndef PHYSICSSPRINGCONSTRAINT_H_
+#define PHYSICSSPRINGCONSTRAINT_H_
+
+#include "PhysicsGenericConstraint.h"
+
+namespace gameplay
+{
+
+/**
+ * Represents a generic spring constraint between two
+ * rigid bodies (or one rigid body and the world)
+ * where the spring strength and damping can be set
+ * for all six degrees of freedom.
+ */
+class PhysicsSpringConstraint : public PhysicsGenericConstraint
+{
+    friend class PhysicsController;
+
+public:
+    /**
+     * Sets the angular damping along the constraint's local X axis.
+     * 
+     * @param damping The angular damping value.
+     */
+    inline void setAngularDampingX(float damping);
+
+    /**
+     * Sets the angular damping along the constraint's local Y axis.
+     * 
+     * @param damping The angular damping value.
+     */
+    inline void setAngularDampingY(float damping);
+
+    /**
+     * Sets the angular damping along the constraint's local Z axis.
+     * 
+     * @param damping The angular damping value.
+     */
+    inline void setAngularDampingZ(float damping);
+
+    /**
+     * Sets the angular strength along the constraint's local X axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for angular movement about the X axis (setting to zero disables it).
+     * 
+     * @param strength The angular strength value.
+     */
+    inline void setAngularStrengthX(float strength);
+
+    /**
+     * Sets the angular strength along the constraint's local Y axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for angular movement about the Y axis (setting to zero disables it).
+     * 
+     * @param strength The angular strength value.
+     */
+    inline void setAngularStrengthY(float strength);
+
+    /**
+     * Sets the angular strength along the constraint's local Z axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for angular movement about the Z axis (setting to zero disables it).
+     * 
+     * @param strength The angular strength value.
+     */
+    inline void setAngularStrengthZ(float strength);
+
+    /**
+     * Sets the linear damping along the constraint's local X axis.
+     * 
+     * @param damping The linear damping value.
+     */
+    inline void setLinearDampingX(float damping);
+
+    /**
+     * Sets the linear damping along the constraint's local Y axis.
+     * 
+     * @param damping The linear damping value.
+     */
+    inline void setLinearDampingY(float damping);
+
+    /**
+     * Sets the linear damping along the constraint's local Z axis.
+     * 
+     * @param damping The linear damping value.
+     */
+    inline void setLinearDampingZ(float damping);
+
+    /**
+     * Sets the linear strength along the constraint's local X axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for linear movement along the X axis (setting to zero disables it).
+     * 
+     * @param strength The linear strength value.
+     */
+    inline void setLinearStrengthX(float strength);
+
+    /**
+     * Sets the linear strength along the constraint's local Y axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for linear movement along the Y axis (setting to zero disables it).
+     * 
+     * @param strength The linear strength value.
+     */
+    inline void setLinearStrengthY(float strength);
+
+    /**
+     * Sets the linear strength along the constraint's local Z axis.
+     *
+     * Note: setting the strength to a non-zero value enables the
+     * spring for linear movement along the Z axis (setting to zero disables it).
+     * 
+     * @param strength The linear strength value.
+     */
+    inline void setLinearStrengthZ(float strength);
+
+private:
+    // Represents the different properties that
+    // can be set on the spring constraint.
+    // 
+    // (Note: the values map to the index parameter
+    // used in the member functions of the Bullet
+    // class btGeneric6DofSpringConstraint.)
+    enum SpringProperty
+    {
+        LINEAR_X = 0,
+        LINEAR_Y,
+        LINEAR_Z,
+        ANGULAR_X,
+        ANGULAR_Y,
+        ANGULAR_Z
+    };
+
+    /**
+     * Creates a spring constraint so that the rigid body (or bodies) is
+     * (are) constrained using its (their) current world position(s) for
+     * the translation offset(s) to the constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param b The second rigid body to constrain (optional).
+     */
+    PhysicsSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
+
+    /**
+     * Creates a spring constraint.
+     * 
+     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
+     *      body specified the constraint applies between it and the global physics world object.
+     * @param rotationOffsetA The rotation offset for the first rigid body 
+     *      (in its local space) with respect to the constraint joint.
+     * @param translationOffsetA The translation offset for the first rigid body
+     *      (in its local space) with respect to the constraint joint.
+     * @param b The second rigid body to constrain (optional).
+     * @param rotationOffsetB The rotation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     * @param translationOffsetB The translation offset for the second rigid body
+     *      (in its local space) with respect to the constraint joint (optional).
+     */
+    PhysicsSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+        PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
+
+    /**
+     * Destructor.
+     */
+    ~PhysicsSpringConstraint();
+
+    // Sets the strength for the given angular/linear 
+    // X/Y/Z axis combination determined by the given index.
+    // 
+    // See the Bullet class btGeneric6DofSpringConstraint
+    // for more information.
+    void setStrength(SpringProperty property, float strength);
+
+    // Sets the damping for the given angular/linear 
+    // X/Y/Z axis combination determined by the given index.
+    // 
+    // See the Bullet class btGeneric6DofSpringConstraint
+    // for more information.
+    void setDamping(SpringProperty property, float damping);
+};
+
+}
+
+#include "PhysicsSpringConstraint.inl"
+
+#endif

+ 70 - 0
gameplay/src/PhysicsSpringConstraint.inl

@@ -0,0 +1,70 @@
+/**
+ * PhysicsSpringConstraint.inl
+ */
+
+#include "PhysicsSpringConstraint.h"
+
+namespace gameplay
+{
+
+inline void PhysicsSpringConstraint::setAngularDampingX(float damping)
+{
+    setDamping(ANGULAR_X, damping);
+}
+
+inline void PhysicsSpringConstraint::setAngularDampingY(float damping)
+{
+    setDamping(ANGULAR_Y, damping);
+}
+
+inline void PhysicsSpringConstraint::setAngularDampingZ(float damping)
+{
+    setDamping(ANGULAR_Z, damping);
+}
+
+inline void PhysicsSpringConstraint::setAngularStrengthX(float strength)
+{
+    setStrength(ANGULAR_X, strength);
+}
+
+inline void PhysicsSpringConstraint::setAngularStrengthY(float strength)
+{
+    setStrength(ANGULAR_Y, strength);
+}
+
+inline void PhysicsSpringConstraint::setAngularStrengthZ(float strength)
+{
+    setStrength(ANGULAR_Z, strength);
+}
+
+inline void PhysicsSpringConstraint::setLinearDampingX(float damping)
+{
+    setDamping(LINEAR_X, damping);
+}
+
+inline void PhysicsSpringConstraint::setLinearDampingY(float damping)
+{
+    setDamping(LINEAR_Y, damping);
+}
+
+inline void PhysicsSpringConstraint::setLinearDampingZ(float damping)
+{
+    setDamping(LINEAR_Z, damping);
+}
+
+inline void PhysicsSpringConstraint::setLinearStrengthX(float strength)
+{
+    setStrength(LINEAR_X, strength);
+}
+
+inline void PhysicsSpringConstraint::setLinearStrengthY(float strength)
+{
+    setStrength(LINEAR_Y, strength);
+}
+
+inline void PhysicsSpringConstraint::setLinearStrengthZ(float strength)
+{
+    setStrength(LINEAR_Z, strength);
+}
+
+}

+ 4 - 0
gameplay/src/PlatformWin32.cpp

@@ -527,6 +527,10 @@ int Platform::enterMessagePump()
             _game->frame();
             SwapBuffers(__hdc);
         }
+
+        // If we are done, then exit.
+        if (_game->getState() == Game::UNINITIALIZED)
+            break;
     }
 
     return msg.wParam;

+ 2 - 2
gameplay/src/Technique.cpp

@@ -10,7 +10,7 @@ namespace gameplay
 {
 
 Technique::Technique(const char* id, Material* material)
-	: _id(id ? id : ""), _material(material)
+    : _id(id ? id : ""), _material(material)
 {
     assert(material);
 
@@ -23,7 +23,7 @@ Technique::Technique(const Technique& m)
 
 Technique::~Technique()
 {
-	// Destroy all the passes.
+    // Destroy all the passes.
     for (unsigned int i = 0, count = _passes.size(); i < count; ++i)
     {
         SAFE_RELEASE(_passes[i]);

+ 11 - 0
gameplay/src/gameplay.h

@@ -61,3 +61,14 @@
 #include "AnimationValue.h"
 #include "Animation.h"
 #include "AnimationClip.h"
+
+// Physics
+#include "PhysicsConstraint.h"
+#include "PhysicsController.h"
+#include "PhysicsFixedConstraint.h"
+#include "PhysicsGenericConstraint.h"
+#include "PhysicsHingeConstraint.h"
+#include "PhysicsMotionState.h"
+#include "PhysicsRigidBody.h"
+#include "PhysicsSocketConstraint.h"
+#include "PhysicsSpringConstraint.h"