Просмотр исходного кода

Merge branch 'physics-gold' of https://github.com/cculy/GamePlay into next-cculy

Conflicts:
	gameplay/src/MaterialParameter.cpp
Chris Culy 14 лет назад
Родитель
Сommit
9283fe222c
43 измененных файлов с 2459 добавлено и 30 удалено
  1. 10 1
      .gitignore
  2. 9 0
      gameplay.sln
  3. 17 8
      gameplay/.cproject
  4. 27 2
      gameplay/gameplay.vcxproj
  5. 69 1
      gameplay/gameplay.vcxproj.filters
  6. 3 0
      gameplay/src/Base.h
  7. 12 1
      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. 1 1
      gameplay/src/MaterialParameter.h
  12. 1 1
      gameplay/src/Matrix.h
  13. 3 1
      gameplay/src/MeshSkin.cpp
  14. 2 0
      gameplay/src/MeshSkin.h
  15. 3 2
      gameplay/src/Model.cpp
  16. 2 2
      gameplay/src/Model.h
  17. 20 3
      gameplay/src/Node.cpp
  18. 27 1
      gameplay/src/Node.h
  19. 38 0
      gameplay/src/PhysicsConstraint.cpp
  20. 78 0
      gameplay/src/PhysicsConstraint.h
  21. 30 0
      gameplay/src/PhysicsConstraint.inl
  22. 211 0
      gameplay/src/PhysicsController.cpp
  23. 214 0
      gameplay/src/PhysicsController.h
  24. 24 0
      gameplay/src/PhysicsFixedConstraint.cpp
  25. 64 0
      gameplay/src/PhysicsFixedConstraint.h
  26. 30 0
      gameplay/src/PhysicsFixedConstraint.inl
  27. 80 0
      gameplay/src/PhysicsGenericConstraint.cpp
  28. 161 0
      gameplay/src/PhysicsGenericConstraint.h
  29. 74 0
      gameplay/src/PhysicsGenericConstraint.inl
  30. 40 0
      gameplay/src/PhysicsHingeConstraint.cpp
  31. 65 0
      gameplay/src/PhysicsHingeConstraint.h
  32. 60 0
      gameplay/src/PhysicsMotionState.cpp
  33. 56 0
      gameplay/src/PhysicsMotionState.h
  34. 179 0
      gameplay/src/PhysicsRigidBody.cpp
  35. 229 0
      gameplay/src/PhysicsRigidBody.h
  36. 97 0
      gameplay/src/PhysicsRigidBody.inl
  37. 65 0
      gameplay/src/PhysicsSocketConstraint.cpp
  38. 58 0
      gameplay/src/PhysicsSocketConstraint.h
  39. 73 0
      gameplay/src/PhysicsSpringConstraint.cpp
  40. 191 0
      gameplay/src/PhysicsSpringConstraint.h
  41. 70 0
      gameplay/src/PhysicsSpringConstraint.inl
  42. 4 0
      gameplay/src/PlatformWin32.cpp
  43. 11 0
      gameplay/src/gameplay.h

+ 10 - 1
.gitignore

@@ -59,4 +59,13 @@
 /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-catapult/Debug
+/gameplay-samples/sample04-catapult/Release
+/gameplay-samples/sample04-catapult/Simulator
+/gameplay-samples/sample04-catapult/Simulator-Coverage
+/gameplay-samples/sample04-catapult/Simulator-Profile
+/gameplay-samples/sample04-catapult/Device-Debug
+/gameplay-samples/sample04-catapult/Device-Coverage
+/gameplay-samples/sample04-catapult/Device-Profile
+/gameplay-samples/sample04-catapult/Device-Release

+ 9 - 0
gameplay.sln

@@ -53,6 +53,11 @@ 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("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample04-catapult", "gameplay-samples\sample04-catapult\sample04-catapult.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
@@ -83,6 +88,10 @@ Global
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.Debug|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}.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>

+ 27 - 2
gameplay/gameplay.vcxproj

@@ -43,6 +43,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" />
@@ -102,6 +111,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" />
@@ -122,6 +140,13 @@
     <ClInclude Include="src\VertexFormat.h" />
     <ClInclude Include="src\Viewport.h" />
   </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>
@@ -168,7 +193,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>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -184,7 +209,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>

+ 69 - 1
gameplay/gameplay.vcxproj.filters

@@ -162,6 +162,33 @@
     <ClCompile Include="src\RenderState.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">
@@ -332,8 +359,49 @@
     <ClInclude Include="src\RenderState.h">
       <Filter>src</Filter>
     </ClInclude>
-    <ClInclude Include="src\Tree.h">
+    <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="src\PhysicsFixedConstraint.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\PhysicsGenericConstraint.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\PhysicsSpringConstraint.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\PhysicsRigidBody.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\PhysicsConstraint.inl">
+      <Filter>src</Filter>
+    </None>
   </ItemGroup>
 </Project>

+ 3 - 0
gameplay/src/Base.h

@@ -116,6 +116,9 @@ extern void printError(const char* format, ...);
 #include <alut.h>
 #endif
 
+// Bullet Physics
+#include <btBulletDynamicsCommon.h>
+
 // Graphics (OpenGLES/OpenGL/png)
 #define WINDOW_VSYNC        1
 #define WINDOW_FULLSCREEN   0

+ 12 - 1
gameplay/src/Game.cpp

@@ -94,6 +94,7 @@ bool Game::startup()
 
     _animationController.initialize();
     _audioController.initialize();
+	_physicsController.initialize();
 
     // Call user initialization.
     initialize();
@@ -111,6 +112,7 @@ void Game::shutdown()
 
         _animationController.finalize();
         _audioController.finalize();
+        _physicsController.finalize();
     }
 
     _state = UNINITIALIZED;
@@ -124,6 +126,7 @@ void Game::pause()
         _pausedTimeLast = Platform::getAbsoluteTime();
         _animationController.pause();
         _audioController.pause();
+        _physicsController.pause();
     }
 }
 
@@ -135,6 +138,7 @@ void Game::resume()
         _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
         _animationController.resume();
         _audioController.resume();
+        _physicsController.resume();
     }
 }
 
@@ -154,8 +158,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);
 
@@ -232,6 +238,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
@@ -178,6 +179,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.
      */
@@ -281,6 +290,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;
 };
 
 }

+ 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

@@ -236,7 +236,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.

+ 3 - 1
gameplay/src/MeshSkin.cpp

@@ -12,7 +12,7 @@
 namespace gameplay
 {
 
-MeshSkin::MeshSkin() : _matrixPalette(NULL)
+MeshSkin::MeshSkin() : _matrixPalette(NULL), _model(NULL)
 {
 }
 
@@ -82,10 +82,12 @@ void MeshSkin::setJoint(Joint* joint, unsigned int index)
 
     if (_joints[index])
     {
+        _joints[index]->_skin = NULL;
         SAFE_RELEASE(_joints[index]);
     }
 
     _joints[index] = joint;
+    _joints[index]->_skin = this;
     joint->addRef();
 }
 

+ 2 - 0
gameplay/src/MeshSkin.h

@@ -20,6 +20,7 @@ class MeshSkin
 {
     friend class Package;
     friend class Model;
+    friend class Joint;
 
 public:
 
@@ -112,6 +113,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;
 };
 
 }

+ 3 - 2
gameplay/src/Model.cpp

@@ -187,6 +187,7 @@ void Model::setSkin(MeshSkin* skin)
 
         // Assign the new skin
         _skin = skin;
+        _skin->_model = this;
     }
 }
 
@@ -323,9 +324,9 @@ void Model::validatePartCount()
         _partCount = _mesh->getPartCount();
     }
 }
-
+
 void Model::setMaterialNodeBinding(Material *material)
-{
+{
     if (_node)
     {
         material->setNodeBinding(_node);

+ 2 - 2
gameplay/src/Model.h

@@ -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.

+ 20 - 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)
     {
@@ -288,7 +288,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);
         }
@@ -788,6 +788,23 @@ void Node::setParticleEmitter(ParticleEmitter* emitter)
     }
 }
 
+PhysicsRigidBody* Node::getPhysicsRigidBody()
+{
+    return _physicsRigidBody;
+}
+
+void Node::setPhysicsRigidBody(PhysicsRigidBody::Type type, float mass, float friction,
+        float restitution, float linearDamping, float angularDamping)
+{
+    if (_physicsRigidBody)
+    {
+        SAFE_RELEASE(_physicsRigidBody);
+    }
+    
+    if (type != PhysicsRigidBody::PHYSICS_SHAPE_NONE)
+        _physicsRigidBody = new PhysicsRigidBody(this, type, mass, friction, restitution, linearDamping, angularDamping);
+}
+
 void Node::childAdded(Node* child)
 {
     child->addRef();

+ 27 - 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,30 @@ 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();
+
+    /**
+     * Assigns a physics rigid body to 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.
+     * @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, float friction = 0.5,
+        float restitution = 0.0, float linearDamping = 0.0, float angularDamping = 0.0);
+
     /**
      * Returns the bounding box for the Node, in world space.
      *
@@ -451,6 +476,7 @@ protected:
     Model* _model;
     AudioSource* _audioSource;
     ParticleEmitter* _particleEmitter;
+    PhysicsRigidBody* _physicsRigidBody;
     mutable Matrix _world;
     mutable int _dirtyBits;
     bool _notifyHierarchyChanged;

+ 38 - 0
gameplay/src/PhysicsConstraint.cpp

@@ -0,0 +1,38 @@
+/*
+ * PhysicsConstraint.cpp
+ */
+
+#include "PhysicsConstraint.h"
+
+#include "Node.h"
+
+namespace gameplay
+{
+
+PhysicsConstraint::PhysicsConstraint() : _constraint(NULL)
+{
+}
+
+PhysicsConstraint::~PhysicsConstraint()
+{
+    if (_constraint)
+    {
+        SAFE_DELETE(_constraint);
+    }
+}
+
+Vector3 PhysicsConstraint::midpoint(Node* a, Node* b)
+{
+    Vector3 tA, tB;
+    a->getWorldMatrix().getTranslation(&tA);
+    b->getWorldMatrix().getTranslation(&tB);
+    
+    Vector3 d(tA, tB);
+    d.scale(0.5f);
+    Vector3 c(tA);
+    c.add(d);
+
+    return c;
+}
+
+}

+ 78 - 0
gameplay/src/PhysicsConstraint.h

@@ -0,0 +1,78 @@
+/*
+ * PhysicsConstraint.h
+ */
+
+#ifndef PHYSICSCONSTRAINT_H_
+#define PHYSICSCONSTRAINT_H_
+
+#include "Base.h"
+#include "Ref.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+    class Node;
+
+/**
+ * Base class for physics constraints.
+ */
+class PhysicsConstraint : public Ref
+{
+    friend class PhysicsController;
+
+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);
+
+protected:
+    /**
+     * Constructor.
+     */
+    PhysicsConstraint();
+
+    /**
+     * Destructor.
+     */
+    virtual ~PhysicsConstraint();
+
+    /**
+     * Calculates the midpoint between the two nodes.
+     */
+    static Vector3 midpoint(Node* a, Node* 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);
+}
+
+}

+ 211 - 0
gameplay/src/PhysicsController.cpp

@@ -0,0 +1,211 @@
+/*
+ * PhysicsController.cpp
+ */
+
+#include "Base.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)
+{
+}
+
+PhysicsController::~PhysicsController()
+{
+}
+
+void PhysicsController::setGravity(const Vector3& gravity)
+{
+	_gravity.setX(gravity.x);
+	_gravity.setY(gravity.y);
+	_gravity.setZ(gravity.z);
+
+	if (_world)
+	{
+		_world->setGravity(_gravity);
+	}
+}
+
+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;
+}
+
+void PhysicsController::initialize()
+{
+	// TODO: Should any of this be configurable?
+	_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(_gravity);
+}
+
+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);
+}
+
+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));
+	btBoxShape* box = new btBoxShape(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();
+
+	btSphereShape* sphere = new btSphereShape(uniformScale * radius);
+	_shapes.push_back(sphere);
+
+	return sphere;
+}
+
+btCollisionShape* PhysicsController::getTriangleMesh(float* vertexData, int vertexPositionStride, unsigned char* indexData, Mesh::IndexFormat indexFormat)
+{
+	return NULL;
+}
+
+btCollisionShape* PhysicsController::getHeightfield(void* data, int width, int height)
+{
+	return NULL;
+}
+
+void PhysicsController::setupConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
+{
+    a->addConstraint(constraint);
+    if (b)
+        b->addConstraint(constraint);
+
+    _world->addConstraint(constraint->_constraint);
+}
+
+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);
+	}
+}
+
+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);
+	}
+}
+
+}

+ 214 - 0
gameplay/src/PhysicsController.h

@@ -0,0 +1,214 @@
+/*
+ * 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 PhysicsRigidBody;
+
+public:
+	/**
+	 * Sets the gravity vector for the simulated physics world.
+	 * 
+	 * @param gravity The gravity vector.
+	 */
+	void setGravity(const Vector3& gravity);
+
+    /**
+     * 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);
+
+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);
+
+    // Creates a box collision shape to be used in the creation of a rigid body.
+	btCollisionShape* getBox(const Vector3& min, const Vector3& max, const btVector3& scale);
+
+    // Creates a sphere collision shape to be used in the creation of a rigid body.
+	btCollisionShape* getSphere(float radius, const btVector3& scale);
+
+    // Creates a triangle mesh collision shape to be used in the creation of a rigid body.
+	btCollisionShape* getTriangleMesh(float* vertexData, int vertexPositionStride, unsigned char* indexData, Mesh::IndexFormat indexFormat);
+
+    // Creates a heightfield collision shape to be used in the creation of a rigid body.
+	btCollisionShape* getHeightfield(void* data, int width, int height);
+    
+    // Sets up the given constraint for the given two rigid bodies.
+    void setupConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint);
+    
+    // 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);
+
+	btVector3 _gravity;
+	btDefaultCollisionConfiguration* _collisionConfiguration;
+	btCollisionDispatcher* _dispatcher;
+	btBroadphaseInterface* _overlappingPairCache;
+	btSequentialImpulseConstraintSolver* _solver;
+	btDynamicsWorld* _world;
+	btAlignedObjectArray<btCollisionShape*> _shapes;
+};
+
+}
+
+#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);
+}
+
+}

+ 80 - 0
gameplay/src/PhysicsGenericConstraint.cpp

@@ -0,0 +1,80 @@
+/**
+ * PhysicsGenericConstraint.cpp
+ */
+
+#include "PhysicsGenericConstraint.h"
+
+#include "Node.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsGenericConstraint::PhysicsGenericConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+PhysicsGenericConstraint::PhysicsGenericConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    if (b)
+    {
+        // Create a translation matrix that translates to the midpoint
+        // between the two physics rigid bodies.
+        Matrix m;
+        Matrix::createTranslation(midpoint(a->_node, b->_node), &m);
+
+        // Calculate the translation and rotation offsets to the rigid bodies
+        // by transforming the translation matrix above into each rigid body's
+        // local space (multiply by the inverse world matrix and extract components).
+        Matrix mAi;
+        a->_node->getWorldMatrix().invert(&mAi);
+        mAi.multiply(m);
+
+        Matrix mBi;
+        b->_node->getWorldMatrix().invert(&mBi);
+        mBi.multiply(m);
+
+        Quaternion rA, rB;
+        mAi.getRotation(&rA);
+        mBi.getRotation(&rB);
+    
+        Vector3 tA, tB;
+        mAi.getTranslation(&tA);
+        mBi.getTranslation(&tB);
+
+        btTransform frameInA(btQuaternion(rA.x, rA.y, rA.z, rA.w), btVector3(tA.x, tA.y, tA.z));
+        btTransform frameInB(btQuaternion(rB.x, rB.y, rB.z, rB.w), btVector3(tB.x, tB.y, tB.z));
+        _constraint = new btGeneric6DofConstraint(*a->_body, *b->_body, frameInA, frameInB, 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)
+{
+    if (b)
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z));
+        btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), 
+            btVector3(translationOffsetB.x, translationOffsetB.y, translationOffsetB.z));
+        _constraint = new btGeneric6DofConstraint(*a->_body, *b->_body, frameInA, frameInB, true);
+    }
+    else
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z));
+        _constraint = new btGeneric6DofConstraint(*a->_body, frameInA, true);
+    }
+}
+
+PhysicsGenericConstraint::~PhysicsGenericConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+}

+ 161 - 0
gameplay/src/PhysicsGenericConstraint.h

@@ -0,0 +1,161 @@
+/*
+ * 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 Quaternion getRotationOffsetA();
+
+    /**
+     * Gets the rotation offset for the second rigid body in the constraint.
+     * 
+     * @return The rotation offset.
+     */
+    inline Quaternion getRotationOffsetB();
+
+    /**
+     * Gets the translation offset for the first rigid body in the constraint.
+     * 
+     * @return The translation offset.
+     */
+    inline Vector3 getTranslationOffsetA();
+
+    /**
+     * Gets the translation offset for the second rigid body in the constraint.
+     * 
+     * @return The translation offset.
+     */
+    inline Vector3 getTranslationOffsetB();
+
+    /**
+     * Sets the lower angular limits along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The lower angular limits along the local X, Y, and Z axes.
+     */
+    inline void setAngularLowerLimit(const Vector3& limits);
+
+    /**
+     * Sets the upper angular limits along the constraint's local
+     * X, Y, and Z axes using the values in the given vector.
+     * 
+     * @param limits The upper angular 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();
+};
+
+}
+
+#include "PhysicsGenericConstraint.inl"
+
+#endif

+ 74 - 0
gameplay/src/PhysicsGenericConstraint.inl

@@ -0,0 +1,74 @@
+/**
+ * PhysicsGenericConstraint.inl
+ */
+
+#include "PhysicsGenericConstraint.h"
+
+namespace gameplay
+{
+
+inline Quaternion PhysicsGenericConstraint::getRotationOffsetA()
+{
+    btQuaternion ro = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().getRotation();
+    return Quaternion(ro.x(), ro.y(), ro.z(), ro.w());
+}
+
+inline Quaternion PhysicsGenericConstraint::getRotationOffsetB()
+{
+    btQuaternion ro = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().getRotation();
+    return Quaternion(ro.x(), ro.y(), ro.z(), ro.w());
+}
+
+inline Vector3 PhysicsGenericConstraint::getTranslationOffsetA()
+{
+    btVector3 to = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetA().getOrigin();
+    return Vector3(to.x(), to.y(), to.z());
+}
+
+inline Vector3 PhysicsGenericConstraint::getTranslationOffsetB()
+{
+    btVector3 to = static_cast<btGeneric6DofConstraint*>(_constraint)->getFrameOffsetB().getOrigin();
+    return Vector3(to.x(), to.y(), to.z());
+}
+
+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));
+}
+
+}

+ 40 - 0
gameplay/src/PhysicsHingeConstraint.cpp

@@ -0,0 +1,40 @@
+/*
+ * PhysicsHingeConstraint.cpp
+ */
+
+#include "PhysicsHingeConstraint.h"
+
+namespace gameplay
+{
+
+void PhysicsHingeConstraint::setLimits(float minAngle, float maxAngle, float softness, float biasFactor, float relaxationFactor)
+{
+    ((btHingeConstraint*)_constraint)->setLimit(minAngle, maxAngle, softness, biasFactor, relaxationFactor);
+}
+
+PhysicsHingeConstraint::PhysicsHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+{
+    if (b)
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z));
+        btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), 
+            btVector3(translationOffsetB.x, translationOffsetB.y, translationOffsetB.z));
+        _constraint = new btHingeConstraint(*a->_body, *b->_body, frameInA, frameInB);
+    }
+    else
+    {
+        btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z));
+        _constraint = new btHingeConstraint(*a->_body, frameInA);
+    }
+}
+
+    
+PhysicsHingeConstraint::~PhysicsHingeConstraint()
+{
+    // DUMMY FUNCTION
+}
+
+}

+ 65 - 0
gameplay/src/PhysicsHingeConstraint.h

@@ -0,0 +1,65 @@
+/*
+ * 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 softness The softness of the hinge (defaults to 0.9).
+     * @param biasFactor The bias factor for the hinge (defaults to 0.3).
+     * @param relaxationFactor The relaxation factor for the hinge (defaults to 1.0).
+     */
+    void setLimits(float minAngle, float maxAngle, float softness = 0.9f, 
+        float biasFactor = 0.3f, float relaxationFactor = 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

+ 60 - 0
gameplay/src/PhysicsMotionState.cpp

@@ -0,0 +1,60 @@
+/**
+ * PhysicsMotionState.cpp
+ */
+
+#include "PhysicsMotionState.h"
+
+namespace gameplay
+{
+
+PhysicsMotionState::PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset) : _node(node),
+    _needsUpdate(false), _centerOfMassOffset(btTransform::getIdentity())
+{
+    // 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)
+    {
+        // Store the center of mass offset.
+        _centerOfMassOffset.setOrigin(btVector3(centerOfMassOffset->x, centerOfMassOffset->y, centerOfMassOffset->z));
+
+        // 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]));
+    }
+}
+
+PhysicsMotionState::~PhysicsMotionState()
+{
+}
+
+void PhysicsMotionState::getWorldTransform(btTransform &transform) const
+{
+	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());
+}
+
+}

+ 56 - 0
gameplay/src/PhysicsMotionState.h

@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+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:
+	Node* _node;
+    btTransform _centerOfMassOffset;
+	btTransform _worldTransform;
+    bool _needsUpdate;
+};
+
+}
+
+#endif

+ 179 - 0
gameplay/src/PhysicsRigidBody.cpp

@@ -0,0 +1,179 @@
+/*
+ * PhysicsRigidBody.cpp
+ */
+
+#include "Base.h"
+#include "Game.h"
+#include "PhysicsController.h"
+#include "PhysicsMotionState.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsRigidBody::PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, float mass, 
+		float friction, float restitution, float linearDamping, float angularDamping)
+        : _shape(NULL), _body(NULL), _node(node)
+{
+	switch (type)
+	{
+		case PhysicsRigidBody::PHYSICS_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::PHYSICS_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;
+		}
+		case PhysicsRigidBody::PHYSICS_SHAPE_TRIANGLE_MESH:
+		{
+			//btTriangleIndexVertexArray meshShape(numTriangles, indexPointer, indexStride, numVertices, vertexPointer, vertexStride);
+			//_shape = btBvhTriangleMeshShape(meshShape, true);
+
+			//_body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
+			break;
+		}
+		case PhysicsRigidBody::PHYSICS_SHAPE_HEIGHTFIELD:
+		{
+			//_shape = btHeightfieldTerrainShape(width, length, data, scale, minHeight, maxHeight, upAxis, dataType, false);
+
+			//_body = createBulletRigidBody(_shape, mass, node, friction, restitution, linearDamping, angularDamping);
+			break;
+		}
+	}
+}
+
+PhysicsRigidBody::~PhysicsRigidBody()
+{
+    // Clean up all constraints linked to this rigid body.
+    for (unsigned int i = 0; i < _constraints.size(); i++)
+    {
+        Game::getInstance()->getPhysicsController()->removeConstraint(_constraints[i]);
+        SAFE_RELEASE(_constraints[i]);
+    }
+
+    // Clean up the rigid body and its related objects.
+    if (_body)
+    {
+        if (_body->getMotionState())
+            delete _body->getMotionState();
+
+        if (_shape)
+            SAFE_DELETE(_shape);
+
+        Game::getInstance()->getPhysicsController()->removeRigidBody(this);
+        SAFE_DELETE(_body);
+    }
+}
+
+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));
+    }
+}
+
+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;
+	btRigidBody* body = new btRigidBody(rbInfo);
+
+	// Add the rigid body to the physics world.
+	PhysicsController* physics = Game::getInstance()->getPhysicsController();
+	physics->_world->addRigidBody(body);
+
+	return body;
+}
+
+
+
+}

+ 229 - 0
gameplay/src/PhysicsRigidBody.h

@@ -0,0 +1,229 @@
+/*
+ * PhysicsRigidBody.h
+ */
+
+#ifndef PHYSICSRIGIDBODY_H_
+#define PHYSICSRIGIDBODY_H_
+
+#include "Mesh.h"
+#include "Ref.h"
+#include "Transform.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+
+class Node;
+class PhysicsConstraint;
+
+/**
+ * Defines a class for physics rigid bodies.
+ */
+class PhysicsRigidBody : public Ref
+{
+    friend class Node;
+	friend class PhysicsController;
+    friend class PhysicsFixedConstraint;
+    friend class PhysicsGenericConstraint;
+    friend class PhysicsHingeConstraint;
+    friend class PhysicsMotionState;
+    friend class PhysicsSocketConstraint;
+    friend class PhysicsSpringConstraint;
+
+public:
+    /**
+     * Represents the different types of rigid bodies.
+     */
+	enum Type
+	{
+		PHYSICS_SHAPE_BOX,
+		PHYSICS_SHAPE_SPHERE,
+		PHYSICS_SHAPE_TRIANGLE_MESH,
+		PHYSICS_SHAPE_HEIGHTFIELD,
+        PHYSICS_SHAPE_NONE
+	};
+
+    /**
+     * 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);
+    
+    /**
+     * 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 Vector3 getAngularVelocity() const;
+
+    /**
+     * Gets the rigid body's anisotropic friction.
+     * 
+     * @return The anisotropic friction.
+     */
+    inline 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 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 Vector3 getLinearVelocity() const;
+
+    /**
+     * Gets the rigid body's restitution.
+     * 
+     * @return The restitution.
+     */
+    inline float getRestitution() 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 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.
+    inline void addConstraint(PhysicsConstraint* constraint);
+
+	btCollisionShape* _shape;
+    btRigidBody* _body;
+    Node* _node;
+    std::vector<PhysicsConstraint*> _constraints;
+};
+
+}
+
+#include "PhysicsRigidBody.inl"
+
+#endif

+ 97 - 0
gameplay/src/PhysicsRigidBody.inl

@@ -0,0 +1,97 @@
+/**
+ * PhysicsRigidBody.inl
+ */
+
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+// TODO: We can't cache these Vector3 values, but should we have member variables
+// that are set each time instead of creating a new Vector3 every time?
+
+inline float PhysicsRigidBody::getAngularDamping() const
+{
+	return _body->getAngularDamping();
+}
+
+inline Vector3 PhysicsRigidBody::getAngularVelocity() const
+{
+	const btVector3& v = _body->getAngularVelocity();
+	return Vector3(v.x(), v.y(), v.z());
+}
+
+inline Vector3 PhysicsRigidBody::getAnisotropicFriction() const
+{
+    const btVector3& af = _body->getAnisotropicFriction();
+    return Vector3(af.x(), af.y(), af.z());
+}
+
+inline float PhysicsRigidBody::getFriction() const
+{
+    return _body->getFriction();
+}
+
+inline Vector3 PhysicsRigidBody::getGravity() const
+{
+    const btVector3& g = _body->getGravity();
+    return Vector3(g.x(), g.y(), g.z());
+}
+
+inline float PhysicsRigidBody::getLinearDamping() const
+{
+	return _body->getLinearDamping();
+}
+
+inline Vector3 PhysicsRigidBody::getLinearVelocity() const
+{
+	const btVector3& v = _body->getLinearVelocity();
+	return Vector3(v.x(), v.y(), v.z());
+}
+
+inline float PhysicsRigidBody::getRestitution() const
+{
+    return _body->getRestitution();
+}
+
+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::setLinearVelocity(const Vector3& velocity)
+{
+	_body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
+}
+
+inline void PhysicsRigidBody::setRestitution(float restitution)
+{
+    _body->setRestitution(restitution);
+}
+
+inline void PhysicsRigidBody::addConstraint(PhysicsConstraint* constraint)
+{
+    _constraints.push_back(constraint);
+}
+
+}

+ 65 - 0
gameplay/src/PhysicsSocketConstraint.cpp

@@ -0,0 +1,65 @@
+/**
+ * PhysicsSocketConstraint.cpp
+ */
+
+#include "PhysicsSocketConstraint.h"
+
+#include "Node.h"
+
+namespace gameplay
+{
+
+PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    if (b)
+    {
+        // Create a translation matrix that translates to the midpoint
+        // between the two physics rigid bodies.
+        Matrix m;
+        Matrix::createTranslation(midpoint(a->_node, b->_node), &m);
+
+        // Calculate the translation offsets to the rigid bodies
+        // by transforming the translation matrix above into each rigid body's
+        // local space (multiply by the inverse world matrix and extract translation).
+        Matrix mAi;
+        a->_node->getWorldMatrix().invert(&mAi);
+        mAi.multiply(m);
+
+        Matrix mBi;
+        b->_node->getWorldMatrix().invert(&mBi);
+        mBi.multiply(m);
+    
+        Vector3 tA, tB;
+        mAi.getTranslation(&tA);
+        mBi.getTranslation(&tB);
+
+        _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(0.0f, 0.0f, 0.0f));
+    }
+}
+
+PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, const Vector3& translationOffsetA, 
+    PhysicsRigidBody* b, const Vector3& translationOffsetB)
+{
+    if (b)
+    {
+        _constraint = new btPoint2PointConstraint(*a->_body, *b->_body, 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z),
+            btVector3(translationOffsetB.x, translationOffsetB.y, translationOffsetB.z));
+    }
+    else
+    {
+        _constraint = new btPoint2PointConstraint(*a->_body, 
+            btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.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

+ 73 - 0
gameplay/src/PhysicsSpringConstraint.cpp

@@ -0,0 +1,73 @@
+/**
+ * PhysicsSpringConstraint.cpp
+ */
+
+#include "PhysicsSpringConstraint.h"
+
+#include "Node.h"
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+
+PhysicsSpringConstraint::PhysicsSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
+{
+    // Create a translation matrix that translates to the midpoint
+    // between the two physics rigid bodies.
+    Matrix m;
+    Matrix::createTranslation(midpoint(a->_node, b->_node), &m);
+
+    // Calculate the translation and rotation offsets to the rigid bodies
+    // by transforming the translation matrix above into each rigid body's
+    // local space (multiply by the inverse world matrix and extract components).
+    Matrix mAi;
+    a->_node->getWorldMatrix().invert(&mAi);
+    mAi.multiply(m);
+
+    Matrix mBi;
+    b->_node->getWorldMatrix().invert(&mBi);
+    mBi.multiply(m);
+
+    Quaternion rA, rB;
+    mAi.getRotation(&rA);
+    mBi.getRotation(&rB);
+    
+    Vector3 tA, tB;
+    mAi.getTranslation(&tA);
+    mBi.getTranslation(&tB);
+
+    btTransform frameInA(btQuaternion(rA.x, rA.y, rA.z, rA.w), btVector3(tA.x, tA.y, tA.z));
+    btTransform frameInB(btQuaternion(rB.x, rB.y, rB.z, rB.w), btVector3(tB.x, tB.y, tB.z));
+            
+    _constraint = new btGeneric6DofSpringConstraint(*a->_body, *b->_body, frameInA, frameInB, true);
+}
+
+PhysicsSpringConstraint::PhysicsSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
+    PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
+{
+    btTransform frameInA(btQuaternion(rotationOffsetA.x, rotationOffsetA.y, rotationOffsetA.z, rotationOffsetA.w), 
+        btVector3(translationOffsetA.x, translationOffsetA.y, translationOffsetA.z));
+    btTransform frameInB(btQuaternion(rotationOffsetB.x, rotationOffsetB.y, rotationOffsetB.z, rotationOffsetB.w), 
+        btVector3(translationOffsetB.x, translationOffsetB.y, translationOffsetB.z));
+    _constraint = new btGeneric6DofSpringConstraint(*a->_body, *b->_body, frameInA, frameInB, true);
+}
+
+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);
+}
+
+}

+ 191 - 0
gameplay/src/PhysicsSpringConstraint.h

@@ -0,0 +1,191 @@
+/*
+ * 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);
+
+    // 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;

+ 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"