Commits

Anonymous committed 31c1596

put the tokamak_1.0.5a to SVN Repositories

git-svn-id: https://tokamakp.svn.sourceforge.net/svnroot/tokamakp@159b4d5e5-9359-492d-972b-49872f59beb6

  • Participants

Comments (0)

Files changed (133)

File trunk/d3dapp/Car.exe

Binary file added.

File trunk/d3dapp/Car.vcproj

+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="Car"
+	ProjectGUID="{EE92B72B-0CBC-4962-8E12-64065F917D28}"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+		<Platform
+			Name="x64"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="../include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;PROFILE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="0"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderThrough="dxut\dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				AdditionalDependencies="tokamak_d.lib dxerr.lib dxguid.lib d3dx9d.lib d3d9.lib winmm.lib comctl32.lib Xinput.lib"
+				OutputFile="$(ProjectName)_d.exe"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="../lib"
+				GenerateDebugInformation="true"
+				ProgramDatabaseFile="$(OutDir)/d3dapp.pdb"
+				SubSystem="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				OmitFramePointers="true"
+				AdditionalIncludeDirectories="../include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				StringPooling="true"
+				ExceptionHandling="0"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderThrough="dxut\dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				AdditionalDependencies="tokamak.lib dxerr.lib dxguid.lib d3dx9.lib d3d9.lib winmm.lib comctl32.lib Xinput.lib"
+				OutputFile="$(ProjectName).exe"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="../lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Profile|Win32"
+			OutputDirectory="Profile"
+			IntermediateDirectory="Profile"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				OmitFramePointers="true"
+				AdditionalIncludeDirectories="../include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;PROFILE"
+				StringPooling="true"
+				ExceptionHandling="0"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderThrough="dxut\dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				OutputFile="$(ProjectName)_p.exe"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="../lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Debug|x64"
+			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\..\Common"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;PROFILE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="0"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				AdditionalDependencies="dxerr.lib dxguid.lib d3dx9d.lib d3d9.lib winmm.lib comctl32.lib"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				ProgramDatabaseFile="$(OutDir)/d3dapp.pdb"
+				SubSystem="2"
+				TargetMachine="17"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|x64"
+			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				OmitFramePointers="true"
+				AdditionalIncludeDirectories="..\..\Common"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				StringPooling="true"
+				ExceptionHandling="0"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				AdditionalDependencies="dxerr.lib dxguid.lib d3dx9.lib d3d9.lib winmm.lib comctl32.lib"
+				OutputFile="$(OutDir)/d3dapp.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="17"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Profile|x64"
+			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
+			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				OmitFramePointers="true"
+				AdditionalIncludeDirectories="..\..\Common"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;PROFILE"
+				StringPooling="true"
+				ExceptionHandling="0"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="dxstdafx.h"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/IGNORE:4089"
+				AdditionalDependencies="dxerr.lib dxguid.lib d3dx9.lib d3d9.lib winmm.lib comctl32.lib"
+				OutputFile="$(OutDir)/d3dapp.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="17"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+				EmbedManifest="false"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+			>
+			<File
+				RelativePath="d3dapp.manifest"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Profile|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|x64"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|x64"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Profile|x64"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="d3dapp.rc"
+				>
+			</File>
+			<File
+				RelativePath="..\..\Common\directx.ico"
+				>
+			</File>
+			<File
+				RelativePath="resource.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Common"
+			>
+			<File
+				RelativePath=".\dxut\dxstdafx.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\dxstdafx.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUT.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUT.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTenum.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTenum.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTgui.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTgui.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTMesh.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTMesh.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTmisc.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTmisc.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTRes.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTRes.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTSettingsDlg.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\dxut\DXUTSettingsDlg.h"
+				>
+			</File>
+		</Filter>
+		<File
+			RelativePath=".\car.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\d3dapp.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\tokamaksampleApp.cpp"
+			>
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

File trunk/d3dapp/Main.fx

+//--------------------------------------------------------------------------------------
+// File: ConfigSystem.fx
+//
+// The effect file for the ConfigSystem sample.  
+// 
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------------------------
+// Global variables
+//--------------------------------------------------------------------------------------
+matrix   g_mWorld;                  // World matrix for object
+matrix   g_mView;                   // View matrix for object
+matrix   g_mProj;                   // Projection matrix for object
+matrix   g_mWorldView;              // World * View matrix
+matrix   g_mWorldViewProj;          // World * View * Projection matrix
+texture  g_txScene;                 // texture for scene rendering
+float4   g_matDiffuse;              // Diffuse component of material
+float4   g_matSpecular;             // Specular component of material
+float    g_matPower;                // Specular power of material
+float4   g_vLightPos[4] = { float4(  3.5f, 1.0f,  5.5f, 1.0f ),
+                            float4( -3.5f, 1.0f, -5.5f, 1.0f ),
+                            float4(  3.5f, 1.0f, -5.5f, 1.0f ),
+                            float4( -3.5f, 1.0f,  5.5f, 1.0f ) };  // Light position in world space
+float4   g_vLightColor = float4( 0.5f, 0.5f, 0.5f, 1.0f );
+
+// These parameters will change based on the config flags.
+bool     g_bUseSpecular = true;
+bool     g_bUseAnisotropic = false;
+int      g_MinFilter = 2;           // Minification filtering
+int      g_MaxAnisotropy = 1;       // Maximum anisotropy
+
+float4 g_Ambient;
+float4 g_LightTokamak0;
+float4 g_LightTokamak1;
+float4 g_ViewPos;
+float4 g_LightColorTokamak0;
+float4 g_LightColorTokamak1;
+
+
+//-----------------------------------------------------------------------------
+// Texture samplers
+//-----------------------------------------------------------------------------
+sampler g_samScene =
+sampler_state
+{
+    Texture = <g_txScene>;
+    MinFilter = <g_MinFilter>;
+    MagFilter = Linear;
+    MipFilter = Linear;
+    MaxAnisotropy = <g_MaxAnisotropy>;
+};
+
+
+void VS20( float4 vPos : POSITION,
+           float3 vNormal : NORMAL,
+           float2 vTex0 : TEXCOORD0,
+           out float4 oPos : POSITION,
+           out float2 oTex0 : TEXCOORD0,
+           out float3 oVtE : TEXCOORD1,
+           out float3 oVNormal : TEXCOORD2,
+           out float3 oViewVtL0 : TEXCOORD3,
+           out float3 oViewVtL1 : TEXCOORD4,
+           out float3 oViewVtL2 : TEXCOORD5,
+           out float3 oViewVtL3 : TEXCOORD6 )
+{
+    oPos = mul( vPos, g_mWorldViewProj );
+
+    // Compute view space normal
+    oVNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
+
+    // Vertex pos in view space (normalize in pixel shader)
+    oVtE = -mul( vPos, g_mWorldView );
+
+    // Compute view space vertex to light vectors (normalized)
+    oViewVtL0 = normalize( mul( g_vLightPos[0], g_mView ) + oVtE );
+    oViewVtL1 = normalize( mul( g_vLightPos[1], g_mView ) + oVtE );
+    oViewVtL2 = normalize( mul( g_vLightPos[2], g_mView ) + oVtE );
+    oViewVtL3 = normalize( mul( g_vLightPos[3], g_mView ) + oVtE );
+
+    // Propogate texcoords
+    oTex0 = vTex0;
+}
+
+float4 PS20( float2 Tex0 : TEXCOORD0,
+             float3 VtE : TEXCOORD1,
+             float3 N : TEXCOORD2,
+             float3 VtL0 : TEXCOORD3,
+             float3 VtL1 : TEXCOORD4,
+             float3 VtL2 : TEXCOORD5,
+             float3 VtL3 : TEXCOORD6 ) : COLOR0
+{
+    // Diffuse luminance
+    float LumD = max( 0.0f, dot( N, VtL0 ) ) +
+                 max( 0.0f, dot( N, VtL1 ) ) +
+                 max( 0.0f, dot( N, VtL2 ) ) +
+                 max( 0.0f, dot( N, VtL3 ) );
+
+    // Normalize view space vertex-to-eye
+    VtE = normalize( VtE );
+
+    // Specular luminance
+    float LumS = pow( max( 0.0f, dot( N, normalize( VtE + VtL0 ) ) ), g_matPower ) +
+                 pow( max( 0.0f, dot( N, normalize( VtE + VtL1 ) ) ), g_matPower ) +
+                 pow( max( 0.0f, dot( N, normalize( VtE + VtL2 ) ) ), g_matPower ) +
+                 pow( max( 0.0f, dot( N, normalize( VtE + VtL3 ) ) ), g_matPower );
+
+    float Specular;
+    if( g_bUseSpecular )
+        Specular = g_matSpecular * LumS * g_vLightColor;
+    else
+        Specular = 0.0f;
+
+    return tex2D( g_samScene, Tex0 ) * g_matDiffuse * LumD * g_vLightColor + Specular;
+}
+
+
+void VS( float4 vPos : POSITION,
+         float3 vNormal : NORMAL,
+         float2 vTex0 : TEXCOORD0,
+         out float4 oDiffuse : COLOR0,
+         out float4 oSpecular : COLOR1,
+         out float4 oPos : POSITION,
+         out float2 oTex0 : TEXCOORD0 )
+{
+    oPos = mul( vPos, g_mWorldViewProj );
+
+    // Compute view space normal
+    float3 N = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
+
+    // Vertex pos in view space
+    float3 Vv = mul( vPos, g_mWorldView );
+
+    float LumD = 0.0f;  // Diffuse luminance
+    float LumS = 0.0f;  // Specular luminance
+    for( int i = 0; i < 4; ++i )
+    {
+        // Light pos in view space
+        float3 Lv = mul( g_vLightPos[i], g_mView );
+
+        // View space vertex-to-light
+        float3 VtL = normalize( Lv - Vv );
+
+        LumD += max( 0.0f, dot( N, VtL ) );
+
+        // View space vertex-to-eye
+        float3 VtE = normalize( -Vv );
+
+        // Half vector
+        float3 H = normalize( VtE + VtL );
+
+        LumS += pow( max( 0.0f, dot( N, H ) ), 40.0f ); // This power is hardcoded to not exceed inst limit.
+    }
+
+    oDiffuse = g_matDiffuse * LumD * g_vLightColor;
+    if( g_bUseSpecular )
+        oSpecular = g_matSpecular * LumS * g_vLightColor;
+    else
+        oSpecular = 0.0f;
+
+    oTex0 = vTex0;
+}
+
+
+float4 PS( float4 Diffuse : COLOR0,
+           float4 Specular : COLOR1,
+           float2 Tex0 : TEXCOORD0 ) : COLOR0
+{
+    return tex2D( g_samScene, Tex0 ) * Diffuse + Specular;
+}
+
+void VS_Tokamak( float4 vPos : POSITION,
+		         float3 vNormal : NORMAL,
+         
+         out float3 oNormal : TEXCOORD0,
+         out float3 oView : TEXCOORD1,
+         out float4 oPos : POSITION)
+{
+	oPos = mul( vPos, g_mWorldViewProj );
+	
+	oNormal = mul(vNormal, g_mWorld);
+	
+	float3 worldPos = mul(vPos, g_mWorld);
+	
+	oView = g_ViewPos - worldPos;
+}
+
+float4 GetReflection(float3 Normal, float3 View, float3 LightDir, float3 LightColor)
+{
+	float ndotl = saturate(dot(Normal, LightDir));
+	
+	float3 reflection = 2.0f * dot(Normal, LightDir) * Normal - LightDir;
+	
+	float reflection_dot_view = dot(reflection, View);
+	
+	return float4(ndotl * LightColor, reflection_dot_view);
+}
+
+float4 PS_Tokamak(	float3 Normal : TEXCOORD0,
+					float3 View : TEXCOORD1) : COLOR0
+{
+	float4 ret;
+	
+	Normal = normalize(Normal);
+	View = normalize(View);
+	
+	float4 light0 = GetReflection(Normal, View, g_LightTokamak0, g_LightColorTokamak0);
+	
+	float4 light1 = GetReflection(Normal, View, g_LightTokamak1, g_LightColorTokamak1);
+		
+	float3 specular = g_matSpecular * pow(light0.w, g_matPower);
+	
+	specular += g_matSpecular * pow(light1.w, g_matPower);
+	
+	ret.rgb = g_matDiffuse.rgb * saturate(light0.xyz + light1.xyz) + specular.rgb;
+	
+	ret.a = g_matDiffuse.a;
+	
+    return ret;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Techniques
+//--------------------------------------------------------------------------------------
+technique RenderSceneTokamak
+{
+    pass P0
+    {
+        VertexShader = compile vs_2_0 VS_Tokamak();
+        PixelShader = compile ps_2_0 PS_Tokamak();
+    }
+}
+
+technique RenderScenePS30
+{
+    pass P0
+    {
+        VertexShader = compile vs_3_0 VS20();
+        PixelShader = compile ps_3_0 PS20();
+    }
+}
+
+
+technique RenderScenePS20A
+{
+    pass P0
+    {
+        VertexShader = compile vs_2_0 VS20();
+        PixelShader = compile ps_2_a PS20();
+    }
+}
+
+
+technique RenderScenePS20B
+{
+    pass P0
+    {
+        VertexShader = compile vs_2_0 VS20();
+        PixelShader = compile ps_2_b PS20();
+    }
+}
+
+
+technique RenderScenePS20
+{
+    pass P0
+    {
+        VertexShader = compile vs_2_0 VS20();
+        PixelShader = compile ps_2_0 PS20();
+    }
+}
+
+
+technique RenderScenePS14
+{
+    pass P0
+    {
+        VertexShader = compile vs_1_1 VS();
+        PixelShader = compile ps_1_4 PS();
+    }
+}
+
+
+technique RenderScenePS13
+{
+    pass P0
+    {
+        VertexShader = compile vs_1_1 VS();
+        PixelShader = compile ps_1_3 PS();
+    }
+}
+
+
+technique RenderScenePS12
+{
+    pass P0
+    {
+        VertexShader = compile vs_1_1 VS();
+        PixelShader = compile ps_1_2 PS();
+    }
+}
+
+
+technique RenderScenePS11
+{
+    pass P0
+    {
+        VertexShader = compile vs_1_1 VS();
+        PixelShader = compile ps_1_1 PS();
+    }
+}
+
+
+technique FFRenderScene
+{
+    pass P0
+    {
+        VertexShader = null;
+        PixelShader = null;
+
+        WorldTransform[0] = <g_mWorld>;
+        ViewTransform = <g_mView>;
+        ProjectionTransform = <g_mProj>;
+
+        Texture[0] = <g_txScene>;
+        MinFilter[0] = <g_MinFilter>;
+        MaxAnisotropy[0] = <g_MaxAnisotropy>;
+        MagFilter[0] = Linear;
+        MipFilter[0] = Linear;
+        AddressU[0] = Wrap;
+        AddressV[0] = Wrap;
+        AddressW[0] = Wrap;
+        ColorArg1[0] = Texture;
+        ColorArg2[0] = Current;
+        ColorOp[0] = Modulate;
+
+        Lighting = True;
+        LightEnable[0] = True;
+//        LightAmbient[0] = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        LightType[0] = Point;
+        LightPosition[0] = <g_vLightPos[0]>;
+        LightRange[0] = 100.0f;
+        LightDiffuse[0] = <g_vLightColor>;
+        LightSpecular[0] = <g_vLightColor>;
+        LightAttenuation0[0] = 1.0f;
+        LightAttenuation1[0] = 0.0f;
+        LightAttenuation2[0] = 0.0f;
+        LightEnable[1] = True;
+//        LightAmbient[1] = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        LightType[1] = Point;
+        LightPosition[1] = <g_vLightPos[1]>;
+        LightRange[1] = 100.0f;
+        LightDiffuse[1] = <g_vLightColor>;
+        LightSpecular[1] = <g_vLightColor>;
+        LightAttenuation0[1] = 1.0f;
+        LightAttenuation1[1] = 0.0f;
+        LightAttenuation2[1] = 0.0f;
+        LightEnable[2] = True;
+//        LightAmbient[2] = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        LightType[2] = Point;
+        LightPosition[2] = <g_vLightPos[2]>;
+        LightRange[2] = 100.0f;
+        LightDiffuse[2] = <g_vLightColor>;
+        LightSpecular[2] = <g_vLightColor>;
+        LightAttenuation0[2] = 1.0f;
+        LightAttenuation1[2] = 0.0f;
+        LightAttenuation2[2] = 0.0f;
+        LightEnable[3] = True;
+//        LightAmbient[3] = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        LightType[3] = Point;
+        LightPosition[3] = <g_vLightPos[3]>;
+        LightRange[3] = 100.0f;
+        LightDiffuse[3] = <g_vLightColor>;
+        LightSpecular[3] = <g_vLightColor>;
+        LightAttenuation0[3] = 1.0f;
+        LightAttenuation1[3] = 0.0f;
+        LightAttenuation2[3] = 0.0f;
+
+        NormalizeNormals = true;
+
+        SpecularEnable = <g_bUseSpecular>;
+        Ambient = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        DiffuseMaterialSource = Material;
+        SpecularMaterialSource = Material;
+        MaterialAmbient = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        MaterialDiffuse = <g_matDiffuse>;
+        MaterialEmissive = float4( 0.0f, 0.0f, 0.0f, 0.0f );
+        MaterialSpecular = <g_matSpecular>;
+        MaterialPower = <g_matPower>;
+    }
+}

File trunk/d3dapp/RadDude.exe

Binary file added.

File trunk/d3dapp/car.cpp

+#include "dxut\dxstdafx.h"
+#include "resource.h"
+#include "d3dapp.h"
+#include "tokamaksampleApp.h"
+
+const s32 WALL_NUMBER = 1;
+
+#define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE  7849
+#define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
+#define XINPUT_GAMEPAD_TRIGGER_THRESHOLD    30
+
+D3DXHANDLE g_hShaderTechTokamak;
+
+D3DXVECTOR4 vLightWorld[NUM_LIGHT] = {	D3DXVECTOR4(1.f,2.f,1.f,0.f),
+										D3DXVECTOR4(-1.f,1.f,1.f,0.f)};
+
+D3DXVECTOR4 vLightColor[NUM_LIGHT] = {	D3DXVECTOR4(0.7f,0.7f,0.7f,0.f),
+										D3DXVECTOR4(0.5f,0.5f,0.5f,0.f)};
+
+const D3DXVECTOR3 g_MinBound( -4.0f, -GROUND_Y, -6.0f );
+const D3DXVECTOR3 g_MaxBound( 4.0f, GROUND_Y, 6.0f );
+
+struct DemoData
+{
+	neV3 pos;
+	neV3 boxSize;
+	neV3 colour;
+};
+
+DemoData gFloor = {	{0.0f,-11.0f,0.0f}, {200.0f,2.0f,200.0f}, {0.3f,0.3f,0.6f}};
+
+#define N_BARRIERS 4
+
+DemoData gBarriers[N_BARRIERS] = {	{{0.0f,-11.0f,-100.0f}, {200.0f,5.0f,2.0f}, {0.3f,0.3f,0.6f}},
+							{{0.0f,-11.0f,100.0f}, {200.0f,5.0f,2.0f}, {0.3f,0.3f,0.6f}},
+							{{-100.0f,-11.0f,0.0f}, {2.0f,5.0f,200.0f}, {0.3f,0.3f,0.6f}},
+							{{100.0f,-11.0f,0.0f}, {2.0f,5.0f,200.0f}, {0.3f,0.3f,0.6f}}};
+
+#define N_RAMPS 4
+
+struct RampData
+{
+	neV3 pos;
+	neV3 boxSize;
+	neV3 colour;
+	neV3 angle;
+};
+
+RampData gRamps[N_RAMPS] = {
+							{{-40.0f,-12.0f,-50.0f}, {30.0f,2.0f,30.0f}, {0.3f,0.3f,0.6f}, {0.0f,0.0f,NE_PI * 0.07f}},
+							{{50.0f,-12.0f,30.0f}, {30.0f,2.0f,30.0f}, {0.3f,0.3f,0.6f}, {-NE_PI * 0.07f,0.0f,0.0f}},
+							{{-30.0f,-12.0f,50.0f}, {30.0f,2.0f,30.0f}, {0.3f,0.3f,0.6f}, {0.0f,0.0f,-NE_PI * 0.07f}},
+							{{50.0f,-12.0f,-30.0f}, {30.0f,2.0f,30.0f}, {0.3f,0.3f,0.6f}, {-NE_PI * 0.07f,0.0f,0.0f}}
+};
+
+const s32 N_CARS = 10;
+//		TARGET_CAR = 0,
+const s32 N_BODY_BOXES = 2;
+const s32 N_PARTS = 3;
+const s32 N_RENDER_PRIMITIVES = (N_BODY_BOXES + N_PARTS);
+const s32 MAX_OVERLAPPED_PAIR = 1000;
+const f32 WHEEL_DIAMETER = 0.9f;
+const f32 WHEEL_WIDTH = 0.3f;
+const f32 MAX_SPEED = 5.0f;
+const f32 MAX_REVERSE_SPEED = -2.0f;
+const f32 MAX_STEER = 0.7f;
+const f32 MAX_SLIDE = 0.8f;
+
+struct SensorData
+{
+	neV3 pos;
+};
+
+SensorData sensorData[4] = 
+{
+	{2.0f, 0.0f, 1.5f},
+	{2.0f, 0.0f, -1.5f},
+	{-2.0f, 0.0f, 1.5f},
+	{-2.0f, 0.0f, -1.5f},
+};
+
+class CControllerCB: public neRigidBodyControllerCallback
+{
+public:
+	
+	void RigidBodyControllerCallback(neRigidBodyController * controller, float timeStep);
+};
+
+CControllerCB cb;
+
+class CSampleCar;
+
+class CCar
+{
+public:
+	void MakeCar(neSimulator * sim, neV3 & pos);
+
+	void MakeParts(neSimulator * sim, neV3 & pos);
+
+	void CarController(neRigidBodyController * controller);
+
+	void Process(XINPUT_STATE &);
+
+	CRenderPrimitive * AddRenderPrimitive()
+	{
+		return &carRenderPrimitives[nextRenderPrim++];
+	}
+
+public:
+	CCar()
+	{
+		id = -1;
+
+		accel = 0.0f;
+
+		steer = 0.0f;
+
+		slide = 0.0f;
+
+		gameWorld = NULL;
+
+		nextRenderPrim = 0;
+	}
+
+	neRigidBody * carRigidBody;
+
+	neRigidBody * carParts[N_PARTS];
+	
+	CRenderPrimitive carRenderPrimitives[N_RENDER_PRIMITIVES];
+
+	CRenderPrimitive wheelRenderPrimitive;
+
+	neV3 displayLines[4][2];
+
+	f32 suspensionLength[4];
+
+	CSampleCar * gameWorld;
+
+	s32 id;
+	
+	f32 accel;
+
+	f32 steer;
+
+	f32 slide;
+
+	neV3 steerDir;
+
+	s32 nextRenderPrim;
+};
+
+class CSampleCar
+{
+public:
+	neSimulator * sim;
+	neAllocatorDefault allocator;
+	nePerformanceReport perfReport;
+
+	CRenderPrimitive groundRender;
+	neAnimatedBody * ground;
+
+	CRenderPrimitive barrierRenders[N_BARRIERS];
+	neAnimatedBody * barriers[N_BARRIERS];
+
+	CRenderPrimitive rampRenders[N_RAMPS];
+	neAnimatedBody * ramps[N_RAMPS];
+
+	CCar cars[N_CARS];
+
+public:
+	CSampleCar() : sim(NULL) {};
+	
+	void CreateSimulator();
+	
+	void CreateGround();
+	
+	void Reset();
+
+	void Cleanup();
+};
+
+CSampleCar sample;
+
+void CSampleCar::CreateSimulator()
+{
+	if (sim)
+	{
+		neSimulator::DestroySimulator(sim);
+
+		sim = NULL;
+	}
+	// creat the physics simulation
+
+	neSimulatorSizeInfo sizeInfo;
+
+	sizeInfo.rigidBodiesCount = (N_PARTS + 1) * N_CARS;
+	sizeInfo.animatedBodiesCount = WALL_NUMBER + N_RAMPS + N_BARRIERS + 1;
+	sizeInfo.geometriesCount = (N_RENDER_PRIMITIVES + 1) * N_CARS + WALL_NUMBER;
+	sizeInfo.overlappedPairsCount = MAX_OVERLAPPED_PAIR;
+	{ //dont need any of these
+		sizeInfo.rigidParticleCount = 0;
+		sizeInfo.terrainNodesStartCount = 200;
+	}
+	neV3 gravity; gravity.Set(0.0f, -8.0f, 0.0f);
+
+	sim = neSimulator::CreateSimulator(sizeInfo, &allocator, &gravity);
+}
+
+void CSampleCar::CreateGround()
+{
+	ground = sim->CreateAnimatedBody();
+
+	neGeometry * geom = ground->AddGeometry();	 
+
+	geom->SetBoxSize(gFloor.boxSize);
+
+	ground->UpdateBoundingInfo();
+
+	ground->SetPos(gFloor.pos);
+
+	groundRender.SetGraphicBox(gFloor.boxSize[0], gFloor.boxSize[1], gFloor.boxSize[2]);
+
+	for (s32 i = 0; i < N_BARRIERS; i++)
+	{
+		barriers[i] = sim->CreateAnimatedBody();
+
+		geom = barriers[i]->AddGeometry();	 
+
+		geom->SetBoxSize(gBarriers[i].boxSize);
+
+		barriers[i]->UpdateBoundingInfo();
+
+		barriers[i]->SetPos(gBarriers[i].pos);
+
+		barrierRenders[i].SetGraphicBox(gBarriers[i].boxSize[0], gBarriers[i].boxSize[1], gBarriers[i].boxSize[2]);
+
+		barrierRenders[i].SetDiffuseColor(D3DXCOLOR(0.6f, 0.8f, 0.5f, 1));
+	}
+
+	for (s32 i = 0; i < N_RAMPS; i++)
+	{
+		ramps[i] = sim->CreateAnimatedBody();
+
+		geom = ramps[i]->AddGeometry();	 
+
+		geom->SetBoxSize(gRamps[i].boxSize);
+
+		ramps[i]->UpdateBoundingInfo();
+
+		ramps[i]->SetPos(gRamps[i].pos);
+
+		neM3 rot; rot.RotateXYZ(gRamps[i].angle);
+
+		ramps[i]->SetRotation(rot);
+
+		rampRenders[i].SetGraphicBox(gRamps[i].boxSize[0], gRamps[i].boxSize[1], gRamps[i].boxSize[2]);
+
+		rampRenders[i].SetDiffuseColor(D3DXCOLOR(0.6f, 0.2f, 0.8f, 1));
+	}
+}
+
+void CSampleCar::Reset()
+{
+	Cleanup();
+
+	// reset the camera position
+	D3DXVECTOR3 vecEye (30.0f, 12.0f, 40.0f);//(0.0f, -GROUND_Y + 1.7f, 0.0f);
+	D3DXVECTOR3 vecAt (0.0f, 0.0f, 1.0f);//(0.0f, -GROUND_Y + 1.7f, 1.0f);
+	g_Camera.SetViewParams( &vecEye, &vecAt );
+
+	CreateSimulator();
+
+	CreateGround();
+
+	neV3 carPos;
+
+	carPos.Set(0.0f, -1.0f, 10.0f);
+
+	for (int i = 0; i < N_CARS; i++)
+	{
+		cars[i].id = i;
+		
+		cars[i].MakeCar(sim, carPos);
+
+		carPos[0] -= 7;
+	}
+}
+
+void CSampleCar::Cleanup()
+{
+	sample.groundRender.mMesh.Destroy();
+
+	for (s32 i = 0; i < N_BARRIERS; i++)
+		sample.barrierRenders[i].mMesh.Destroy();
+
+	for (s32 i = 0; i < N_RAMPS; i++)
+		sample.rampRenders[i].mMesh.Destroy();
+
+	for (s32 i = 0; i < N_CARS; i++)
+	{
+		sample.cars[i].wheelRenderPrimitive.mMesh.Destroy();
+
+		for (s32 j = 0; j < N_RENDER_PRIMITIVES; j++)
+		{
+			sample.cars[i].carRenderPrimitives[j].mMesh.Destroy();
+		}
+	}
+
+	neSimulator::DestroySimulator(sample.sim);
+
+	sim = NULL;
+}
+
+void CCar::MakeCar(neSimulator * sim, neV3 & pos)
+{
+	f32 mass = 1.0f;
+
+	neRigidBody * rigidBody = sim->CreateRigidBody();
+
+//	rigidBody->SetSleepingParameter(0.01f);
+
+	rigidBody->CollideConnected(true);
+
+	neGeometry * geom = rigidBody->AddGeometry();
+
+	neV3 boxSize; 
+	{
+		// the car consist of two boxes
+
+		boxSize.Set(6.0f, 1.0f, 3.2f);
+
+		geom->SetBoxSize(boxSize);
+
+		neT3 t; 
+		
+		t.SetIdentity();
+
+		t.pos.Set(0.0f, 0.25f, 0.0f);
+
+		geom->SetTransform(t);
+
+		geom = rigidBody->AddGeometry();
+
+		boxSize.Set(2.5f, 1.0f, 2.8f);
+
+		geom->SetBoxSize(boxSize[0],boxSize[1],boxSize[2]);
+
+		t.pos.Set(-0.6f, 1.0f, 0.0f);
+
+		geom->SetTransform(t);
+	}
+	{ // add 4 sensors to the rigid body
+		neSensor * sn;
+		
+		for (s32 si = 0; si < 4; si++)
+		{
+			sn =rigidBody->AddSensor();
+
+			neV3 snPos, snDir;
+
+			snDir.Set(0.0f, -1.0f, 0.0f);
+
+			snPos.Set(sensorData[si].pos);
+
+			sn->SetLineSensor(snPos, snDir);
+		}
+
+		// add a controller to the rigid body
+
+		neRigidBodyController * controller; 
+
+		controller = rigidBody->AddController(&cb, 0);
+	}
+
+	neV3 tensorSize;
+
+	tensorSize = boxSize;
+
+	rigidBody->UpdateBoundingInfo();
+	
+	rigidBody->SetInertiaTensor(neBoxInertiaTensor(tensorSize, mass));
+
+	rigidBody->SetMass(mass);
+
+	rigidBody->SetUserData((u32)this);
+
+	carRigidBody = rigidBody;
+
+	{ // setup the display boxes for the car
+
+		s32 i = 0;
+		
+		rigidBody->BeginIterateGeometry();
+
+		while (geom = rigidBody->GetNextGeometry())
+		{
+			//neSimpleToken * token = gw.MakeToken(geom);
+
+			//token->SetDiffuseColour(neV4(0.2f, 0.2f, 0.8f, 1.0f));
+
+			//token->SetAmbientColour(neV4(0.0f, 0.2f, 0.3f, 1.0f));
+
+			neV3 boxSize;
+			
+			geom->GetBoxSize(boxSize);
+
+			CRenderPrimitive * renderPrim = AddRenderPrimitive();
+
+			renderPrim->SetGraphicBox(boxSize[0], boxSize[1], boxSize[2]);
+
+			geom->SetUserData((u32)renderPrim);
+
+			renderPrim->SetDiffuseColor(D3DXCOLOR(0.2f, 0.2f, 0.8f, 1));
+		}
+	}
+
+	wheelRenderPrimitive.SetGraphicCylinder(WHEEL_DIAMETER * 0.5f, WHEEL_WIDTH);
+
+	// set the car position
+	
+	carRigidBody->SetPos(pos);
+
+	// add bonnet to the car
+
+	MakeParts(sim, pos);
+}
+
+struct PartData
+{
+	neV3 boxSize;
+	neV3 position;
+	neV3 jointPos;
+	neV3 jointRot;
+	f32 lowerLimit;
+	f32 upperLimit;
+};
+
+PartData parts[] =
+{
+	{	// Bonet
+		{2.0f, 0.1f, 3.0f},
+		{1.65f, 0.8f, 0.0f},
+		{0.65f, 0.8f, 0.0f},
+		{NE_PI * 0.5f, 0.0f, 0.0f},
+		0.0f,
+		NE_PI * 0.4f,
+	},
+	{	//Left Door
+		{2.0f, 0.8f, 0.1f},
+		{-0.2f, 0.25f, 1.6f},
+		{0.65f, 0.25f, 1.6f},
+		{0.0f, 0.0f, 0.0f},
+		0.0f,
+		NE_PI * 0.4f,
+	},
+	{	//Right Door
+		{2.0f, 0.8f, 0.1f},
+		{-0.2f, 0.25f, -1.6f},
+		{0.65f, 0.25f, -1.6f},
+		{0.0f, 0.0f, 0.0f},
+		-NE_PI * 0.4f,
+		0.0f,
+	},
+};
+
+void CCar::MakeParts(neSimulator * sim, neV3 & pos)
+{
+	s32 i;
+
+	for (i = 0; i < N_PARTS; i++)
+	{
+		neRigidBody * rb = sim->CreateRigidBody();
+
+		if (id == 0 ) //make it harder to sleep
+			rb->SetSleepingParameter(0.1f);
+
+		rb->SetPos(parts[i].position + pos);
+
+		neGeometry * geom = rb->AddGeometry();
+
+		geom->SetBoxSize(parts[i].boxSize);
+
+		rb->SetMass(0.01f);
+
+		rb->UpdateBoundingInfo();
+
+		rb->SetInertiaTensor(neBoxInertiaTensor(parts[i].boxSize, 0.01f));
+
+		neJoint * joint = sim->CreateJoint(rb, carRigidBody);
+
+		neT3 trans;
+
+		trans.pos = parts[i].jointPos + pos;
+
+		trans.rot.RotateXYZ(parts[i].jointRot);
+
+		joint->SetJointFrameWorld(trans);
+
+		joint->SetType(neJoint::NE_JOINT_HINGE);
+
+		joint->SetLowerLimit(parts[i].lowerLimit);
+
+		joint->SetUpperLimit(parts[i].upperLimit);
+
+		joint->SetEpsilon(0.0f);
+
+		joint->SetIteration(4);
+
+		joint->EnableLimit(true);
+
+		joint->Enable(true);
+
+		carParts[i] = rb;
+
+		CRenderPrimitive * renderPrim = AddRenderPrimitive();
+
+		renderPrim->SetGraphicBox(parts[i].boxSize[0], parts[i].boxSize[1], parts[i].boxSize[2]);
+
+		geom->SetUserData((u32)renderPrim);
+	}
+}
+
+void MyAppInit()
+{
+    // TODO: Perform any application-level initialization here
+    // Setup the camera
+    D3DXVECTOR3 MinBound( g_MinBound.x + CAMERA_SIZE, g_MinBound.y + CAMERA_SIZE, g_MinBound.z + CAMERA_SIZE );
+    D3DXVECTOR3 MaxBound( g_MaxBound.x - CAMERA_SIZE, g_MaxBound.y - CAMERA_SIZE, g_MaxBound.z - CAMERA_SIZE );
+
+    g_Camera.SetEnableYAxisMovement( true );
+    g_Camera.SetRotateButtons( false, false, true );
+    g_Camera.SetScalers( 0.01f, 50.0f );
+    D3DXVECTOR3 vecEye (0.0f, 0.0f, -10.0f);//(0.0f, -GROUND_Y + 1.7f, 0.0f);
+    D3DXVECTOR3 vecAt (0.0f, 0.0f, 1.0f);//(0.0f, -GROUND_Y + 1.7f, 1.0f);
+    g_Camera.SetViewParams( &vecEye, &vecAt );
+
+	for (s32 i = 0; i < NUM_LIGHT; i++)
+		D3DXVec4Normalize(&vLightWorld[i], &vLightWorld[i]);
+
+//	OnMyAppDestroyDevice(g_pD3dDevice);
+
+	sample.Reset();
+};
+
+void CALLBACK OnMyAppFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
+{
+	f32 t = 1.0f / 30.0f;//(f32)delta / 1000.0f;
+
+	//sim->Advance(TIME_STEP, 1, &g_PerfReport);
+	sample.sim->Advance(t, 1.0f / 30.0f, 1.0f/ 30.0f, NULL);
+
+	D3DXVECTOR3 vecEye (30.0f, 12.0f, 40.0f);
+	
+	neV3 v = sample.cars[0].carRigidBody->GetPos();
+	D3DXVECTOR3 vecAt(v[0], v[1], v[2]);
+
+	D3DXVECTOR3 offset(0.0f, 0.0f, 80.0f);
+
+	vecEye = vecAt + offset;
+
+	vecEye[1] = 40.0f;
+
+	g_Camera.SetViewParams( &vecEye, &vecAt );
+
+	DWORD dwResult;    
+
+	XINPUT_STATE state;
+
+	ZeroMemory( &state, sizeof(XINPUT_STATE) );
+
+	// Simply get the state of the controller from XInput.
+	dwResult = XInputGetState( 0, &state );
+
+	//if( dwResult == ERROR_SUCCESS )
+	{ 
+		// Controller is connected 
+		sample.cars[0].Process(state);
+	}
+}
+
+void CALLBACK OnMyAppFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
+{
+	neT3 t;
+	
+	t = sample.ground->GetTransform();
+
+	t.MakeD3DCompatibleMatrix();
+
+    sample.groundRender.Render(pd3dDevice, &t);
+
+	for (s32 i = 0; i < N_BARRIERS; i++)
+	{
+		t = sample.barriers[i]->GetTransform();
+
+		t.MakeD3DCompatibleMatrix();
+
+		sample.barrierRenders[i].Render(pd3dDevice, &t);
+	}
+
+	for (s32 i = 0; i < N_RAMPS; i++)
+	{
+		t = sample.ramps[i]->GetTransform();
+
+		t.MakeD3DCompatibleMatrix();
+
+		sample.rampRenders[i].Render(pd3dDevice, &t);
+	}
+
+	for (s32 i = 0; i < N_CARS; i++)
+	{
+		CCar * car = &sample.cars[i];
+
+		t = car->carRigidBody->GetTransform();
+
+		car->carRigidBody->BeginIterateGeometry();
+
+		while (neGeometry * geom = car->carRigidBody->GetNextGeometry())
+		{
+			neT3 t2 = geom->GetTransform();
+
+			neT3 t3 = t * t2;
+
+			t3.MakeD3DCompatibleMatrix();
+
+			CRenderPrimitive * rp = (CRenderPrimitive *)geom->GetUserData();
+
+			rp->Render(pd3dDevice, &t3);
+		}
+
+		for (s32 j = 0; j < N_PARTS; j++)
+		{
+			t = car->carParts[j]->GetTransform();
+
+			t.MakeD3DCompatibleMatrix();
+
+			car->carParts[j]->BeginIterateGeometry();
+
+			neGeometry * geom = car->carParts[j]->GetNextGeometry();
+
+			CRenderPrimitive * rp = (CRenderPrimitive *)geom->GetUserData();
+
+			rp->Render(pd3dDevice, &t);
+		}
+
+		for (s32 j = 0; j < 4; j++)
+		{
+			//GETDISPLAY->DrawLine(2, colour, &displayLines[i][0]);
+
+			neT3 wheel2World, suspension2Body, tire2Suspension, cylinder2Tire;
+
+			suspension2Body.SetIdentity();
+
+			suspension2Body.pos.Set(0.0f, -car->suspensionLength[j] + WHEEL_DIAMETER / 2.0f, 0.0f);
+
+			suspension2Body.pos += sensorData[j].pos;
+
+			cylinder2Tire.SetIdentity();
+
+			neV3 rot; rot.Set(NE_PI * 0.5f, 0.0f, 0.0f);
+
+			cylinder2Tire.rot.RotateXYZ(rot);
+
+			tire2Suspension.SetIdentity();
+
+			if (j == 0 || j == 1)
+			{
+				rot.Set(0.0f, car->steer, 0.0f);
+
+				tire2Suspension.rot.RotateXYZ(rot);
+			}
+
+			wheel2World = car->carRigidBody->GetTransform() * suspension2Body * tire2Suspension * cylinder2Tire;
+
+			if (j == 0 || j == 1)
+			{
+				car->steerDir = wheel2World.rot[0];
+			}
+			wheel2World.MakeD3DCompatibleMatrix();
+
+			car->wheelRenderPrimitive.Render(pd3dDevice, &wheel2World);
+		}
+	}
+
+	WCHAR * str[2];
+	
+	str[0] = L"Tokamak Car Sample";
+	str[1] = L"";
+
+	MyRenderText(str, 2);
+}
+
+LRESULT CALLBACK MyAppMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 
+                      bool* pbNoFurtherProcessing, void* pUserContext )
+{
+	return 0;
+}
+
+void CALLBACK OnMyAppDestroyDevice( void* pUserContext )
+{
+	SAFE_RELEASE( g_pEffect );
+
+	sample.Cleanup();
+}
+
+void CALLBACK MyAppKeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext )
+{
+	if( bKeyDown )
+	{
+		 switch( nChar )
+		 {
+		 case 'R':
+			 {
+				//OnMyAppDestroyDevice(g_pD3dDevice);
+
+				sample.Reset();
+			 }
+			 break;
+
+		 default:
+			 break;
+		 }
+	}
+}
+
+void CControllerCB::RigidBodyControllerCallback(neRigidBodyController * controller, float timeStep)
+{
+	neRigidBody * rb = controller->GetRigidBody();
+
+	CCar * car = (CCar *)(rb->GetUserData());
+
+	car->CarController(controller);
+}
+
+void CCar::CarController(neRigidBodyController * controller)
+{
+	neT3 body2World = carRigidBody->GetTransform();
+
+	carRigidBody->BeginIterateSensor();
+
+	neSensor * sn;
+
+	neV3 force, torque;
+
+	force.SetZero();
+
+	torque.SetZero();
+
+	s32 i = 0;
+
+	while (sn = carRigidBody->GetNextSensor())
+	{
+		f32 k = 15.0f; //spring constant
+
+		f32 u = 3.f; //damping constant
+
+		if (i == 2 || i == 3)
+		{
+			k = 10.0f;
+		}
+
+		// add spring force
+
+		f32 depth = sn->GetDetectDepth();
+
+		//gw.car.suspensionLength[i] = 1.0f - depth;
+		suspensionLength[i] = 1.0f - depth;
+
+		if (depth == 0.0f)
+		{
+			i++;
+			continue;
+		}
+		//if (depth > 0.7f)
+		//	depth = 0.7f;
+		
+		neV3 groundNormal = sn->GetDetectNormal();
+
+		neV3 lineNormal = body2World.rot * sn->GetLineUnitVector();
+
+		neV3 linePos = body2World * sn->GetLinePos();
+
+		f32 dot = lineNormal.Dot(groundNormal) * -1.0f;
+
+		//if (dot <= 0.7f)
+		//	continue;
+
+		neV3 f = depth * lineNormal * -k;// * dot;
+
+		force += f;
+
+		neV3 r = linePos - carRigidBody->GetPos();
+
+		torque += r.Cross(f);
+
+		// add damping force
+		
+		f32 speed = carRigidBody->GetVelocityAtPoint(r).Dot(lineNormal);
+
+		f = -speed * lineNormal * u;
+
+		force += f;
+
+		torque += r.Cross(f);
+
+		// add friction force
+
+		neV3 vel = carRigidBody->GetVelocityAtPoint(sn->GetDetectContactPoint() - carRigidBody->GetPos());
+
+		vel.RemoveComponent(groundNormal);
+
+		if (i == 0 || i == 1)
+		{
+			//steering
+
+			vel.RemoveComponent(steerDir);
+		}
+		else
+		{
+			vel.RemoveComponent(body2World.rot[0]); //rear wheel always parallel to car body
+		}
+
+
+		f = vel;
+
+		f.Normalize();
+
+		f *= -7.0f;
+
+		if (i == 2 || i ==3)
+		{
+			//f *= (1.0f - slide);
+		}
+		f[1] = 0.0f;
+		
+		force += f;
+
+		r = sn->GetDetectContactPoint() - carRigidBody->GetPos();
+
+		torque += r.Cross(f);
+
+		// driving force
+
+		if (i == 2 || i == 3) // rear wheel
+		{
+			f = body2World.rot[0];
+
+			f *= accel;
+
+			force += f;
+
+			torque += r.Cross(f);
+		}
+/*
+		gw.car.displayLines[i][0] = linePos;
+
+		gw.car.displayLines[i][1] = sn->GetDetectContactPoint();
+*/
+		i++;
+	}
+
+	// drag
+	f32 dragConstant = 0.3f;
+
+	neV3 vel = carRigidBody->GetVelocity();
+
+	f32 dot = vel.Dot(body2World.rot[0]);
+
+	neV3 drag = dot * body2World.rot[0] * -dragConstant;
+
+	force += drag;
+
+	controller->SetControllerForce(force);
+
+	controller->SetControllerTorque(torque);
+}
+
+void CCar::Process(XINPUT_STATE & InputState)
+{
+	// Zero value if thumbsticks are within the dead zone 
+	if( (InputState.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && 
+		 InputState.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) && 
+		(InputState.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && 
+		 InputState.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) )
+	{	
+	   InputState.Gamepad.sThumbLX = 0;
+	   InputState.Gamepad.sThumbLY = 0;
+	}
+
+	if( (InputState.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && 
+		 InputState.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) && 
+		(InputState.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && 
+	InputState.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) ) 
+	{
+	   InputState.Gamepad.sThumbRX = 0;
+	   InputState.Gamepad.sThumbRY = 0;
+	}
+
+	neV3 vel;
+
+	if (GetAsyncKeyState('S'))
+	{
+		accel += 0.1f;
+
+		if (accel > MAX_SPEED)
+			accel = MAX_SPEED;
+	} 
+	else if (GetAsyncKeyState('X'))
+	{
+		accel -= 0.1f;
+
+		if (accel < MAX_REVERSE_SPEED)
+			accel = MAX_REVERSE_SPEED;
+	}
+	else if (InputState.Gamepad.bRightTrigger > 0)
+	{
+		accel = (float)InputState.Gamepad.bRightTrigger / 255.0f * MAX_SPEED;
+	}
+	else if (InputState.Gamepad.bLeftTrigger > 0)
+	{
+		accel = (float)InputState.Gamepad.bLeftTrigger / 255.0f * MAX_REVERSE_SPEED;
+	}
+	else 
+	{
+		//accel *= 0.99f;
+	}
+
+	if (GetAsyncKeyState('L'))
+	{
+		steer += 0.02f;