Explorar o código

- Interim commit on Physics development (before getting changes from SVN).

Chris Culy %!s(int64=14) %!d(string=hai) anos
pai
achega
cf536cc2fd

+ 7 - 1
.gitignore

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

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

+ 7 - 2
gameplay/gameplay.vcxproj

@@ -43,6 +43,8 @@
     <ClCompile Include="src\Node.cpp" />
     <ClCompile Include="src\Package.cpp" />
     <ClCompile Include="src\ParticleEmitter.cpp" />
+    <ClCompile Include="src\PhysicsController.cpp" />
+    <ClCompile Include="src\PhysicsRigidBody.cpp" />
     <ClCompile Include="src\Plane.cpp" />
     <ClCompile Include="src\PlatformQNX.cpp" />
     <ClCompile Include="src\PlatformWin32.cpp" />
@@ -102,6 +104,9 @@
     <ClInclude Include="src\Node.h" />
     <ClInclude Include="src\Package.h" />
     <ClInclude Include="src\ParticleEmitter.h" />
+    <ClInclude Include="src\PhysicsController.h" />
+    <ClInclude Include="src\PhysicsMotionState.h" />
+    <ClInclude Include="src\PhysicsRigidBody.h" />
     <ClInclude Include="src\Plane.h" />
     <ClInclude Include="src\Platform.h" />
     <ClInclude Include="src\Properties.h" />
@@ -168,7 +173,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 +189,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>

+ 16 - 1
gameplay/gameplay.vcxproj.filters

@@ -162,6 +162,12 @@
     <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>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">
@@ -335,5 +341,14 @@
     <ClInclude Include="src\Tree.h">
       <Filter>src</Filter>
     </ClInclude>
+    <ClInclude Include="src\PhysicsController.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsMotionState.h">
+      <Filter>src</Filter>
+    </ClInclude>
+    <ClInclude Include="src\PhysicsRigidBody.h">
+      <Filter>src</Filter>
+    </ClInclude>
   </ItemGroup>
-</Project>
+</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.
 };
 
 }

+ 27 - 5
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,10 +43,6 @@ 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(t, bindShape, &t);
@@ -68,4 +64,30 @@ void Joint::setInverseBindPose(const Matrix& m)
     _jointMatrixDirty = true;
 }
 
+const Matrix& Joint::getWorldMatrix() const
+{
+    return Node::getWorldMatrix();
+}
+
+const Matrix& Joint::getJointMatrix() 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)
+    {
+        if (_skin != NULL)
+            Matrix::multiply(_skin->_model->getNode()->getWorldMatrix(), Node::getWorldMatrix(), &_jointWorld);
+        else if (_firstChild != NULL && ((Joint*)_firstChild)->_skin != NULL)
+            Matrix::multiply(((Joint*)_firstChild)->_skin->_model->getNode()->getWorldMatrix(), Node::getWorldMatrix(), &_jointWorld);
+    }
+    else
+    {
+        memcpy((void*)_jointWorld.m, Node::getWorldMatrix().m, MATRIX_SIZE);
+    }
+
+    return _jointWorld;
+}
+
 }

+ 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;
 };
 
 }

+ 5 - 2
gameplay/src/MaterialParameter.h

@@ -13,8 +13,6 @@
 #include "Texture.h"
 #include "Effect.h"
 
-#define MATERIALPARAMETER_ANIMATE_UNIFORM           1
-
 namespace gameplay
 {
 
@@ -49,6 +47,11 @@ public:
      */
     const char* getName() const;
 
+    /**
+     * MaterialParameter's animation target property.
+     */
+    static const int ANIMATE_UNIFORM = 1;
+
     /**
      * Sets the value of this parameter to a float value.
      */

+ 3 - 4
gameplay/src/MeshSkin.cpp

@@ -12,7 +12,7 @@
 namespace gameplay
 {
 
-MeshSkin::MeshSkin() : _matrixPalette(NULL)
+MeshSkin::MeshSkin() : _matrixPalette(NULL), _model(NULL)
 {
 }
 
@@ -41,10 +41,7 @@ Joint* MeshSkin::getJoint(const char* id) const
     {
         Joint* j = _joints[i];
         if (j && j->getId() != NULL && strcmp(j->getId(), id) == 0)
-        {
             return j;
-        }
-    }
 
     return NULL;
 }
@@ -82,10 +79,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();
 }
 

+ 3 - 1
gameplay/src/MeshSkin.h

@@ -20,6 +20,7 @@ class MeshSkin
 {
     friend class Package;
     friend class Model;
+    friend class Joint;
 
 public:
 
@@ -62,7 +63,7 @@ public:
      */
     unsigned int getMatrixPaletteSize() const;
 
-private:
+//private:
 
     /**
      * Constructor.
@@ -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;
 };
 
 }

+ 1 - 0
gameplay/src/Model.cpp

@@ -187,6 +187,7 @@ void Model::setSkin(MeshSkin* skin)
 
         // Assign the new skin
         _skin = skin;
+        _skin->_model = this;
     }
 }
 

+ 19 - 2
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)
     {
@@ -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 bouncyness of
+     *      the rigid body; between 0.0 and 1.0, where 0.0 is minimal bouncyness and 1.0 is maximal bouncyness).
+     * @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;

+ 143 - 0
gameplay/src/PhysicsController.cpp

@@ -0,0 +1,143 @@
+/*
+ * PhysicsController.cpp
+ */
+
+#include "Base.h"
+#include "PhysicsController.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(Vector3 gravity)
+{
+	_gravity.setX(gravity.x);
+	_gravity.setY(gravity.y);
+	_gravity.setZ(gravity.z);
+
+	if (_world)
+	{
+		_world->setGravity(_gravity);
+	}
+}
+
+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()
+{
+	// Remove the rigid bodies from the world and delete them.
+	for (int i = _world->getNumCollisionObjects() - 1; i >= 0 ; i--)
+	{
+		btCollisionObject* obj = _world->getCollisionObjectArray()[i];
+		btRigidBody* body = btRigidBody::upcast(obj);
+		if (body && body->getMotionState())
+		{
+			delete body->getMotionState();
+		}
+		_world->removeCollisionObject(obj);
+		delete obj;
+	}
+
+	// Delete all of the collision shapes.
+	for (int i = 0; i < _shapes.size(); i++)
+	{
+		btCollisionShape* shape = _shapes[i];
+		_shapes[i] = 0;
+		delete shape;
+	}
+	_shapes.clear();
+
+	// Clean up the world and its various components.
+	delete _world; 
+	_world = NULL;
+
+	delete _solver; 
+	_solver = NULL;
+
+	delete _overlappingPairCache; 
+	_overlappingPairCache = NULL;
+	
+	delete _dispatcher; 
+	_dispatcher = NULL;
+	
+	delete _collisionConfiguration; 
+	_collisionConfiguration = NULL;
+}
+
+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;
+}
+
+}

+ 83 - 0
gameplay/src/PhysicsController.h

@@ -0,0 +1,83 @@
+/*
+ * PhysicsController.h
+ */
+
+#ifndef PHYSICSCONTROLLER_H_
+#define PHYSICSCONTROLLER_H_
+
+#include "PhysicsRigidBody.h"
+
+namespace gameplay
+{
+	
+/**
+ * Defines a class for controlling game physics.
+ */
+class PhysicsController
+{
+	friend class Game;
+	friend class PhysicsRigidBody;
+
+public:
+    
+	/**
+	 * Destructor
+	 */
+	virtual ~PhysicsController();
+
+	/**
+	 * Sets the gravity vector for the simulated physics world.
+	 * 
+	 * @param gravity The gravity vector.
+	 */
+	void setGravity(Vector3 gravity);
+
+private:
+	
+	/**
+	 * Constructor
+	 */
+	PhysicsController();
+
+	/**
+	 * Controller initialize
+	 */
+	void initialize();
+
+	/**
+	 * Controller finalize
+	 */
+    void finalize();
+
+	/**
+	 * Controller pause
+	 */
+    void pause();
+
+	/**
+	 * Controller resume
+	 */
+    void resume();
+
+	/**
+	 * Controller update
+	 */
+    void update(long elapsedTime);
+
+	btCollisionShape* getBox(const Vector3& min, const Vector3& max, const btVector3& scale);
+	btCollisionShape* getSphere(float radius, const btVector3& scale);
+	btCollisionShape* getTriangleMesh(float* vertexData, int vertexPositionStride, unsigned char* indexData, Mesh::IndexFormat indexFormat);
+	btCollisionShape* getHeightfield(void* data, int width, int height);
+
+	btVector3 _gravity;
+	btDefaultCollisionConfiguration* _collisionConfiguration;
+	btCollisionDispatcher* _dispatcher;
+	btBroadphaseInterface* _overlappingPairCache;
+	btSequentialImpulseConstraintSolver* _solver;
+	btDynamicsWorld* _world;
+	btAlignedObjectArray<btCollisionShape*> _shapes;
+};
+
+}
+
+#endif

+ 60 - 0
gameplay/src/PhysicsMotionState.h

@@ -0,0 +1,60 @@
+/*
+ * PhysicsMotionState.h
+ */
+
+#ifndef PHYSICSMOTIONSTATE_H_
+#define PHYSICSMOTIONSTATE_H_
+
+#include "Node.h"
+#include "PhysicsRigidBody.h"
+#include "Transform.h"
+
+namespace gameplay
+{
+
+class PhysicsMotionState : public btMotionState
+{
+	friend class PhysicsRigidBody;
+
+	PhysicsMotionState(Node* node) : _node(node)
+	{
+        // Store the initial world transform (minus the scale) for use by Bullet later on.
+        Quaternion rotation;
+        const Matrix& m = _node->getWorldMatrix();
+        m.getRotation(&rotation);
+		_worldTransform = btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w), 
+			btVector3(m.m[12], m.m[13], m.m[14]));
+	}
+
+public:
+
+	virtual ~PhysicsMotionState()
+	{
+    }
+
+    virtual void getWorldTransform(btTransform &transform) const
+	{
+		transform = _worldTransform;
+    }
+
+    virtual void setWorldTransform(const btTransform &transform)
+	{
+		// Calculate the actual world transform by 
+		// taking into account the center of mass offset.
+		_worldTransform = transform;
+
+        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());
+    }
+
+private:
+	Node* _node;
+	btTransform _worldTransform;
+};
+
+}
+
+#endif

+ 147 - 0
gameplay/src/PhysicsRigidBody.cpp

@@ -0,0 +1,147 @@
+/*
+ * 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)
+        : _node(node), _body(NULL)
+{
+	switch (type)
+	{
+		case PhysicsRigidBody::PHYSICS_SHAPE_BOX:
+		{
+			const BoundingBox& box = node->getModel()->getMesh()->getBoundingBox();
+
+            PhysicsController* physics = Game::getInstance()->getPhysicsController();
+            btCollisionShape* shape = physics->getBox(box.min, box.max, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+			
+			_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();
+			btCollisionShape* shape = physics->getSphere(sphere.radius, btVector3(node->getScaleX(), node->getScaleY(), node->getScaleZ()));
+
+            _body = createBulletRigidBody(shape, mass, node, friction, restitution, linearDamping, angularDamping);
+			break;
+		}
+		case PhysicsRigidBody::PHYSICS_SHAPE_TRIANGLE_MESH:
+		{
+			//btTriangleIndexVertexArray meshShape(numTriangles, indexPointer, indexStride, numVertices, vertexPointer, vertexStride);
+			//btCollisionShape* shape = btBvhTriangleMeshShape(meshShape, true);
+
+			//_body = createBulletRigidBody(shape, mass, node, friction, restitution, linearDamping, angularDamping);
+			break;
+		}
+		case PhysicsRigidBody::PHYSICS_SHAPE_HEIGHTFIELD:
+		{
+			//btCollisionShape* shape = btHeightfieldTerrainShape(width, length, data, scale, minHeight, maxHeight, upAxis, dataType, false);
+
+			//_body = createBulletRigidBody(shape, mass, node, friction, restitution, linearDamping, angularDamping);
+			break;
+		}
+	}
+}
+
+PhysicsRigidBody::~PhysicsRigidBody()
+{
+    if (_body)
+    {
+        if (_body->getMotionState())
+            delete _body->getMotionState();
+
+        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)
+{
+	// 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);
+	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;
+}
+
+}

+ 164 - 0
gameplay/src/PhysicsRigidBody.h

@@ -0,0 +1,164 @@
+/*
+ * PhysicsRigidBody.h
+ */
+
+#ifndef PHYSICSRIGIDBODY_H_
+#define PHYSICSRIGIDBODY_H_
+
+#include "Mesh.h"
+#include "Ref.h"
+#include "Transform.h"
+#include "Vector3.h"
+
+namespace gameplay
+{
+
+class Node;
+
+/**
+ * Defines a class for physics rigid bodies.
+ */
+class PhysicsRigidBody : public Ref
+{
+public:
+
+	enum Type
+	{
+		PHYSICS_SHAPE_BOX,
+		PHYSICS_SHAPE_SPHERE,
+		PHYSICS_SHAPE_TRIANGLE_MESH,
+		PHYSICS_SHAPE_HEIGHTFIELD,
+        PHYSICS_SHAPE_NONE
+	};
+
+    void applyForce(const Vector3& force, const Vector3* relativePosition = NULL);
+	void applyImpulse(const Vector3& impulse, const Vector3* relativePosition = NULL);
+	void applyTorque(const Vector3& torque);
+    void applyTorqueImpulse(const Vector3& torque);
+
+    inline void setFriction(float friction);
+    inline void setRestitution(float restitution);
+    inline void setAnisotropicFriction(const Vector3& friction);
+    inline void setGravity(const Vector3& gravity);
+	inline float getFriction();
+    inline float getRestitution();
+    inline Vector3 getAnisotropicFriction();
+    inline Vector3 getGravity();
+
+    inline void setLinearVelocity(const Vector3& velocity);
+	inline void setAngularVelocity(const Vector3& velocity);
+
+	inline Vector3 getLinearVelocity();
+	inline Vector3 getAngularVelocity();
+
+	inline void setDamping(float linearDamping, float angularDamping);
+	inline float getLinearDamping();
+	inline float getAngularDamping();
+
+private:
+
+	friend class Node;
+	friend class PhysicsMotionState;
+
+    PhysicsRigidBody(Node* node, PhysicsRigidBody::Type type, float mass, 
+		float friction = 0.5, float restitution = 0.0, float linearDamping = 0.0, float angularDamping = 0.0);
+    ~PhysicsRigidBody();
+
+    /**
+     * Private copy constructor to disallow copying.
+     */
+    PhysicsRigidBody(const PhysicsRigidBody& body) {}
+
+	static btRigidBody* createBulletRigidBody(btCollisionShape* shape, float mass, Node* node,
+        float friction, float restitution, float linearDamping, float angularDamping);
+
+	btRigidBody* _body;
+    Node* _node;
+};
+
+// Inline functions.
+
+void PhysicsRigidBody::setFriction(float friction)
+{
+    _body->setFriction(friction);
+}
+
+void PhysicsRigidBody::setRestitution(float restitution)
+{
+    _body->setRestitution(restitution);
+}
+
+float PhysicsRigidBody::getFriction()
+{
+    return _body->getFriction();
+}
+
+float PhysicsRigidBody::getRestitution()
+{
+    return _body->getRestitution();
+}
+
+void PhysicsRigidBody::setLinearVelocity(const Vector3& velocity)
+{
+	_body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
+}
+
+void PhysicsRigidBody::setAngularVelocity(const Vector3& velocity)
+{
+	_body->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z));
+}
+
+// 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?
+Vector3 PhysicsRigidBody::getLinearVelocity()
+{
+	const btVector3& v = _body->getLinearVelocity();
+	return Vector3(v.x(), v.y(), v.z());
+}
+
+Vector3 PhysicsRigidBody::getAngularVelocity()
+{
+	const btVector3& v = _body->getAngularVelocity();
+	return Vector3(v.x(), v.y(), v.z());
+}
+
+Vector3 PhysicsRigidBody::getAnisotropicFriction()
+{
+    const btVector3& af = _body->getAnisotropicFriction();
+    return Vector3(af.x(), af.y(), af.z());
+}
+
+Vector3 PhysicsRigidBody::getGravity()
+{
+    const btVector3& g = _body->getGravity();
+    return Vector3(g.x(), g.y(), g.z());
+}
+
+void PhysicsRigidBody::setDamping(float linearDamping, float angularDamping)
+{
+    _body->setDamping(linearDamping, angularDamping);
+}
+
+float PhysicsRigidBody::getLinearDamping()
+{
+	return _body->getLinearDamping();
+}
+
+float PhysicsRigidBody::getAngularDamping()
+{
+	return _body->getAngularDamping();
+}
+
+void PhysicsRigidBody::setAnisotropicFriction(const Vector3& friction)
+{
+    _body->setAnisotropicFriction(btVector3(friction.x, friction.y, friction.z));
+}
+
+void PhysicsRigidBody::setGravity(const Vector3& gravity)
+{
+    _body->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
+}
+
+}
+
+#endif

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

+ 277 - 0
gameplay/src/Tree.h

@@ -0,0 +1,277 @@
+/*
+ * Tree.h
+ */
+
+#ifndef TREE_H_
+#define TREE_H_
+
+namespace gameplay
+{
+
+/**
+ * Defines a class that provides a tree hierarchy, which includes
+ * a doubly linked list of siblings and a list of children.
+ *
+ * This class is intended to be extended rather than used as a stand-alone
+ * data structure (this is reflected by the protected constructor). Classes
+ * wishing to expose a tree-like structure may inherit this class. An example
+ * is the Node class, which extends Tree<Node> to provide support for nesting of
+ * nodes within nodes and tracking of parent/child relationships in a scene
+ * graph.
+ */
+template <class T>
+class Tree
+{
+public:
+
+    /**
+     * Adds a child to this item in the tree.
+     *
+     * @param child The child to add.
+     */
+    virtual void addChild(T* child);
+
+    /**
+     * Removes a child from this item in the tree.
+     *
+     * @param child The child to remove.
+     */
+    virtual void removeChild(T* child);
+
+    /**
+     * Removes all children under this item in the tree.
+     */
+    virtual void removeAllChildren();
+
+    /**
+     * Returns the first child for this item in the tree.
+     *
+     * @return The first child.
+     */
+    T* getFirstChild() const;
+
+    /**
+     * Returns the first sibling of this item in the tree.
+     *
+     * @return The first sibling.
+     */
+    T* getNextSibling() const;
+
+    /**
+     * Returns the previous sibling to this item in the tree.
+     *
+     * @return The previous sibling.
+     */
+    T* getPreviousSibling() const;
+
+    /**
+     * Returns the parent of this item in the tree.
+     *
+     * @return The parent.
+     */
+    T* getParent() const;
+
+    /**
+     * Returns the number of direct children of this item.
+     *
+     * @return The number of children.
+     */
+    unsigned int getChildCount() const;
+
+protected:
+
+    /**
+     * Constructor.
+     */
+    Tree();
+
+    /**
+     * Destructor.
+     */
+    virtual ~Tree();
+
+    /**
+     * Removes this item from its list.
+     */
+    void remove();
+
+    /**
+     * Called when a child is added to this item in the tree.
+     * 
+     * @param child The child that was added.
+     */
+    virtual void childAdded(T* child);
+
+    /**
+     * Called when a child is removed from this item in the tree.
+     *
+     * @param child The child that was removed.
+     */
+    virtual void childRemoved(T* child);
+
+    /**
+     * Called when the parent of this item changes.
+     *
+     * @param oldParent The previous parent for this item.
+     */
+    virtual void parentChanged(T* oldParent);
+
+    T* _firstChild;
+    T* _nextSibling;
+    T* _prevSibling;
+    T* _parent;
+    unsigned int _childCount;
+};
+
+template <class T>
+Tree<T>::Tree()
+    : _firstChild(NULL), _nextSibling(NULL), _prevSibling(NULL), _parent(NULL), _childCount(0)
+{
+}
+
+template <class T>
+Tree<T>::~Tree()
+{
+    removeAllChildren();
+}
+
+template <class T>
+void Tree<T>::addChild(T* child)
+{
+    assert(child);
+
+    // If the item belongs to another hierarchy, remove it first.
+    T* parent = child->_parent;
+    if (parent)
+    {
+        parent->removeChild(child);
+    }
+
+    // Order is irrelevant, so add to the beginning of the list.
+    if (_firstChild)
+    {
+        _firstChild->_prevSibling = child;
+        child->_nextSibling = _firstChild;
+        _firstChild = child;
+    }
+    else
+    {
+        _firstChild = child;
+    }
+
+    child->_parent = static_cast<T*>(this);
+
+    ++_childCount;
+
+    // Fire events.
+    static_cast<Tree<T>*>(child)->parentChanged(parent);
+    childAdded(child);
+}
+
+template <class T>
+void Tree<T>::removeChild(T* child)
+{
+    if (child == NULL || child->_parent != this)
+    {
+        // The child is not in our hierarchy.
+        return;
+    }
+
+    // Call remove on the child.
+    static_cast<Tree<T>*>(child)->remove();
+}
+
+template <class T>
+void Tree<T>::removeAllChildren()
+{
+    while (_firstChild)
+    {
+        removeChild(_firstChild);
+    }
+}
+
+template <class T>
+void Tree<T>::remove()
+{
+    // Re-link our neighbours.
+    if (_prevSibling)
+    {
+        _prevSibling->_nextSibling = _nextSibling;
+    }
+    if (_nextSibling)
+    {
+        _nextSibling->_prevSibling = _prevSibling;
+    }
+
+    // Update our parent.
+    T* parent = _parent;
+    if (parent)
+    {
+        if (this == parent->_firstChild)
+        {
+            parent->_firstChild = _nextSibling;
+        }
+
+        --parent->_childCount;
+    }
+
+    _nextSibling = NULL;
+    _prevSibling = NULL;
+    _parent = NULL;
+
+    // Fire events.
+    if (parent)
+    {
+        parentChanged(parent);
+        static_cast<Tree<T>*>(parent)->childRemoved(static_cast<T*>(this));
+    }
+}
+
+template <class T>
+T* Tree<T>::getFirstChild() const
+{
+    return _firstChild;
+}
+
+template <class T>
+T* Tree<T>::getNextSibling() const
+{
+    return _nextSibling;
+}
+
+template <class T>
+T* Tree<T>::getPreviousSibling() const
+{
+    return _prevSibling;
+}
+
+template <class T>
+T* Tree<T>::getParent() const
+{
+    return _parent;
+}
+
+template <class T>
+unsigned int Tree<T>::getChildCount() const
+{
+    return _childCount;
+}
+
+template <class T>
+void Tree<T>::childAdded(T* child)
+{
+}
+
+template <class T>
+void Tree<T>::childRemoved(T* child)
+{
+}
+
+template <class T>
+void Tree<T>::parentChanged(T* oldParent)
+{
+}
+
+}
+
+#endif