diff --git a/build/vs2015/bounce.sln b/build/vs2015/bounce.sln deleted file mode 100644 index 4f3d5a8..0000000 --- a/build/vs2015/bounce.sln +++ /dev/null @@ -1,66 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2015 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bounce", "bounce.vcxproj", "{C13B93F4-ADDD-BDCA-9698-D11E82D9441B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glad", "glad.vcxproj", "{DD62977C-C999-980D-7286-7E105E9C140F}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glfw", "glfw.vcxproj", "{9563977C-819A-980D-2A87-7E10169D140F}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imgui", "imgui.vcxproj", "{0098A80F-6CAC-D0C0-352E-7420A101CDF1}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testbed", "testbed.vcxproj", "{90781ED9-FC57-9D74-0570-284B71CE03D6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - debug|Win32 = debug|Win32 - debug|x64 = debug|x64 - release|Win32 = release|Win32 - release|x64 = release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.debug|Win32.ActiveCfg = debug|Win32 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.debug|Win32.Build.0 = debug|Win32 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.debug|x64.ActiveCfg = debug|x64 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.debug|x64.Build.0 = debug|x64 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.release|Win32.ActiveCfg = release|Win32 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.release|Win32.Build.0 = release|Win32 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.release|x64.ActiveCfg = release|x64 - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B}.release|x64.Build.0 = release|x64 - {DD62977C-C999-980D-7286-7E105E9C140F}.debug|Win32.ActiveCfg = debug|Win32 - {DD62977C-C999-980D-7286-7E105E9C140F}.debug|Win32.Build.0 = debug|Win32 - {DD62977C-C999-980D-7286-7E105E9C140F}.debug|x64.ActiveCfg = debug|x64 - {DD62977C-C999-980D-7286-7E105E9C140F}.debug|x64.Build.0 = debug|x64 - {DD62977C-C999-980D-7286-7E105E9C140F}.release|Win32.ActiveCfg = release|Win32 - {DD62977C-C999-980D-7286-7E105E9C140F}.release|Win32.Build.0 = release|Win32 - {DD62977C-C999-980D-7286-7E105E9C140F}.release|x64.ActiveCfg = release|x64 - {DD62977C-C999-980D-7286-7E105E9C140F}.release|x64.Build.0 = release|x64 - {9563977C-819A-980D-2A87-7E10169D140F}.debug|Win32.ActiveCfg = debug|Win32 - {9563977C-819A-980D-2A87-7E10169D140F}.debug|Win32.Build.0 = debug|Win32 - {9563977C-819A-980D-2A87-7E10169D140F}.debug|x64.ActiveCfg = debug|x64 - {9563977C-819A-980D-2A87-7E10169D140F}.debug|x64.Build.0 = debug|x64 - {9563977C-819A-980D-2A87-7E10169D140F}.release|Win32.ActiveCfg = release|Win32 - {9563977C-819A-980D-2A87-7E10169D140F}.release|Win32.Build.0 = release|Win32 - {9563977C-819A-980D-2A87-7E10169D140F}.release|x64.ActiveCfg = release|x64 - {9563977C-819A-980D-2A87-7E10169D140F}.release|x64.Build.0 = release|x64 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.debug|Win32.ActiveCfg = debug|Win32 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.debug|Win32.Build.0 = debug|Win32 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.debug|x64.ActiveCfg = debug|x64 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.debug|x64.Build.0 = debug|x64 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.release|Win32.ActiveCfg = release|Win32 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.release|Win32.Build.0 = release|Win32 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.release|x64.ActiveCfg = release|x64 - {0098A80F-6CAC-D0C0-352E-7420A101CDF1}.release|x64.Build.0 = release|x64 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.debug|Win32.ActiveCfg = debug|Win32 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.debug|Win32.Build.0 = debug|Win32 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.debug|x64.ActiveCfg = debug|x64 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.debug|x64.Build.0 = debug|x64 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.release|Win32.ActiveCfg = release|Win32 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.release|Win32.Build.0 = release|Win32 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.release|x64.ActiveCfg = release|x64 - {90781ED9-FC57-9D74-0570-284B71CE03D6}.release|x64.Build.0 = release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/build/vs2015/bounce.vcxproj b/build/vs2015/bounce.vcxproj deleted file mode 100644 index a0e890c..0000000 --- a/build/vs2015/bounce.vcxproj +++ /dev/null @@ -1,291 +0,0 @@ - - - - - debug - Win32 - - - debug - x64 - - - release - Win32 - - - release - x64 - - - - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B} - true - Win32Proj - bounce - - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - - - - - - - - - - - - - - - - - bin\x32\debug\bounce\ - obj\x32\debug\bounce\ - bounce - .lib - - - bin\x64\debug\bounce\ - obj\x64\debug\bounce\ - bounce - .lib - - - bin\x32\release\bounce\ - obj\x32\release\bounce\ - bounce - .lib - - - bin\x64\release\bounce\ - obj\x64\release\bounce\ - bounce - .lib - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\include;%(AdditionalIncludeDirectories) - EditAndContinue - Disabled - false - Fast - - - Windows - true - - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\include;%(AdditionalIncludeDirectories) - ProgramDatabase - Disabled - false - Fast - - - Windows - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\include;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Windows - false - true - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\include;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Windows - false - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/vs2015/bounce.vcxproj.filters b/build/vs2015/bounce.vcxproj.filters deleted file mode 100644 index bca65bb..0000000 --- a/build/vs2015/bounce.vcxproj.filters +++ /dev/null @@ -1,458 +0,0 @@ - - - - - {89AF369E-F58E-B539-FEA6-40106A051C9B} - - - {D419DC43-C0E7-CF49-A97B-407095E8ABAE} - - - {0FC81CFD-FBEC-6B7D-2438-510D10BC6A9B} - - - {9AC16B4F-867C-5BFB-2F34-D4451BCEA58B} - - - {86F36B4F-72AE-5BFB-1B66-D4450700A68B} - - - {02B88A21-6E9B-9961-779E-C79DE30060B2} - - - {A12552DA-8D4B-1C41-7691-A10C6256410D} - - - {AC64A0F9-18D1-5BF4-E1C4-F3514DF07D5C} - - - {252146D6-1131-F2A6-7AEA-56C56619E13F} - - - {B4B69780-A071-872C-4929-007735C3D1BC} - - - {577D3B7B-43A3-05E2-2CE9-8AAD18AE2AAE} - - - {DB55CFD2-478D-176A-5097-7B8DBC4D3E63} - - - {09FBB88C-F54B-A4CE-1EB0-92900A603738} - - - {14818B0F-00FE-7E52-297B-7F6615571BE6} - - - {A1E236CD-8D08-0134-764E-86FF62132600} - - - {4E48B2E1-3A6E-7C48-23B4-01140F79A114} - - - {F52AA7E9-E14F-F669-0A9B-DBF9F61EF587} - - - {2DAB880B-99B4-887C-2230-9F7C8E38947C} - - - {F814F251-E4CC-339F-4DD4-0CFB39ABCE8F} - - - {33003210-1F8F-BBD9-C8AD-CFD4B41BCC7F} - - - {BE6BE8DC-AA90-375D-D3DB-1CEDBF5F367B} - - - {AA9DE8DC-96C2-375D-BF0D-1DEDAB91367B} - - - {A6DFD2EA-12ED-00D1-9BD3-FCBB07E0CC87} - - - {C5E8A1B9-B1F8-4D8A-1AB2-B2A806E13C23} - - - {50EF0F83-BC05-0E19-057D-993A71D2DEA0} - - - {49F28903-35EC-B255-1E59-49660AF218C2} - - - {D860140E-C485-638E-EDD0-481ED95462AC} - - - {7F194C76-EB7A-2984-74E8-6F36E0486043} - - - {2D17067F-19D2-F52A-C289-6E75AE2340BB} - - - {3881B4FC-2468-76F4-CDB8-DC11B97EEF5A} - - - {C5A586AC-B1B5-327D-1A6F-979B069E2116} - - - {720B02C1-5E1B-AE91-C7D4-12B0B3039D2A} - - - {1963BCFC-05F2-45C6-AE10-5AC19A7E566C} - - - - - include\bounce - - - include\bounce\collision - - - include\bounce\collision - - - include\bounce\collision\gjk - - - include\bounce\collision\gjk - - - include\bounce\collision\gjk - - - include\bounce\collision\sat - - - include\bounce\collision\sat - - - include\bounce\collision\sat - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\shapes - - - include\bounce\collision\trees - - - include\bounce\collision\trees - - - include\bounce\common - - - include\bounce\common - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\math - - - include\bounce\common\memory - - - include\bounce\common\memory - - - include\bounce\common - - - include\bounce\common\template - - - include\bounce\common\template - - - include\bounce\common\template - - - include\bounce\common\template - - - include\bounce\common - - - include\bounce\dynamics - - - include\bounce\dynamics - - - include\bounce\dynamics\contacts\collide - - - include\bounce\dynamics\contacts\collide - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics\contacts - - - include\bounce\dynamics - - - include\bounce\dynamics - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\joints - - - include\bounce\dynamics\shapes - - - include\bounce\dynamics\shapes - - - include\bounce\dynamics\shapes - - - include\bounce\dynamics\shapes - - - include\bounce\dynamics\shapes - - - include\bounce\dynamics - - - include\bounce\dynamics - - - include\bounce\dynamics - - - include\bounce\quickhull - - - - - src\bounce\collision - - - src\bounce\collision - - - src\bounce\collision\gjk - - - src\bounce\collision\gjk - - - src\bounce\collision\gjk - - - src\bounce\collision\sat - - - src\bounce\collision\sat - - - src\bounce\collision\sat - - - src\bounce\collision\shapes - - - src\bounce\collision\trees - - - src\bounce\collision\trees - - - src\bounce\common\math - - - src\bounce\common\memory - - - src\bounce\common\memory - - - src\bounce\common - - - src\bounce\common - - - src\bounce\dynamics - - - src\bounce\dynamics - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts\collide - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics\contacts - - - src\bounce\dynamics - - - src\bounce\dynamics - - - src\bounce\dynamics - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\joints - - - src\bounce\dynamics\shapes - - - src\bounce\dynamics\shapes - - - src\bounce\dynamics\shapes - - - src\bounce\dynamics\shapes - - - src\bounce\dynamics\shapes - - - src\bounce\dynamics - - - src\bounce\quickhull - - - - - include\bounce\collision\shapes - - - include\bounce\quickhull - - - \ No newline at end of file diff --git a/build/vs2015/glad.vcxproj b/build/vs2015/glad.vcxproj deleted file mode 100644 index fc2d28f..0000000 --- a/build/vs2015/glad.vcxproj +++ /dev/null @@ -1,180 +0,0 @@ - - - - - debug - Win32 - - - debug - x64 - - - release - Win32 - - - release - x64 - - - - {DD62977C-C999-980D-7286-7E105E9C140F} - true - Win32Proj - glad - - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - - - - - - - - - - - - - - - - - bin\x32\debug\glad\ - obj\x32\debug\glad\ - glad - .lib - - - bin\x64\debug\glad\ - obj\x64\debug\glad\ - glad - .lib - - - bin\x32\release\glad\ - obj\x32\release\glad\ - glad - .lib - - - bin\x64\release\glad\ - obj\x64\release\glad\ - glad - .lib - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - EditAndContinue - Disabled - false - Fast - CompileAsC - - - Windows - true - - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - ProgramDatabase - Disabled - false - Fast - CompileAsC - - - Windows - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - CompileAsC - - - Windows - false - true - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - CompileAsC - - - Windows - false - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/vs2015/glad.vcxproj.filters b/build/vs2015/glad.vcxproj.filters deleted file mode 100644 index 3f4c0a6..0000000 --- a/build/vs2015/glad.vcxproj.filters +++ /dev/null @@ -1,24 +0,0 @@ - - - - - {C196CD9C-2D76-4C38-368E-D70EA2ECB299} - - - {89565304-F535-D29F-FE4D-5D766AAC3801} - - - - - Headers - - - Headers - - - - - Sources - - - \ No newline at end of file diff --git a/build/vs2015/glfw.vcxproj b/build/vs2015/glfw.vcxproj deleted file mode 100644 index 2b629be..0000000 --- a/build/vs2015/glfw.vcxproj +++ /dev/null @@ -1,198 +0,0 @@ - - - - - debug - Win32 - - - debug - x64 - - - release - Win32 - - - release - x64 - - - - {9563977C-819A-980D-2A87-7E10169D140F} - true - Win32Proj - glfw - - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - - - - - - - - - - - - - - - - - bin\x32\debug\glfw\ - obj\x32\debug\glfw\ - glfw - .lib - - - bin\x64\debug\glfw\ - obj\x64\debug\glfw\ - glfw - .lib - - - bin\x32\release\glfw\ - obj\x32\release\glfw\ - glfw - .lib - - - bin\x64\release\glfw\ - obj\x64\release\glfw\ - glfw - .lib - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_GLFW_USE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external\glfw;%(AdditionalIncludeDirectories) - EditAndContinue - Disabled - false - Fast - CompileAsC - - - Windows - true - - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_GLFW_USE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external\glfw;%(AdditionalIncludeDirectories) - ProgramDatabase - Disabled - false - Fast - CompileAsC - - - Windows - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_GLFW_USE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external\glfw;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - CompileAsC - - - Windows - false - true - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_GLFW_USE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external\glfw;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - CompileAsC - - - Windows - false - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/vs2015/glfw.vcxproj.filters b/build/vs2015/glfw.vcxproj.filters deleted file mode 100644 index 0f71ea6..0000000 --- a/build/vs2015/glfw.vcxproj.filters +++ /dev/null @@ -1,78 +0,0 @@ - - - - - {C196CD9C-2D76-4C38-368E-D70EA2ECB299} - - - {89565304-F535-D29F-FE4D-5D766AAC3801} - - - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - Sources - - - \ No newline at end of file diff --git a/build/vs2015/imgui.vcxproj b/build/vs2015/imgui.vcxproj deleted file mode 100644 index 7b1660c..0000000 --- a/build/vs2015/imgui.vcxproj +++ /dev/null @@ -1,183 +0,0 @@ - - - - - debug - Win32 - - - debug - x64 - - - release - Win32 - - - release - x64 - - - - {0098A80F-6CAC-D0C0-352E-7420A101CDF1} - true - Win32Proj - imgui - - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - true - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - StaticLibrary - false - Unicode - v140 - - - - - - - - - - - - - - - - - - - bin\x32\debug\imgui\ - obj\x32\debug\imgui\ - imgui - .lib - - - bin\x64\debug\imgui\ - obj\x64\debug\imgui\ - imgui - .lib - - - bin\x32\release\imgui\ - obj\x32\release\imgui\ - imgui - .lib - - - bin\x64\release\imgui\ - obj\x64\release\imgui\ - imgui - .lib - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - EditAndContinue - Disabled - false - Fast - - - Windows - true - - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - ProgramDatabase - Disabled - false - Fast - - - Windows - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Windows - false - true - true - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\external;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Windows - false - true - true - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/vs2015/imgui.vcxproj.filters b/build/vs2015/imgui.vcxproj.filters deleted file mode 100644 index d8aa08e..0000000 --- a/build/vs2015/imgui.vcxproj.filters +++ /dev/null @@ -1,45 +0,0 @@ - - - - - {C196CD9C-2D76-4C38-368E-D70EA2ECB299} - - - {89565304-F535-D29F-FE4D-5D766AAC3801} - - - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - - - Sources - - - Sources - - - Sources - - - \ No newline at end of file diff --git a/build/vs2015/testbed.vcxproj b/build/vs2015/testbed.vcxproj deleted file mode 100644 index 3038242..0000000 --- a/build/vs2015/testbed.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - debug - Win32 - - - debug - x64 - - - release - Win32 - - - release - x64 - - - - {90781ED9-FC57-9D74-0570-284B71CE03D6} - true - Win32Proj - testbed - - - - Application - true - Unicode - v140 - - - Application - true - Unicode - v140 - - - Application - false - Unicode - v140 - - - Application - false - Unicode - v140 - - - - - - - - - - - - - - - - - - - true - bin\x32\debug\testbed\ - obj\x32\debug\testbed\ - testbed - .exe - - - true - bin\x64\debug\testbed\ - obj\x64\debug\testbed\ - testbed - .exe - - - false - bin\x32\release\testbed\ - obj\x32\release\testbed\ - testbed - .exe - - - false - bin\x64\release\testbed\ - obj\x64\release\testbed\ - testbed - .exe - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\external;..\..\include;%(AdditionalIncludeDirectories) - EditAndContinue - Disabled - false - Fast - - - Console - true - glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies) - mainCRTStartup - - - - - NotUsing - Level3 - _DEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\external;..\..\include;%(AdditionalIncludeDirectories) - ProgramDatabase - Disabled - false - Fast - - - Console - true - glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies) - mainCRTStartup - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\external;..\..\include;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Console - false - true - true - glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies) - mainCRTStartup - - - - - NotUsing - Level3 - NDEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) - ..\..\external;..\..\include;%(AdditionalIncludeDirectories) - Full - true - true - false - true - false - Fast - - - Console - false - true - true - glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies) - mainCRTStartup - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {C13B93F4-ADDD-BDCA-9698-D11E82D9441B} - - - {DD62977C-C999-980D-7286-7E105E9C140F} - - - {9563977C-819A-980D-2A87-7E10169D140F} - - - {0098A80F-6CAC-D0C0-352E-7420A101CDF1} - - - - - - \ No newline at end of file diff --git a/build/vs2015/testbed.vcxproj.filters b/build/vs2015/testbed.vcxproj.filters deleted file mode 100644 index 2edc665..0000000 --- a/build/vs2015/testbed.vcxproj.filters +++ /dev/null @@ -1,123 +0,0 @@ - - - - - {C196CD9C-2D76-4C38-368E-D70EA2ECB299} - - - {89565304-F535-D29F-FE4D-5D766AAC3801} - - - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - - - Sources - - - Sources - - - Sources - - - Sources - - - \ No newline at end of file diff --git a/building.txt b/building.txt index 6cfdc32..dcdd949 100644 --- a/building.txt +++ b/building.txt @@ -1,14 +1,35 @@ Bounce uses premake for generating project files in a platform agnostic manner. Grab premake from http://industriousone.com/premake. -Put premake.exe into bounce/. +Put premake into bounce/. Visual Studio 2015 -Open bounce/bat. -Open premake_vs2015.bat. This will run a premake script and open bounce/build/vs2015/bounce.sln. +Say { premake5 vs2015 } on a command line. +Open build/vs2015/bounce.sln. Set testbed as the startup project. -Press F5 or Ctrl-F5 to run. +Press F5 to run. -premake files for building on Mac will be available later because I don't run Mac currently and -therefore can't test the build system in this platform. \ No newline at end of file +Linux + +On a clean Ubuntu 16.04 install these packages first: + +mesa-common-dev +libgl1-mesa-dev +libglu1-mesa-dev + +x32 + +Say { premake5 gmake } on a terminal. +From build/gmake say { make config="debug_x32" }. +Open testbed from /bin/x32/testbed/. + +x64 + +Say { premake5 gmake } on a terminal. +From build/gmake say { make config="debug_x64" }. +Open testbed from /bin/x64/testbed/. + +Mac + +I don't run Mac currently and therefore can't test the build system in this platform. diff --git a/external/glad/glad.h b/external/glad/glad.h index f256317..030df9c 100644 --- a/external/glad/glad.h +++ b/external/glad/glad.h @@ -636,7 +636,7 @@ GLAPI int gladLoadGL(void); GLAPI int gladLoadGLLoader(GLADloadproc); #include -//#include +//#include #include #ifndef GLEXT_64_TYPES_DEFINED /* This code block is duplicated in glxext.h, so must be protected */ diff --git a/external/glad/glad_glx.c b/external/glad/glad_glx.c new file mode 100644 index 0000000..aaa6e08 --- /dev/null +++ b/external/glad/glad_glx.c @@ -0,0 +1,312 @@ +/* + + GLX loader generated by glad 0.1.12a0 on Tue Dec 20 17:04:11 2016. + + Language/Generator: C/C++ + Specification: glx + APIs: glx=1.4 + Profile: - + Extensions: + + Loader: True + Local files: False + Omit khrplatform: False + + Commandline: + --api="glx=1.4" --generator="c" --spec="glx" --extensions="" + Online: + http://glad.dav1d.de/#language=c&specification=glx&loader=on&api=glx%3D1.4 +*/ + +#include +#include +#include +#include + +static void* get_proc(const char *namez); + +#ifdef _WIN32 +#include +static HMODULE libGL; + +typedef void* (APIENTRYP PFNWGLGETPROCADDRESSPROC_PRIVATE)(const char*); +PFNWGLGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; + +static +int open_gl(void) { + libGL = LoadLibraryW(L"opengl32.dll"); + if(libGL != NULL) { + gladGetProcAddressPtr = (PFNWGLGETPROCADDRESSPROC_PRIVATE)GetProcAddress( + libGL, "wglGetProcAddress"); + return gladGetProcAddressPtr != NULL; + } + + return 0; +} + +static +void close_gl(void) { + if(libGL != NULL) { + FreeLibrary(libGL); + libGL = NULL; + } +} +#else +#include +static void* libGL; + +#ifndef __APPLE__ +typedef void* (APIENTRYP PFNGLXGETPROCADDRESSPROC_PRIVATE)(const char*); +PFNGLXGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; +#endif + +static +int open_gl(void) { +#ifdef __APPLE__ + static const char *NAMES[] = { + "../Frameworks/OpenGL.framework/OpenGL", + "/Library/Frameworks/OpenGL.framework/OpenGL", + "/System/Library/Frameworks/OpenGL.framework/OpenGL", + "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" + }; +#else + static const char *NAMES[] = {"libGL.so.1", "libGL.so"}; +#endif + + unsigned int index = 0; + for(index = 0; index < (sizeof(NAMES) / sizeof(NAMES[0])); index++) { + libGL = dlopen(NAMES[index], RTLD_NOW | RTLD_GLOBAL); + + if(libGL != NULL) { +#ifdef __APPLE__ + return 1; +#else + gladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)dlsym(libGL, + "glXGetProcAddressARB"); + return gladGetProcAddressPtr != NULL; +#endif + } + } + + return 0; +} + +static +void close_gl() { + if(libGL != NULL) { + dlclose(libGL); + libGL = NULL; + } +} +#endif + +static +void* get_proc(const char *namez) { + void* result = NULL; + if(libGL == NULL) return NULL; + +#ifndef __APPLE__ + if(gladGetProcAddressPtr != NULL) { + result = gladGetProcAddressPtr(namez); + } +#endif + if(result == NULL) { +#ifdef _WIN32 + result = (void*)GetProcAddress(libGL, namez); +#else + result = dlsym(libGL, namez); +#endif + } + + return result; +} + +int gladLoadGLX(Display *dpy, int screen) { + int status = 0; + + if(open_gl()) { + status = gladLoadGLXLoader((GLADloadproc)get_proc, dpy, screen); + close_gl(); + } + + return status; +} + +static Display *GLADGLXDisplay = 0; +static int GLADGLXscreen = 0; + +static int get_exts(void) { + return 1; +} + +static void free_exts(void) { + return; +} + +static int has_ext(const char *ext) { + const char *terminator; + const char *loc; + const char *extensions; + + if(!GLAD_GLX_VERSION_1_1) + return 0; + + extensions = glXQueryExtensionsString(GLADGLXDisplay, GLADGLXscreen); + + if(extensions == NULL || ext == NULL) + return 0; + + while(1) { + loc = strstr(extensions, ext); + if(loc == NULL) + break; + + terminator = loc + strlen(ext); + if((loc == extensions || *(loc - 1) == ' ') && + (*terminator == ' ' || *terminator == '\0')) + { + return 1; + } + extensions = terminator; + } + + return 0; +} + +int GLAD_GLX_VERSION_1_0; +int GLAD_GLX_VERSION_1_1; +int GLAD_GLX_VERSION_1_2; +int GLAD_GLX_VERSION_1_3; +int GLAD_GLX_VERSION_1_4; +PFNGLXGETSELECTEDEVENTPROC glad_glXGetSelectedEvent; +PFNGLXQUERYEXTENSIONPROC glad_glXQueryExtension; +PFNGLXMAKECURRENTPROC glad_glXMakeCurrent; +PFNGLXSELECTEVENTPROC glad_glXSelectEvent; +PFNGLXCREATECONTEXTPROC glad_glXCreateContext; +PFNGLXCREATEGLXPIXMAPPROC glad_glXCreateGLXPixmap; +PFNGLXQUERYVERSIONPROC glad_glXQueryVersion; +PFNGLXGETCURRENTREADDRAWABLEPROC glad_glXGetCurrentReadDrawable; +PFNGLXDESTROYPIXMAPPROC glad_glXDestroyPixmap; +PFNGLXGETCURRENTCONTEXTPROC glad_glXGetCurrentContext; +PFNGLXGETPROCADDRESSPROC glad_glXGetProcAddress; +PFNGLXWAITGLPROC glad_glXWaitGL; +PFNGLXISDIRECTPROC glad_glXIsDirect; +PFNGLXDESTROYWINDOWPROC glad_glXDestroyWindow; +PFNGLXCREATEWINDOWPROC glad_glXCreateWindow; +PFNGLXCOPYCONTEXTPROC glad_glXCopyContext; +PFNGLXCREATEPBUFFERPROC glad_glXCreatePbuffer; +PFNGLXSWAPBUFFERSPROC glad_glXSwapBuffers; +PFNGLXGETCURRENTDISPLAYPROC glad_glXGetCurrentDisplay; +PFNGLXGETCURRENTDRAWABLEPROC glad_glXGetCurrentDrawable; +PFNGLXQUERYCONTEXTPROC glad_glXQueryContext; +PFNGLXCHOOSEVISUALPROC glad_glXChooseVisual; +PFNGLXQUERYSERVERSTRINGPROC glad_glXQueryServerString; +PFNGLXDESTROYCONTEXTPROC glad_glXDestroyContext; +PFNGLXDESTROYGLXPIXMAPPROC glad_glXDestroyGLXPixmap; +PFNGLXGETFBCONFIGATTRIBPROC glad_glXGetFBConfigAttrib; +PFNGLXUSEXFONTPROC glad_glXUseXFont; +PFNGLXDESTROYPBUFFERPROC glad_glXDestroyPbuffer; +PFNGLXCHOOSEFBCONFIGPROC glad_glXChooseFBConfig; +PFNGLXCREATENEWCONTEXTPROC glad_glXCreateNewContext; +PFNGLXMAKECONTEXTCURRENTPROC glad_glXMakeContextCurrent; +PFNGLXGETCONFIGPROC glad_glXGetConfig; +PFNGLXGETFBCONFIGSPROC glad_glXGetFBConfigs; +PFNGLXCREATEPIXMAPPROC glad_glXCreatePixmap; +PFNGLXWAITXPROC glad_glXWaitX; +PFNGLXGETVISUALFROMFBCONFIGPROC glad_glXGetVisualFromFBConfig; +PFNGLXQUERYDRAWABLEPROC glad_glXQueryDrawable; +PFNGLXQUERYEXTENSIONSSTRINGPROC glad_glXQueryExtensionsString; +PFNGLXGETCLIENTSTRINGPROC glad_glXGetClientString; +static void load_GLX_VERSION_1_0(GLADloadproc load) { + if(!GLAD_GLX_VERSION_1_0) return; + glad_glXChooseVisual = (PFNGLXCHOOSEVISUALPROC)load("glXChooseVisual"); + glad_glXCreateContext = (PFNGLXCREATECONTEXTPROC)load("glXCreateContext"); + glad_glXDestroyContext = (PFNGLXDESTROYCONTEXTPROC)load("glXDestroyContext"); + glad_glXMakeCurrent = (PFNGLXMAKECURRENTPROC)load("glXMakeCurrent"); + glad_glXCopyContext = (PFNGLXCOPYCONTEXTPROC)load("glXCopyContext"); + glad_glXSwapBuffers = (PFNGLXSWAPBUFFERSPROC)load("glXSwapBuffers"); + glad_glXCreateGLXPixmap = (PFNGLXCREATEGLXPIXMAPPROC)load("glXCreateGLXPixmap"); + glad_glXDestroyGLXPixmap = (PFNGLXDESTROYGLXPIXMAPPROC)load("glXDestroyGLXPixmap"); + glad_glXQueryExtension = (PFNGLXQUERYEXTENSIONPROC)load("glXQueryExtension"); + glad_glXQueryVersion = (PFNGLXQUERYVERSIONPROC)load("glXQueryVersion"); + glad_glXIsDirect = (PFNGLXISDIRECTPROC)load("glXIsDirect"); + glad_glXGetConfig = (PFNGLXGETCONFIGPROC)load("glXGetConfig"); + glad_glXGetCurrentContext = (PFNGLXGETCURRENTCONTEXTPROC)load("glXGetCurrentContext"); + glad_glXGetCurrentDrawable = (PFNGLXGETCURRENTDRAWABLEPROC)load("glXGetCurrentDrawable"); + glad_glXWaitGL = (PFNGLXWAITGLPROC)load("glXWaitGL"); + glad_glXWaitX = (PFNGLXWAITXPROC)load("glXWaitX"); + glad_glXUseXFont = (PFNGLXUSEXFONTPROC)load("glXUseXFont"); +} +static void load_GLX_VERSION_1_1(GLADloadproc load) { + if(!GLAD_GLX_VERSION_1_1) return; + glad_glXQueryExtensionsString = (PFNGLXQUERYEXTENSIONSSTRINGPROC)load("glXQueryExtensionsString"); + glad_glXQueryServerString = (PFNGLXQUERYSERVERSTRINGPROC)load("glXQueryServerString"); + glad_glXGetClientString = (PFNGLXGETCLIENTSTRINGPROC)load("glXGetClientString"); +} +static void load_GLX_VERSION_1_2(GLADloadproc load) { + if(!GLAD_GLX_VERSION_1_2) return; + glad_glXGetCurrentDisplay = (PFNGLXGETCURRENTDISPLAYPROC)load("glXGetCurrentDisplay"); +} +static void load_GLX_VERSION_1_3(GLADloadproc load) { + if(!GLAD_GLX_VERSION_1_3) return; + glad_glXGetFBConfigs = (PFNGLXGETFBCONFIGSPROC)load("glXGetFBConfigs"); + glad_glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)load("glXChooseFBConfig"); + glad_glXGetFBConfigAttrib = (PFNGLXGETFBCONFIGATTRIBPROC)load("glXGetFBConfigAttrib"); + glad_glXGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)load("glXGetVisualFromFBConfig"); + glad_glXCreateWindow = (PFNGLXCREATEWINDOWPROC)load("glXCreateWindow"); + glad_glXDestroyWindow = (PFNGLXDESTROYWINDOWPROC)load("glXDestroyWindow"); + glad_glXCreatePixmap = (PFNGLXCREATEPIXMAPPROC)load("glXCreatePixmap"); + glad_glXDestroyPixmap = (PFNGLXDESTROYPIXMAPPROC)load("glXDestroyPixmap"); + glad_glXCreatePbuffer = (PFNGLXCREATEPBUFFERPROC)load("glXCreatePbuffer"); + glad_glXDestroyPbuffer = (PFNGLXDESTROYPBUFFERPROC)load("glXDestroyPbuffer"); + glad_glXQueryDrawable = (PFNGLXQUERYDRAWABLEPROC)load("glXQueryDrawable"); + glad_glXCreateNewContext = (PFNGLXCREATENEWCONTEXTPROC)load("glXCreateNewContext"); + glad_glXMakeContextCurrent = (PFNGLXMAKECONTEXTCURRENTPROC)load("glXMakeContextCurrent"); + glad_glXGetCurrentReadDrawable = (PFNGLXGETCURRENTREADDRAWABLEPROC)load("glXGetCurrentReadDrawable"); + glad_glXQueryContext = (PFNGLXQUERYCONTEXTPROC)load("glXQueryContext"); + glad_glXSelectEvent = (PFNGLXSELECTEVENTPROC)load("glXSelectEvent"); + glad_glXGetSelectedEvent = (PFNGLXGETSELECTEDEVENTPROC)load("glXGetSelectedEvent"); +} +static void load_GLX_VERSION_1_4(GLADloadproc load) { + if(!GLAD_GLX_VERSION_1_4) return; + glad_glXGetProcAddress = (PFNGLXGETPROCADDRESSPROC)load("glXGetProcAddress"); +} +static int find_extensionsGLX(void) { + if (!get_exts()) return 0; + free_exts(); + return 1; +} + +static void find_coreGLX(Display *dpy, int screen) { + int major = 0, minor = 0; + if(dpy == 0 && GLADGLXDisplay == 0) { + dpy = XOpenDisplay(0); + screen = XScreenNumberOfScreen(XDefaultScreenOfDisplay(dpy)); + } else if(dpy == 0) { + dpy = GLADGLXDisplay; + screen = GLADGLXscreen; + } + glXQueryVersion(dpy, &major, &minor); + GLADGLXDisplay = dpy; + GLADGLXscreen = screen; + GLAD_GLX_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1; + GLAD_GLX_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1; + GLAD_GLX_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1; + GLAD_GLX_VERSION_1_3 = (major == 1 && minor >= 3) || major > 1; + GLAD_GLX_VERSION_1_4 = (major == 1 && minor >= 4) || major > 1; +} + +int gladLoadGLXLoader(GLADloadproc load, Display *dpy, int screen) { + glXQueryVersion = (PFNGLXQUERYVERSIONPROC)load("glXQueryVersion"); + if(glXQueryVersion == NULL) return 0; + find_coreGLX(dpy, screen); + load_GLX_VERSION_1_0(load); + load_GLX_VERSION_1_1(load); + load_GLX_VERSION_1_2(load); + load_GLX_VERSION_1_3(load); + load_GLX_VERSION_1_4(load); + + if (!find_extensionsGLX()) return 0; + return 1; +} + diff --git a/external/glad/glad_glx.h b/external/glad/glad_glx.h new file mode 100644 index 0000000..d402402 --- /dev/null +++ b/external/glad/glad_glx.h @@ -0,0 +1,433 @@ +/* + + GLX loader generated by glad 0.1.12a0 on Tue Dec 20 17:04:11 2016. + + Language/Generator: C/C++ + Specification: glx + APIs: glx=1.4 + Profile: - + Extensions: + + Loader: True + Local files: False + Omit khrplatform: False + + Commandline: + --api="glx=1.4" --generator="c" --spec="glx" --extensions="" + Online: + http://glad.dav1d.de/#language=c&specification=glx&loader=on&api=glx%3D1.4 +*/ + + +#include +#include +#include +#include + +#ifndef __glad_glxext_h_ + +#ifdef __glxext_h_ +#error GLX header already included, remove this include, glad already provides it +#endif + +#define __glad_glxext_h_ +#define __glxext_h_ + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void* (* GLADloadproc)(const char *name); + +#ifndef GLAPI +# if defined(GLAD_GLAPI_EXPORT) +# if defined(WIN32) || defined(__CYGWIN__) +# if defined(GLAD_GLAPI_EXPORT_BUILD) +# if defined(__GNUC__) +# define GLAPI __attribute__ ((dllexport)) extern +# else +# define GLAPI __declspec(dllexport) extern +# endif +# else +# if defined(__GNUC__) +# define GLAPI __attribute__ ((dllimport)) extern +# else +# define GLAPI __declspec(dllimport) extern +# endif +# endif +# elif defined(__GNUC__) && defined(GLAD_GLAPI_EXPORT_BUILD) +# define GLAPI __attribute__ ((visibility ("default"))) extern +# else +# define GLAPI extern +# endif +# else +# define GLAPI extern +# endif +#endif + +GLAPI int gladLoadGLX(Display *dpy, int screen); + +GLAPI int gladLoadGLXLoader(GLADloadproc, Display *dpy, int screen); + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GLX_OML_sync_control extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif +typedef XID GLXFBConfigID; +typedef struct __GLXFBConfigRec *GLXFBConfig; +typedef XID GLXContextID; +typedef struct __GLXcontextRec *GLXContext; +typedef XID GLXPixmap; +typedef XID GLXDrawable; +typedef XID GLXWindow; +typedef XID GLXPbuffer; +typedef void (APIENTRY *__GLXextFuncPtr)(void); +typedef XID GLXVideoCaptureDeviceNV; +typedef unsigned int GLXVideoDeviceNV; +typedef XID GLXVideoSourceSGIX; +typedef XID GLXFBConfigIDSGIX; +typedef struct __GLXFBConfigRec *GLXFBConfigSGIX; +typedef XID GLXPbufferSGIX; +typedef struct { + int event_type; /* GLX_DAMAGED or GLX_SAVED */ + int draw_type; /* GLX_WINDOW or GLX_PBUFFER */ + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* XID of Drawable */ + unsigned int buffer_mask; /* mask indicating which buffers are affected */ + unsigned int aux_buffer; /* which aux buffer was affected */ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXPbufferClobberEvent; +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + GLXDrawable drawable; /* drawable on which event was requested in event mask */ + int event_type; + int64_t ust; + int64_t msc; + int64_t sbc; +} GLXBufferSwapComplete; +typedef union __GLXEvent { + GLXPbufferClobberEvent glxpbufferclobber; + GLXBufferSwapComplete glxbufferswapcomplete; + long pad[24]; +} GLXEvent; +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + int extension; + int evtype; + GLXDrawable window; + Bool stereo_tree; +} GLXStereoNotifyEventEXT; +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* i.d. of Drawable */ + int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */ + int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */ + unsigned int mask; /* mask indicating which buffers are affected*/ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXBufferClobberEventSGIX; +typedef struct { + char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ + int networkId; +} GLXHyperpipeNetworkSGIX; +typedef struct { + char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ + int channel; + unsigned int participationType; + int timeSlice; +} GLXHyperpipeConfigSGIX; +typedef struct { + char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ + int srcXOrigin, srcYOrigin, srcWidth, srcHeight; + int destXOrigin, destYOrigin, destWidth, destHeight; +} GLXPipeRect; +typedef struct { + char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ + int XOrigin, YOrigin, maxHeight, maxWidth; +} GLXPipeRectLimits; +#define GLX_EXTENSION_NAME "GLX" +#define GLX_PbufferClobber 0 +#define GLX_BufferSwapComplete 1 +#define __GLX_NUMBER_EVENTS 17 +#define GLX_BAD_SCREEN 1 +#define GLX_BAD_ATTRIBUTE 2 +#define GLX_NO_EXTENSION 3 +#define GLX_BAD_VISUAL 4 +#define GLX_BAD_CONTEXT 5 +#define GLX_BAD_VALUE 6 +#define GLX_BAD_ENUM 7 +#define GLX_USE_GL 1 +#define GLX_BUFFER_SIZE 2 +#define GLX_LEVEL 3 +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_STEREO 6 +#define GLX_AUX_BUFFERS 7 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_ACCUM_RED_SIZE 14 +#define GLX_ACCUM_GREEN_SIZE 15 +#define GLX_ACCUM_BLUE_SIZE 16 +#define GLX_ACCUM_ALPHA_SIZE 17 +#define GLX_VENDOR 0x1 +#define GLX_VERSION 0x2 +#define GLX_EXTENSIONS 0x3 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#define GLX_SAMPLE_BUFFERS 100000 +#define GLX_SAMPLES 100001 +#ifndef GLX_VERSION_1_0 +#define GLX_VERSION_1_0 1 +GLAPI int GLAD_GLX_VERSION_1_0; +typedef XVisualInfo * (APIENTRYP PFNGLXCHOOSEVISUALPROC)(Display *dpy, int screen, int *attribList); +GLAPI PFNGLXCHOOSEVISUALPROC glad_glXChooseVisual; +#define glXChooseVisual glad_glXChooseVisual +typedef GLXContext (APIENTRYP PFNGLXCREATECONTEXTPROC)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); +GLAPI PFNGLXCREATECONTEXTPROC glad_glXCreateContext; +#define glXCreateContext glad_glXCreateContext +typedef void (APIENTRYP PFNGLXDESTROYCONTEXTPROC)(Display *dpy, GLXContext ctx); +GLAPI PFNGLXDESTROYCONTEXTPROC glad_glXDestroyContext; +#define glXDestroyContext glad_glXDestroyContext +typedef Bool (APIENTRYP PFNGLXMAKECURRENTPROC)(Display *dpy, GLXDrawable drawable, GLXContext ctx); +GLAPI PFNGLXMAKECURRENTPROC glad_glXMakeCurrent; +#define glXMakeCurrent glad_glXMakeCurrent +typedef void (APIENTRYP PFNGLXCOPYCONTEXTPROC)(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask); +GLAPI PFNGLXCOPYCONTEXTPROC glad_glXCopyContext; +#define glXCopyContext glad_glXCopyContext +typedef void (APIENTRYP PFNGLXSWAPBUFFERSPROC)(Display *dpy, GLXDrawable drawable); +GLAPI PFNGLXSWAPBUFFERSPROC glad_glXSwapBuffers; +#define glXSwapBuffers glad_glXSwapBuffers +typedef GLXPixmap (APIENTRYP PFNGLXCREATEGLXPIXMAPPROC)(Display *dpy, XVisualInfo *visual, Pixmap pixmap); +GLAPI PFNGLXCREATEGLXPIXMAPPROC glad_glXCreateGLXPixmap; +#define glXCreateGLXPixmap glad_glXCreateGLXPixmap +typedef void (APIENTRYP PFNGLXDESTROYGLXPIXMAPPROC)(Display *dpy, GLXPixmap pixmap); +GLAPI PFNGLXDESTROYGLXPIXMAPPROC glad_glXDestroyGLXPixmap; +#define glXDestroyGLXPixmap glad_glXDestroyGLXPixmap +typedef Bool (APIENTRYP PFNGLXQUERYEXTENSIONPROC)(Display *dpy, int *errorb, int *event); +GLAPI PFNGLXQUERYEXTENSIONPROC glad_glXQueryExtension; +#define glXQueryExtension glad_glXQueryExtension +typedef Bool (APIENTRYP PFNGLXQUERYVERSIONPROC)(Display *dpy, int *maj, int *min); +GLAPI PFNGLXQUERYVERSIONPROC glad_glXQueryVersion; +#define glXQueryVersion glad_glXQueryVersion +typedef Bool (APIENTRYP PFNGLXISDIRECTPROC)(Display *dpy, GLXContext ctx); +GLAPI PFNGLXISDIRECTPROC glad_glXIsDirect; +#define glXIsDirect glad_glXIsDirect +typedef int (APIENTRYP PFNGLXGETCONFIGPROC)(Display *dpy, XVisualInfo *visual, int attrib, int *value); +GLAPI PFNGLXGETCONFIGPROC glad_glXGetConfig; +#define glXGetConfig glad_glXGetConfig +typedef GLXContext (APIENTRYP PFNGLXGETCURRENTCONTEXTPROC)(); +GLAPI PFNGLXGETCURRENTCONTEXTPROC glad_glXGetCurrentContext; +#define glXGetCurrentContext glad_glXGetCurrentContext +typedef GLXDrawable (APIENTRYP PFNGLXGETCURRENTDRAWABLEPROC)(); +GLAPI PFNGLXGETCURRENTDRAWABLEPROC glad_glXGetCurrentDrawable; +#define glXGetCurrentDrawable glad_glXGetCurrentDrawable +typedef void (APIENTRYP PFNGLXWAITGLPROC)(); +GLAPI PFNGLXWAITGLPROC glad_glXWaitGL; +#define glXWaitGL glad_glXWaitGL +typedef void (APIENTRYP PFNGLXWAITXPROC)(); +GLAPI PFNGLXWAITXPROC glad_glXWaitX; +#define glXWaitX glad_glXWaitX +typedef void (APIENTRYP PFNGLXUSEXFONTPROC)(Font font, int first, int count, int list); +GLAPI PFNGLXUSEXFONTPROC glad_glXUseXFont; +#define glXUseXFont glad_glXUseXFont +#endif +#ifndef GLX_VERSION_1_1 +#define GLX_VERSION_1_1 1 +GLAPI int GLAD_GLX_VERSION_1_1; +typedef const char * (APIENTRYP PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display *dpy, int screen); +GLAPI PFNGLXQUERYEXTENSIONSSTRINGPROC glad_glXQueryExtensionsString; +#define glXQueryExtensionsString glad_glXQueryExtensionsString +typedef const char * (APIENTRYP PFNGLXQUERYSERVERSTRINGPROC)(Display *dpy, int screen, int name); +GLAPI PFNGLXQUERYSERVERSTRINGPROC glad_glXQueryServerString; +#define glXQueryServerString glad_glXQueryServerString +typedef const char * (APIENTRYP PFNGLXGETCLIENTSTRINGPROC)(Display *dpy, int name); +GLAPI PFNGLXGETCLIENTSTRINGPROC glad_glXGetClientString; +#define glXGetClientString glad_glXGetClientString +#endif +#ifndef GLX_VERSION_1_2 +#define GLX_VERSION_1_2 1 +GLAPI int GLAD_GLX_VERSION_1_2; +typedef Display * (APIENTRYP PFNGLXGETCURRENTDISPLAYPROC)(); +GLAPI PFNGLXGETCURRENTDISPLAYPROC glad_glXGetCurrentDisplay; +#define glXGetCurrentDisplay glad_glXGetCurrentDisplay +#endif +#ifndef GLX_VERSION_1_3 +#define GLX_VERSION_1_3 1 +GLAPI int GLAD_GLX_VERSION_1_3; +typedef GLXFBConfig * (APIENTRYP PFNGLXGETFBCONFIGSPROC)(Display *dpy, int screen, int *nelements); +GLAPI PFNGLXGETFBCONFIGSPROC glad_glXGetFBConfigs; +#define glXGetFBConfigs glad_glXGetFBConfigs +typedef GLXFBConfig * (APIENTRYP PFNGLXCHOOSEFBCONFIGPROC)(Display *dpy, int screen, const int *attrib_list, int *nelements); +GLAPI PFNGLXCHOOSEFBCONFIGPROC glad_glXChooseFBConfig; +#define glXChooseFBConfig glad_glXChooseFBConfig +typedef int (APIENTRYP PFNGLXGETFBCONFIGATTRIBPROC)(Display *dpy, GLXFBConfig config, int attribute, int *value); +GLAPI PFNGLXGETFBCONFIGATTRIBPROC glad_glXGetFBConfigAttrib; +#define glXGetFBConfigAttrib glad_glXGetFBConfigAttrib +typedef XVisualInfo * (APIENTRYP PFNGLXGETVISUALFROMFBCONFIGPROC)(Display *dpy, GLXFBConfig config); +GLAPI PFNGLXGETVISUALFROMFBCONFIGPROC glad_glXGetVisualFromFBConfig; +#define glXGetVisualFromFBConfig glad_glXGetVisualFromFBConfig +typedef GLXWindow (APIENTRYP PFNGLXCREATEWINDOWPROC)(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +GLAPI PFNGLXCREATEWINDOWPROC glad_glXCreateWindow; +#define glXCreateWindow glad_glXCreateWindow +typedef void (APIENTRYP PFNGLXDESTROYWINDOWPROC)(Display *dpy, GLXWindow win); +GLAPI PFNGLXDESTROYWINDOWPROC glad_glXDestroyWindow; +#define glXDestroyWindow glad_glXDestroyWindow +typedef GLXPixmap (APIENTRYP PFNGLXCREATEPIXMAPPROC)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +GLAPI PFNGLXCREATEPIXMAPPROC glad_glXCreatePixmap; +#define glXCreatePixmap glad_glXCreatePixmap +typedef void (APIENTRYP PFNGLXDESTROYPIXMAPPROC)(Display *dpy, GLXPixmap pixmap); +GLAPI PFNGLXDESTROYPIXMAPPROC glad_glXDestroyPixmap; +#define glXDestroyPixmap glad_glXDestroyPixmap +typedef GLXPbuffer (APIENTRYP PFNGLXCREATEPBUFFERPROC)(Display *dpy, GLXFBConfig config, const int *attrib_list); +GLAPI PFNGLXCREATEPBUFFERPROC glad_glXCreatePbuffer; +#define glXCreatePbuffer glad_glXCreatePbuffer +typedef void (APIENTRYP PFNGLXDESTROYPBUFFERPROC)(Display *dpy, GLXPbuffer pbuf); +GLAPI PFNGLXDESTROYPBUFFERPROC glad_glXDestroyPbuffer; +#define glXDestroyPbuffer glad_glXDestroyPbuffer +typedef void (APIENTRYP PFNGLXQUERYDRAWABLEPROC)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +GLAPI PFNGLXQUERYDRAWABLEPROC glad_glXQueryDrawable; +#define glXQueryDrawable glad_glXQueryDrawable +typedef GLXContext (APIENTRYP PFNGLXCREATENEWCONTEXTPROC)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +GLAPI PFNGLXCREATENEWCONTEXTPROC glad_glXCreateNewContext; +#define glXCreateNewContext glad_glXCreateNewContext +typedef Bool (APIENTRYP PFNGLXMAKECONTEXTCURRENTPROC)(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +GLAPI PFNGLXMAKECONTEXTCURRENTPROC glad_glXMakeContextCurrent; +#define glXMakeContextCurrent glad_glXMakeContextCurrent +typedef GLXDrawable (APIENTRYP PFNGLXGETCURRENTREADDRAWABLEPROC)(); +GLAPI PFNGLXGETCURRENTREADDRAWABLEPROC glad_glXGetCurrentReadDrawable; +#define glXGetCurrentReadDrawable glad_glXGetCurrentReadDrawable +typedef int (APIENTRYP PFNGLXQUERYCONTEXTPROC)(Display *dpy, GLXContext ctx, int attribute, int *value); +GLAPI PFNGLXQUERYCONTEXTPROC glad_glXQueryContext; +#define glXQueryContext glad_glXQueryContext +typedef void (APIENTRYP PFNGLXSELECTEVENTPROC)(Display *dpy, GLXDrawable draw, unsigned long event_mask); +GLAPI PFNGLXSELECTEVENTPROC glad_glXSelectEvent; +#define glXSelectEvent glad_glXSelectEvent +typedef void (APIENTRYP PFNGLXGETSELECTEDEVENTPROC)(Display *dpy, GLXDrawable draw, unsigned long *event_mask); +GLAPI PFNGLXGETSELECTEDEVENTPROC glad_glXGetSelectedEvent; +#define glXGetSelectedEvent glad_glXGetSelectedEvent +#endif +#ifndef GLX_VERSION_1_4 +#define GLX_VERSION_1_4 1 +GLAPI int GLAD_GLX_VERSION_1_4; +typedef __GLXextFuncPtr (APIENTRYP PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName); +GLAPI PFNGLXGETPROCADDRESSPROC glad_glXGetProcAddress; +#define glXGetProcAddress glad_glXGetProcAddress +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/glfw/CMakeLists.txt b/external/glfw/CMakeLists.txt deleted file mode 100644 index 9c5ee15..0000000 --- a/external/glfw/CMakeLists.txt +++ /dev/null @@ -1,121 +0,0 @@ -add_definitions(-D_GLFW_USE_CONFIG_H) - -set(common_HEADERS internal.h - "${GLFW_BINARY_DIR}/src/glfw_config.h" - "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" - "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") -set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c) - -if (_GLFW_COCOA) - set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h - posix_tls.h nsgl_context.h) - set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m - cocoa_monitor.m cocoa_window.m cocoa_time.c posix_tls.c - nsgl_context.m) -elseif (_GLFW_WIN32) - set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h - wgl_context.h egl_context.h) - set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c - win32_monitor.c win32_time.c win32_tls.c win32_window.c - wgl_context.c egl_context.c) -elseif (_GLFW_X11) - set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h - linux_joystick.h posix_time.h posix_tls.h glx_context.h - egl_context.h) - set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c - xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c - glx_context.c egl_context.c) -elseif (_GLFW_WAYLAND) - set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h - posix_time.h posix_tls.h xkb_unicode.h egl_context.h) - set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c - linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c - egl_context.c) - - ecm_add_wayland_client_protocol(glfw_SOURCES - PROTOCOL - ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml - BASENAME relative-pointer-unstable-v1) - ecm_add_wayland_client_protocol(glfw_SOURCES - PROTOCOL - ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml - BASENAME pointer-constraints-unstable-v1) -elseif (_GLFW_MIR) - set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h - posix_time.h posix_tls.h xkb_unicode.h egl_context.h) - set(glfw_SOURCES ${common_SOURCES} mir_init.c mir_monitor.c mir_window.c - linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c - egl_context.c) -endif() - -if (APPLE) - # For some reason, CMake doesn't know about .m - set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) -endif() - -add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) -set_target_properties(glfw PROPERTIES - OUTPUT_NAME ${GLFW_LIB_NAME} - VERSION ${GLFW_VERSION} - SOVERSION ${GLFW_VERSION_MAJOR} - POSITION_INDEPENDENT_CODE ON - FOLDER "GLFW3") - -target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H) -target_include_directories(glfw PUBLIC - $ - $/include>) -target_include_directories(glfw PRIVATE - "${GLFW_SOURCE_DIR}/src" - "${GLFW_BINARY_DIR}/src" - ${glfw_INCLUDE_DIRS}) - -# HACK: When building on MinGW, WINVER and UNICODE need to be defined before -# the inclusion of stddef.h (by glfw3.h), which is itself included before -# win32_platform.h. We define them here until a saner solution can be found -# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. -target_compile_definitions(glfw PRIVATE - "$<$:UNICODE;WINVER=0x0501>") - -# Enable a reasonable set of warnings (no, -Wextra is not reasonable) -target_compile_options(glfw PRIVATE - "$<$:-Wall>" - "$<$:-Wall>") - -if (BUILD_SHARED_LIBS) - if (WIN32) - if (MINGW) - # Remove the lib prefix on the DLL (but not the import library - set_target_properties(glfw PROPERTIES PREFIX "") - - # Add a suffix to the import library to avoid naming conflicts - set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") - else() - # Add a suffix to the import library to avoid naming conflicts - set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") - endif() - elseif (APPLE) - # Add -fno-common to work around a bug in Apple's GCC - target_compile_options(glfw PRIVATE "-fno-common") - - set_target_properties(glfw PROPERTIES - INSTALL_NAME_DIR "lib${LIB_SUFFIX}") - elseif (UNIX) - # Hide symbols not explicitly tagged for export from the shared library - target_compile_options(glfw PRIVATE "-fvisibility=hidden") - endif() - - target_compile_definitions(glfw INTERFACE -DGLFW_DLL) - target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) -else() - target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES}) -endif() - -if (MSVC) - target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) -endif() - -if (GLFW_INSTALL) - install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) -endif() - diff --git a/external/glfw/glfw_config.h b/external/glfw/glfw_config.h index 76dc937..2250ff0 100644 --- a/external/glfw/glfw_config.h +++ b/external/glfw/glfw_config.h @@ -37,7 +37,7 @@ // Define this to 1 if building GLFW for X11 /* #undef _GLFW_X11 */ // Define this to 1 if building GLFW for Win32 -#define _GLFW_WIN32 +//#define _GLFW_WIN32 // Define this to 1 if building GLFW for Cocoa /* #undef _GLFW_COCOA */ // Define this to 1 if building GLFW for Wayland @@ -63,3 +63,16 @@ // Define this to 1 if windows should use full resolution on Retina displays /* #undef _GLFW_USE_RETINA */ +#if defined ( _WIN32 ) + #define _GLFW_WIN32 + #define _GLFW_WGL +#elif defined ( __APPLE__ ) + #define _GLFW_COCOA + #define _GLFW_NSGL +#else + #define _GLFW_X11 + #define _GLFW_GLX +#endif + +#define _GLFW_USE_MENUBAR +#define _GLFW_USE_OPENGL diff --git a/external/imgui/CMakeLists.txt b/external/imgui/CMakeLists.txt deleted file mode 100644 index 048d0f6..0000000 --- a/external/imgui/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -set(imgui_HEADERS - imconfig.h - imgui.h - imgui_internal.h - imgui_impl_glfw_gl3.h - stb_rect_pack.h - stb_textedit.h - stb_truetype.h -) - -set(imgui_SOURCES - imgui.cpp - imgui_draw.cpp - imgui_impl_glfw_gl3.cpp -) - -include_directories(../) -add_library(imgui STATIC ${imgui_HEADERS} ${imgui_SOURCES}) \ No newline at end of file diff --git a/external/imgui/imgui_impl_glfw_gl3.cpp b/external/imgui/imgui_impl_glfw_gl3.cpp index e8ff8d4..d097d65 100644 --- a/external/imgui/imgui_impl_glfw_gl3.cpp +++ b/external/imgui/imgui_impl_glfw_gl3.cpp @@ -6,21 +6,23 @@ // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui -#include "imgui.h" +#include #include "imgui_impl_glfw_gl3.h" -// GL3W/GLFW #if defined(__APPLE_CC__) -#include + #include #else -#include + // GLEW/GL3W/GLAD/... + #include #endif + #include -#ifdef _WIN32 -#undef APIENTRY -#define GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WGL -#include + +#if defined ( _WIN32 ) + #undef APIENTRY + #define GLFW_EXPOSE_NATIVE_WIN32 + #define GLFW_EXPOSE_NATIVE_WGL + #include #endif // Data @@ -208,7 +210,7 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects() glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); const GLchar *vertex_shader = - "#version 330\n" + "#version 130\n" "uniform mat4 ProjMtx;\n" "in vec2 Position;\n" "in vec2 UV;\n" @@ -223,7 +225,7 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects() "}\n"; const GLchar* fragment_shader = - "#version 330\n" + "#version 130\n" "uniform sampler2D Texture;\n" "in vec2 Frag_UV;\n" "in vec4 Frag_Color;\n" diff --git a/include/bounce/bounce.h b/include/bounce/bounce.h index 081c14d..c6bfbcf 100644 --- a/include/bounce/bounce.h +++ b/include/bounce/bounce.h @@ -21,40 +21,40 @@ // Include this file header in your project to directly access Bounce objects. -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #endif \ No newline at end of file diff --git a/include/bounce/collision/broad_phase.h b/include/bounce/collision/broad_phase.h index fec07b8..7dfb836 100644 --- a/include/bounce/collision/broad_phase.h +++ b/include/bounce/collision/broad_phase.h @@ -19,7 +19,7 @@ #ifndef B3_BROAD_PHASE_H #define B3_BROAD_PHASE_H -#include +#include #include // A pair of broad-phase proxies. @@ -29,8 +29,8 @@ struct b3Pair i32 proxy2; }; -// The broad-phase collision interface. -// It is used to perform ray, AABB, and overlapping-pair queries +// The broad-phase interface. +// It is used to perform ray casts, volume queries, and overlapping queries // against AABBs. class b3BroadPhase { @@ -38,14 +38,14 @@ public: b3BroadPhase(); ~b3BroadPhase(); - // Create a broad-phase proxy and return a proxy. + // Create a proxy and return a index to it. i32 CreateProxy(const b3AABB3& aabb, void* userData); - // Destroy an existing proxy. + // Destroy a given proxy and remove it from the broadphase. void DestroyProxy(i32 proxyId); - // Update an existing proxy with a given AABB and a displacement. - // displacement = int[a, b](dv/dt) dt = F(b) - F(a) = x(b) - x(a) ~= v * dt + // Update an existing proxy AABB with a given AABB and a displacement. + // displacement = dt * velocity // Return true if the proxy has moved. bool MoveProxy(i32 proxyId, const b3AABB3& aabb, const b3Vec3& displacement); @@ -65,15 +65,15 @@ public: // Notify the client callback the AABBs that are overlapping the // passed ray. template - void QueryRay(T* callback, const b3RayCastInput& input) const; + void RayCast(T* callback, const b3RayCastInput& input) const; // Notify the client callback the AABB pairs that are overlapping. // The client must store the notified pairs. template void FindNewPairs(T* callback); - // Debug b3Draw the AABB proxies. - void Draw(b3Draw* b3Draw) const; + // Draw the proxy AABBs. + void Draw(b3Draw* draw) const; private : friend class b3DynamicTree; @@ -81,18 +81,18 @@ private : // Only moved proxies will be used as an AABB query reference object. void BufferMove(i32 proxyId); - // The client callback used to add a overlapping pair + // The client callback used to add an overlapping pair // to the overlapping pair buffer. bool Report(i32 proxyId); // The dynamic tree. b3DynamicTree m_tree; - // The current proxy being queried for - // overlap witha another proxies. Is used to avoid a proxy overlap with itself. + // The current proxy being queried for overlap with another proxies. + // It is used to avoid a proxy overlap with itself. i32 m_queryProxyId; - // Keep a buffer of the objects that have moved in a step. + // The objects that have moved in a step. i32* m_moveBuffer; u32 m_moveBufferCount; u32 m_moveBufferCapacity; @@ -120,9 +120,9 @@ inline void b3BroadPhase::QueryAABB(T* callback, const b3AABB3& aabb) const } template -inline void b3BroadPhase::QueryRay(T* callback, const b3RayCastInput& input) const +inline void b3BroadPhase::RayCast(T* callback, const b3RayCastInput& input) const { - return m_tree.QueryRay(callback, input); + return m_tree.RayCast(callback, input); } inline bool operator<(const b3Pair& pair1, const b3Pair& pair2) @@ -189,9 +189,9 @@ inline void b3BroadPhase::FindNewPairs(T* callback) } } -inline void b3BroadPhase::Draw(b3Draw* b3Draw) const +inline void b3BroadPhase::Draw(b3Draw* draw) const { - m_tree.Draw(b3Draw); + m_tree.Draw(draw); } #endif \ No newline at end of file diff --git a/include/bounce/collision/distance.h b/include/bounce/collision/distance.h index 916000e..49f15f3 100644 --- a/include/bounce/collision/distance.h +++ b/include/bounce/collision/distance.h @@ -16,27 +16,13 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef B3_COLLISION_H -#define B3_COLLISION_H +#ifndef B3_DISTANCE_H +#define B3_DISTANCE_H -#include -#include -#include +#include +#include -// Input for a ray cast query. -struct b3RayCastInput -{ - b3Vec3 p1; // first point on segment - b3Vec3 p2; // second point on segment - float32 maxFraction; // maximum intersection -}; - -// Output of ray cast query. -struct b3RayCastOutput -{ - float32 fraction; // time of intersection - b3Vec3 normal; // surface normal of intersection -}; +/////////////////////////////////////////////////////////////////////////////////////////////////// // Find the closest point for a point P to a normalized plane. b3Vec3 b3ClosestPointOnPlane(const b3Vec3& P, const b3Plane& plane); @@ -59,9 +45,26 @@ void b3ClosestPointsOnNormalizedLines(b3Vec3* C1, b3Vec3* C2, const b3Vec3& P1, const b3Vec3& N1, const b3Vec3& P2, const b3Vec3& N2); -// Find the closest points of two segments P1-Q1 to a segment P2-Q2. +// Find the closest points of two segments. void b3ClosestPointsOnSegments(b3Vec3* C1, b3Vec3* C2, const b3Vec3& P1, const b3Vec3& Q1, const b3Vec3& P2, const b3Vec3& Q2); +/////////////////////////////////////////////////////////////////////////////////////////////////// + +// Input for a ray cast. +struct b3RayCastInput +{ + b3Vec3 p1; // first point on segment + b3Vec3 p2; // second point on segment + float32 maxFraction; // maximum intersection +}; + +// Output of a ray cast. +struct b3RayCastOutput +{ + float32 fraction; // time of intersection on ray-segment + b3Vec3 normal; // surface normal of intersection +}; + #endif \ No newline at end of file diff --git a/include/bounce/collision/gjk/gjk.h b/include/bounce/collision/gjk/gjk.h index 75e6a4b..652d331 100644 --- a/include/bounce/collision/gjk/gjk.h +++ b/include/bounce/collision/gjk/gjk.h @@ -19,7 +19,7 @@ #ifndef B3_GJK_H #define B3_GJK_H -#include +#include class b3GJKProxy; struct b3SimplexCache; @@ -30,8 +30,8 @@ struct b3SimplexVertex b3Vec3 pointB; // support vertex on proxy B b3Vec3 point; // minkowski vertex float32 weight; // barycentric coordinate for point - u32 indexA; // support A index - u32 indexB; // support B index + u32 indexA; // support A vertex index + u32 indexB; // support B vertex index }; struct b3Simplex @@ -58,7 +58,8 @@ struct b3Simplex // The output of the GJK algorithm. // It contains the closest points between two proxies // and their euclidean distance. -struct b3GJKOutput +// If the distance is zero then the proxies are overlapping. +struct b3GJKOutput { b3Vec3 pointA; // closest point on proxy A b3Vec3 pointB; // closest point on proxy B @@ -67,8 +68,7 @@ struct b3GJKOutput }; // Find the closest points and distance between two proxies. -// If the distance is zero then the proxies are overlapping. b3GJKOutput b3GJK(const b3Transform& xfA, const b3GJKProxy& proxyA, const b3Transform& xfB, const b3GJKProxy& proxyB); -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/gjk/gjk_cache.h b/include/bounce/collision/gjk/gjk_cache.h index e58306b..51c8ffd 100644 --- a/include/bounce/collision/gjk/gjk_cache.h +++ b/include/bounce/collision/gjk/gjk_cache.h @@ -19,15 +19,16 @@ #ifndef B3_GJK_CACHE_H #define B3_GJK_CACHE_H -#include +#include -// A simplex used to improve the performance +// A cached simplex is used to improve the performance // of the GJK when called more than once. // Make sure to set cache.count to zero before -// calling the GJK for the first time. +// passing this structure as an argument to GJK when called +// for the first time. struct b3SimplexCache { - float32 metric; // length or area or volume + float32 metric; // distance or area or volume u32 iterations; // number of GJK iterations u16 count; // number of support vertices u8 indexA[4]; // support vertices on proxy A @@ -36,11 +37,13 @@ struct b3SimplexCache // Find the closest points and distance between two proxies. // Assumes a simplex is given for increasing the performance of -// the GJK when called more than once. +// the algorithm when called more than once. b3GJKOutput b3GJK(const b3Transform& xfA, const b3GJKProxy& proxyA, const b3Transform& xfB, const b3GJKProxy& proxyB, bool applyRadius, b3SimplexCache* cache); +// A feature pair contains the vertices of the features associated +// with the closest points. struct b3GJKFeaturePair { enum Type @@ -57,10 +60,10 @@ struct b3GJKFeaturePair u32 indexB[3]; // vertices on proxy B }; -// Get the vertices of the features that the closest points between two +// Identify the vertices of the features that the closest points between two // GJK proxies are contained on given a cached simplex. // The GJK must have been called using the pair of proxies and // cache.count must be < 4, that is, the proxies must not be overlapping. b3GJKFeaturePair b3GetFeaturePair(const b3SimplexCache& cache); -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/gjk/gjk_proxy.h b/include/bounce/collision/gjk/gjk_proxy.h index b29ace4..a9189e1 100644 --- a/include/bounce/collision/gjk/gjk_proxy.h +++ b/include/bounce/collision/gjk/gjk_proxy.h @@ -19,31 +19,31 @@ #ifndef B3_GJK_PROXY_H #define B3_GJK_PROXY_H -#include +#include // A GJK proxy encapsulates any convex hull to be used by the GJK. class b3GJKProxy { public: - b3GJKProxy() : m_vertices(nullptr), m_count(0), m_radius(0.0f) { } + b3GJKProxy() : m_vertices(NULL), m_count(0), m_radius(0.0f) { } - // Get the number of vertices of this proxy. + // Get the number of vertices in this proxy. u32 GetVertexCount() const; // Read an indexed vertex from this proxy. const b3Vec3& GetVertex(u32 index) const; // Get the support vertex index in a given direction. - u32 GetSupportIndex(const b3Vec3& d) const; + u32 GetSupportIndex(const b3Vec3& direction) const; // Convenience function. // Get the support vertex in a given direction. - const b3Vec3& GetSupportVertex(const b3Vec3& d) const; + const b3Vec3& GetSupportVertex(const b3Vec3& direction) const; - b3Vec3 m_buffer[3]; // for childs - const b3Vec3* m_vertices; - u32 m_count; - float32 m_radius; + const b3Vec3* m_vertices; // vertices in this proxy + u32 m_count; // number of vertices + float32 m_radius; // shape radius + b3Vec3 m_buffer[3]; // vertices from a child shape }; inline u32 b3GJKProxy::GetVertexCount() const @@ -79,4 +79,4 @@ inline const b3Vec3& b3GJKProxy::GetSupportVertex(const b3Vec3& d) const return m_vertices[index]; } -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/sat/sat.h b/include/bounce/collision/sat/sat.h index 5992864..afb2431 100644 --- a/include/bounce/collision/sat/sat.h +++ b/include/bounce/collision/sat/sat.h @@ -19,7 +19,7 @@ #ifndef B3_SAT_H #define B3_SAT_H -#include +#include struct b3Hull; diff --git a/include/bounce/collision/sat/sat_edge_and_hull.h b/include/bounce/collision/sat/sat_edge_and_hull.h index cacc941..1b796c5 100644 --- a/include/bounce/collision/sat/sat_edge_and_hull.h +++ b/include/bounce/collision/sat/sat_edge_and_hull.h @@ -16,10 +16,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef B3_EDGE_SAT_H -#define B3_EDGE_SAT_H +#ifndef B3_EDGE_HULL_SAT_H +#define B3_EDGE_HULL_SAT_H -#include +#include struct b3Capsule; @@ -37,4 +37,4 @@ float32 b3ProjectEdge(const b3Vec3& P1, const b3Vec3& E1, const b3Vec3& P2, cons b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xfA, const b3Capsule* hullA, const b3Transform& xfB, const b3Hull* hullB); -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/sat/sat_vertex_and_hull.h b/include/bounce/collision/sat/sat_vertex_and_hull.h index 0a5fea4..24c8de6 100644 --- a/include/bounce/collision/sat/sat_vertex_and_hull.h +++ b/include/bounce/collision/sat/sat_vertex_and_hull.h @@ -16,10 +16,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef B3_VERTEX_SAT_H -#define B3_VERTEX_SAT_H +#ifndef B3_VERTEX_HULL_SAT_H +#define B3_VERTEX_HULL_SAT_H -#include +#include struct b3Sphere; diff --git a/include/bounce/collision/shapes/aabb3.h b/include/bounce/collision/shapes/aabb3.h index 137e1be..5206ef5 100644 --- a/include/bounce/collision/shapes/aabb3.h +++ b/include/bounce/collision/shapes/aabb3.h @@ -19,11 +19,15 @@ #ifndef B3_AABB_3_H #define B3_AABB_3_H -#include +#include // A min-max representation of a three-dimensional AABB. struct b3AABB3 { + b3Vec3 m_lower; // lower vertex + b3Vec3 m_upper; // upper vertex + + // Get the support vertex in a given direction. b3Vec3 GetSupportVertex(const b3Vec3& direction) const { b3Vec3 support; @@ -128,7 +132,7 @@ struct b3AABB3 } // Test if this AABB contains a point. - bool TestPoint(const b3Vec3& point) const + bool Contains(const b3Vec3& point) const { return m_lower.x <= point.x && point.x <= m_upper.x && m_lower.y <= point.y && point.y <= m_upper.y && @@ -138,11 +142,11 @@ struct b3AABB3 // Test if this AABB contains another AABB. bool Contains(const b3AABB3& aabb) const { - return TestPoint(aabb.m_lower) && TestPoint(aabb.m_upper); + return Contains(aabb.m_lower) && Contains(aabb.m_upper); } - // Test if a ray intersect this AABB. - // Output the minimum fraction to derive the intersection point. + // Test if a ray intersects this AABB. + // Output the minimum and maximum intersection fractions to derive the minimum and maximum intersection points. bool TestRay(const b3Vec3& p1, const b3Vec3& p2, float32 maxFraction, float32& minFraction) const { // Solve segment to slab plane. @@ -159,9 +163,10 @@ struct b3AABB3 for (u32 i = 0; i < 3; ++i) { float32 numerators[2], denominators[2]; - //numerators[0] = (-m_lower[i]) - (-p1[i]); + numerators[0] = p1[i] - m_lower[i]; numerators[1] = m_upper[i] - p1[i]; + denominators[0] = -d[i]; denominators[1] = d[i]; @@ -215,9 +220,6 @@ struct b3AABB3 minFraction = lower; return true; } - - b3Vec3 m_lower; // lower vertex - b3Vec3 m_upper; // upper vertex }; // Compute an AABB that encloses two AABBs. @@ -236,4 +238,4 @@ inline bool b3TestOverlap(const b3AABB3& a, const b3AABB3& b) (a.m_upper.x >= b.m_lower.x) && (a.m_upper.y >= b.m_lower.y) && (a.m_upper.z >= b.m_lower.z); } -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/shapes/box_hull.h b/include/bounce/collision/shapes/box_hull.h index f83b1f5..690c10c 100644 --- a/include/bounce/collision/shapes/box_hull.h +++ b/include/bounce/collision/shapes/box_hull.h @@ -19,7 +19,7 @@ #ifndef B3_BOX_HULL_H #define B3_BOX_HULL_H -#include +#include struct b3BoxHull : public b3Hull { @@ -28,9 +28,10 @@ struct b3BoxHull : public b3Hull b3Face boxFaces[6]; b3Plane boxPlanes[6]; + // Does nothing for performance. b3BoxHull() { } - // Set this box to the unit box. + // Set this box to the unit box centered at the origin. void SetIdentity() { boxVertices[0] = b3Vec3(1.0f, 1.0f, -1.0f); @@ -90,9 +91,18 @@ struct b3BoxHull : public b3Hull planes = boxPlanes; faceCount = 6; } + + // Set this box from three extents and centered at the origin. + void Set(float32 ex, float32 ey, float32 ez) + { + b3Transform xf; + xf.position.SetZero(); + xf.rotation = b3Diagonal(ex, ey, ez); + SetTransform(xf); + } - // Set this box to the unit box and transform - // it. The transform must not contain non-uniform + // Set this box to the unit box and transform it. + // Warning: The transform must not contain non-uniform // scaling! void SetTransform(const b3Transform& T) { @@ -162,4 +172,4 @@ struct b3BoxHull : public b3Hull } }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/shapes/capsule.h b/include/bounce/collision/shapes/capsule.h index 49ca261..7ad03b1 100644 --- a/include/bounce/collision/shapes/capsule.h +++ b/include/bounce/collision/shapes/capsule.h @@ -19,7 +19,7 @@ #ifndef B3_CAPSULE_H #define B3_CAPSULE_H -#include +#include struct b3Capsule { @@ -27,7 +27,6 @@ struct b3Capsule float32 radius; const b3Vec3& GetVertex(u32 index) const; - u32 GetSupportVertex(const b3Vec3& direction) const; }; @@ -36,13 +35,13 @@ inline const b3Vec3& b3Capsule::GetVertex(u32 index) const return vertices[index]; } -inline u32 b3Capsule::GetSupportVertex(const b3Vec3& direction) const +inline u32 b3Capsule::GetSupportVertex(const b3Vec3& d) const { - if (b3Dot(direction, vertices[0]) > b3Dot(direction, vertices[1])) + if (b3Dot(d, vertices[0]) > b3Dot(d, vertices[1])) { return 0; } return 1; } -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/shapes/hull.h b/include/bounce/collision/shapes/hull.h index 909673a..c3a43e9 100644 --- a/include/bounce/collision/shapes/hull.h +++ b/include/bounce/collision/shapes/hull.h @@ -19,7 +19,7 @@ #ifndef B3_HULL_H #define B3_HULL_H -#include +#include struct b3Face { @@ -52,14 +52,14 @@ struct b3Hull u32 GetSupportVertex(const b3Vec3& direction) const; u32 GetSupportFace(const b3Vec3& direction) const; - b3Plane GetEdgeSidePlane(u32 index) const; + u32 GetSize() const; void Validate() const; void Validate(const b3Face* face) const; void Validate(const b3HalfEdge* edge) const; }; -#include +#include #endif \ No newline at end of file diff --git a/include/bounce/collision/shapes/mesh.h b/include/bounce/collision/shapes/mesh.h index 3298a33..dfdefc6 100644 --- a/include/bounce/collision/shapes/mesh.h +++ b/include/bounce/collision/shapes/mesh.h @@ -19,8 +19,8 @@ #ifndef B3_MESH_H #define B3_MESH_H -#include -#include +#include +#include struct b3Mesh { diff --git a/include/bounce/collision/shapes/sphere.h b/include/bounce/collision/shapes/sphere.h index 5746b01..49198d5 100644 --- a/include/bounce/collision/shapes/sphere.h +++ b/include/bounce/collision/shapes/sphere.h @@ -19,7 +19,7 @@ #ifndef B3_SPHERE_H #define B3_SPHERE_H -#include +#include struct b3Sphere { @@ -27,7 +27,6 @@ struct b3Sphere float32 radius; const b3Vec3& GetVertex(u32 index) const; - u32 GetSupportVertex(const b3Vec3& direction) const; }; diff --git a/include/bounce/collision/shapes/triangle_hull.h b/include/bounce/collision/shapes/triangle_hull.h index c3f2417..1ed5964 100644 --- a/include/bounce/collision/shapes/triangle_hull.h +++ b/include/bounce/collision/shapes/triangle_hull.h @@ -19,7 +19,7 @@ #ifndef B3_TRIANGLE_HULL_H #define B3_TRIANGLE_HULL_H -#include +#include struct b3TriangleHull : public b3Hull { @@ -37,9 +37,7 @@ struct b3TriangleHull : public b3Hull void Set(const b3Vec3& A, const b3Vec3& B, const b3Vec3& C) { - const float32 kInv3 = 1.0f / 3.0f; - - centroid = kInv3 * (A + B + C); + centroid = (A + B + C) / 3.0f; triangleVertices[0] = A; triangleVertices[1] = B; @@ -73,4 +71,4 @@ struct b3TriangleHull : public b3Hull } }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/trees/dynamic_tree.h b/include/bounce/collision/trees/dynamic_tree.h index 6d953dc..ad3b01f 100644 --- a/include/bounce/collision/trees/dynamic_tree.h +++ b/include/bounce/collision/trees/dynamic_tree.h @@ -19,21 +19,21 @@ #ifndef B3_DYNAMIC_TREE_H #define B3_DYNAMIC_TREE_H -#include -#include -#include -#include +#include +#include +#include +#include #define NULL_NODE (-1) -// An AABB tree for dynamic AABBs. +// AABB tree for dynamic AABBs. class b3DynamicTree { public : b3DynamicTree(); ~b3DynamicTree(); - // Insert a node to the tree and return its ID. + // Insert a node into the tree and return its ID. i32 InsertNode(const b3AABB3& aabb, void* userData); // Remove a node from the tree. @@ -48,7 +48,7 @@ public : // Get the data associated with a given proxy. void* GetUserData(i32 proxyId) const; - // Check if two aabbs of this tree are overlapping. + // Check if two aabbs in this tree are overlapping. bool TestOverlap(i32 proxy1, i32 proxy2) const; // Keep reporting the client callback the AABBs that are overlapping with @@ -61,22 +61,24 @@ public : // the given ray. The client callback must return the new intersection fraction. // If the fraction == 0 then the query is cancelled immediately. template - void QueryRay(T* callback, const b3RayCastInput& input) const; + void RayCast(T* callback, const b3RayCastInput& input) const; // Validate a given node of this tree. void Validate(i32 node) const; // Draw this tree. - void Draw(b3Draw* b3Draw) const; + void Draw(b3Draw* draw) const; private : struct b3Node { + // Is this node a leaf? bool IsLeaf() const { - return child1 == NULL_NODE; //or child 2 == NULL_NODE, or height == 0. + //A node is a leaf if child 2 == NULL_NODE or height == 0. + return child1 == NULL_NODE; } - // The (enlarged) AABB of this node. + // The fattened node AABB. b3AABB3 aabb; // The associated user data. @@ -91,31 +93,30 @@ private : i32 child1; i32 child2; - // leaf = 0, free node = -1 + // leaf if 0, free node if -1 i32 height; }; - // Insert a allocated (leaf) node into the tree. + // Insert a node into the tree. void InsertLeaf(i32 node); - // Remove a allocated node from the tree. + // Remove a node from the tree. void RemoveLeaf(i32 node); - // Rebuild the tree hierarchy starting from the given node. + // Rebuild the hierarchy starting from the given node. void WalkBackNodeAndCombineVolumes(i32 node); - // Perform a basic surface area heuristic search to find the best - // node that can be merged with a given AABB. - i32 HeuristicSearch(const b3AABB3& leafAABB) const; + // Find the best node that can be merged with a given AABB. + i32 FindBest(const b3AABB3& aabb) const; // Peel a node from the free list and insert into the node array. // Allocate a new node if necessary. The function returns the new node index. i32 AllocateNode(); - // Free a node (not destroy) from the node pool and add it to the free list. + // Free a node from the node pool and add it to the free list. void FreeNode(i32 node); - // Make a node available for the next allocation request. + // Make a node available for the next allocation. void AddToFreeList(i32 node); // The root of this tree. @@ -128,25 +129,25 @@ private : i32 m_freeList; }; -inline bool b3DynamicTree::TestOverlap(i32 proxy1, i32 proxy2) const -{ - B3_ASSERT(proxy1 < m_nodeCount); - B3_ASSERT(proxy2 < m_nodeCount); - return b3TestOverlap(m_nodes[proxy1].aabb, m_nodes[proxy2].aabb); -} - -inline const b3AABB3& b3DynamicTree::GetAABB(i32 proxyId) const +inline const b3AABB3& b3DynamicTree::GetAABB(i32 proxyId) const { B3_ASSERT(proxyId < m_nodeCount); return m_nodes[proxyId].aabb; } -inline void* b3DynamicTree::GetUserData(i32 proxyId) const +inline void* b3DynamicTree::GetUserData(i32 proxyId) const { B3_ASSERT(proxyId < m_nodeCount); return m_nodes[proxyId].userData; } +inline bool b3DynamicTree::TestOverlap(i32 proxy1, i32 proxy2) const +{ + B3_ASSERT(proxy1 < m_nodeCount); + B3_ASSERT(proxy2 < m_nodeCount); + return b3TestOverlap(m_nodes[proxy1].aabb, m_nodes[proxy2].aabb); +} + template inline void b3DynamicTree::QueryAABB(T* callback, const b3AABB3& aabb) const { @@ -184,14 +185,14 @@ inline void b3DynamicTree::QueryAABB(T* callback, const b3AABB3& aabb) const } template -inline void b3DynamicTree::QueryRay(T* callback, const b3RayCastInput& input) const +inline void b3DynamicTree::RayCast(T* callback, const b3RayCastInput& input) const { b3Vec3 p1 = input.p1; b3Vec3 p2 = input.p2; b3Vec3 d = p2 - p1; float32 maxFraction = input.maxFraction; - // Ensure non-degeneracy. + // Ensure non-degenerate segment. B3_ASSERT(b3Dot(d, d) > B3_EPSILON * B3_EPSILON); b3Stack stack; @@ -237,4 +238,4 @@ inline void b3DynamicTree::QueryRay(T* callback, const b3RayCastInput& input) co } } -#endif +#endif \ No newline at end of file diff --git a/include/bounce/collision/trees/static_tree.h b/include/bounce/collision/trees/static_tree.h index 3acc8cb..d09c293 100644 --- a/include/bounce/collision/trees/static_tree.h +++ b/include/bounce/collision/trees/static_tree.h @@ -19,28 +19,28 @@ #ifndef B3_STATIC_TREE_H #define B3_STATIC_TREE_H -#include -#include -#include -#include +#include +#include +#include +#include #define NULL_NODE_S (0xFFFFFFFF) -// An AABB tree for static AABBs. +// AABB tree for static AABBs. class b3StaticTree { public: b3StaticTree(); ~b3StaticTree(); - // Build the tree. - // Output a sorted index array. + // Build this tree from a list of AABBs and the list + // of indices to the AABBs. void Build(u32* indices, const b3AABB3* aabbs, u32 count); // Get the AABB of a given proxy. const b3AABB3& GetAABB(u32 proxyId) const; - // Get the index associated of a given proxy. + // Get the user data associated with a given proxy. u32 GetUserData(u32 proxyId) const; // Report the client callback all AABBs that are overlapping with @@ -53,10 +53,10 @@ public: // the given ray. The client callback must return the new intersection fraction // (real). If the fraction == 0 then the query is cancelled immediatly. template - void QueryRay(T* callback, const b3RayCastInput& input) const; + void RayCast(T* callback, const b3RayCastInput& input) const; - // Draw the hierarchy. - void Draw(b3Draw* b3Draw) const; + // Draw this tree. + void Draw(b3Draw* draw) const; private : // A node in a static tree. struct b3Node @@ -69,13 +69,14 @@ private : u32 index; }; - // Check if a node is a leaf node + // Is this node a leaf? bool IsLeaf() const { return child1 == NULL_NODE_S; } }; + // The nodes of this tree stored in an array. u32 m_nodeCount; b3Node* m_nodes; }; @@ -109,7 +110,12 @@ inline void b3StaticTree::QueryAABB(T* callback, const b3AABB3& aabb) const while (stack.IsEmpty() == false) { u32 nodeIndex = stack.Top(); - + + if (nodeIndex == NULL_NODE_S) + { + continue; + } + stack.Pop(); const b3Node* node = m_nodes + nodeIndex; @@ -133,7 +139,7 @@ inline void b3StaticTree::QueryAABB(T* callback, const b3AABB3& aabb) const } template -inline void b3StaticTree::QueryRay(T* callback, const b3RayCastInput& input) const +inline void b3StaticTree::RayCast(T* callback, const b3RayCastInput& input) const { if (m_nodeCount == 0) { @@ -145,7 +151,7 @@ inline void b3StaticTree::QueryRay(T* callback, const b3RayCastInput& input) con b3Vec3 d = p2 - p1; float32 maxFraction = input.maxFraction; - // Ensure non-degeneracy. + // Ensure non-degenerate segment. B3_ASSERT(b3Dot(d, d) > B3_EPSILON * B3_EPSILON); u32 root = 0; diff --git a/include/bounce/common/draw.h b/include/bounce/common/draw.h index 1703ccf..fb35cfd 100644 --- a/include/bounce/common/draw.h +++ b/include/bounce/common/draw.h @@ -19,10 +19,10 @@ #ifndef B3_DRAW_H #define B3_DRAW_H -#include -#include +#include +#include -// Color channels used by the debug b3Draw interface. +// Color channels used by the debug draw interface. struct b3Color { b3Color() { } @@ -32,11 +32,11 @@ struct b3Color float32 r, g, b, a; }; -// Implement this interface and set to a world so it can b3Draw the physics entities. +// Implement this interface and set to a world so it can draw the physics entities. class b3Draw { public : - // Bit flags to tell the world what needs to be b3Draw. + // Bit flags to tell the world what needs to be draw. enum b3Flags { e_shapesFlag = 0x0001, @@ -88,10 +88,10 @@ public : // Draw a AABB. virtual void DrawAABB(const b3AABB3& aabb, const b3Color& color) = 0; - // Draw a b3Transform. + // Draw a transform. virtual void DrawTransform(const b3Transform& xf) = 0; - // Debug b3Draw flags. + // Debug draw flags. u32 m_flags; }; diff --git a/include/bounce/common/geometry.h b/include/bounce/common/geometry.h index e2c4b4c..8fbc1d6 100644 --- a/include/bounce/common/geometry.h +++ b/include/bounce/common/geometry.h @@ -19,8 +19,8 @@ #ifndef B3_GEOMETRY_H #define B3_GEOMETRY_H -#include -#include +#include +#include // A triangle in indexed form. struct b3Triangle @@ -106,13 +106,13 @@ inline b3Plane b3Mul(const b3Transform& T, const b3Plane& plane) return b3Plane(normal, plane.offset + b3Dot(normal, T.position)); } +// Compute the distance between a point and a plane. inline float32 b3Distance(const b3Vec3& P, const b3Plane& plane) { return b3Dot(plane.normal, P) - plane.offset; } -// Project a point onto a plane. -// The plane must be normalized. +// Project a point onto a normal plane. inline b3Vec3 b3Project(const b3Vec3& P, const b3Plane& plane) { float32 fraction = b3Distance(P, plane); diff --git a/include/bounce/common/math/mat.h b/include/bounce/common/math/mat.h index 15658f7..e30a0c9 100644 --- a/include/bounce/common/math/mat.h +++ b/include/bounce/common/math/mat.h @@ -19,7 +19,7 @@ #ifndef B3_MAT_H #define B3_MAT_H -#include +#include // A vector stored in column-major order. template @@ -79,7 +79,10 @@ struct b3Mat }; // Solve Ax = b. -// Warning: Make sure to pass a copy of A to the function. It will be invalidated. +// It doesn't compute the inverse. +// Therefore, is more efficient. +// Returns false if the matrix is singular. +// Warning: Make sure to pass a copy of the original matrix to the function. A will be invalidated. bool b3Solve(float32* b, float32* A, u32 n); -#endif +#endif \ No newline at end of file diff --git a/include/bounce/common/math/mat22.h b/include/bounce/common/math/mat22.h index 9266d50..d4ca2f2 100644 --- a/include/bounce/common/math/mat22.h +++ b/include/bounce/common/math/mat22.h @@ -19,7 +19,7 @@ #ifndef B3_MAT_22_H #define B3_MAT_22_H -#include +#include // A 2-by-2 matrix stored in column-major order. struct b3Mat22 @@ -27,7 +27,7 @@ struct b3Mat22 // Does nothing for performance. b3Mat22() { } - // Set this matrix from two vector elements. + // Set this matrix from two vectors. b3Mat22(const b3Vec2& _x, const b3Vec2& _y) : x(_x), y(_y) { } // Solve Ax = b. diff --git a/include/bounce/common/math/mat33.h b/include/bounce/common/math/mat33.h index 13a3511..ae681f7 100644 --- a/include/bounce/common/math/mat33.h +++ b/include/bounce/common/math/mat33.h @@ -19,7 +19,7 @@ #ifndef B3_MAT_33_H #define B3_MAT_33_H -#include +#include // A 3-by-3 matrix stored in column-major order. struct b3Mat33 @@ -27,7 +27,7 @@ struct b3Mat33 // Does nothing for performance. b3Mat33() { } - // Set this matrix from three elements. + // Set this matrix from three column vectors. b3Mat33(const b3Vec3& _x, const b3Vec3& _y, const b3Vec3& _z) : x(_x), y(_y), z(_z) { } // Read an indexed column vector from this matrix. @@ -42,6 +42,12 @@ struct b3Mat33 return (&x)[i]; } + // Read an indexed element from this matrix. + float32 operator()(u32 i, u32 j) const + { + return (&x.x)[i + 3 * j]; + } + // Add a matrix to this matrix. void operator+=(const b3Mat33& B) { @@ -72,11 +78,6 @@ struct b3Mat33 // Returns the zero vector if the matrix is singular. b3Vec3 Solve(const b3Vec3& b) const; - float32 operator()(u32 i, u32 j) const - { - return (&x.x)[i + 3 * j]; - } - b3Vec3 x, y, z; }; @@ -134,7 +135,7 @@ inline b3Mat33 b3Mul(const b3Mat33& A, const b3Mat33& B) // Multiply the transpose of a matrix times a vector. If // the matrix represents a rotation frame this transforms the -// vector from one frame to another (inverse b3Transform). +// vector from one frame to another (inverse transform). inline b3Vec3 b3MulT(const b3Mat33& A, const b3Vec3& v) { return b3Vec3(b3Dot(A.x, v), b3Dot(A.y, v), b3Dot(A.z, v)); diff --git a/include/bounce/common/math/math.h b/include/bounce/common/math/math.h index 85e522f..17522cb 100644 --- a/include/bounce/common/math/math.h +++ b/include/bounce/common/math/math.h @@ -20,7 +20,7 @@ #define B3_MATH_H #include -#include +#include inline bool b3IsValid(float32 fx) { @@ -30,13 +30,13 @@ inline bool b3IsValid(float32 fx) inline float32 b3Sqrt(float32 x) { - return sqrtf(x); + return std::sqrt(x); } template inline T b3Abs(T x) { - return abs(x); + return std::abs(x); } template diff --git a/include/bounce/common/math/quat.h b/include/bounce/common/math/quat.h index 4b02508..fa88783 100644 --- a/include/bounce/common/math/quat.h +++ b/include/bounce/common/math/quat.h @@ -19,10 +19,10 @@ #ifndef B3_QUAT_H #define B3_QUAT_H -#include -#include +#include +#include -// A quaternion represents an orientation with 4 real numbers. +// A quaternion can represent an orientation with 4 scalars. struct b3Quat { // Default constructor does nothing for performance. @@ -157,13 +157,13 @@ inline b3Quat b3Normalize(const b3Quat& q) return b3Quat(0.0f, 0.0f, 0.0f, 1.0f); } -// Compute the dot poduct of two quaternions. +// Perform the dot poduct of two quaternions. inline float b3Dot(const b3Quat& a, const b3Quat& b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } -// Compute the conjugate of a quaternion. +// Conjugate of a quaternion. inline b3Quat b3Conjugate(const b3Quat& q) { return b3Quat(-q.x, -q.y, -q.z, q.w); @@ -230,7 +230,6 @@ inline b3Quat b3Slerp(const b3Quat& a, const b3Quat& b, float32 fraction) b3Quat q1 = sin(w1 * angle) * a; b3Quat q2 = sin(w2 * angle) * b2; float32 invSin = 1.0f / sine; - return invSin * (q1 + q2); } diff --git a/include/bounce/common/math/transform.h b/include/bounce/common/math/transform.h index cdfdc76..b4baf2f 100644 --- a/include/bounce/common/math/transform.h +++ b/include/bounce/common/math/transform.h @@ -19,10 +19,10 @@ #ifndef B3_TRANSFORM_H #define B3_TRANSFORM_H -#include -#include +#include +#include -// A b3Transform represents a rigid frame. +// A transform represents a rigid frame. // It has a translation representing a position // and a rotation representing an orientation. struct b3Transform @@ -30,7 +30,7 @@ struct b3Transform // Default ctor does nothing for performance. b3Transform() { } - // Set this b3Transform from a translation vector and an orientation + // Set this transform from a translation vector and an orientation // quaternion. b3Transform(const b3Vec3& p, const b3Quat& q) { @@ -38,7 +38,7 @@ struct b3Transform rotation = b3ConvertQuatToRot(q); } - // Set this b3Transform to the identity. + // Set this transform to the identity. void SetIdentity() { position.SetZero(); @@ -61,7 +61,7 @@ struct b3Sweep b3Vec3 worldCenter; // world center b3Quat orientation; // world orientation - // Get this sweep b3Transform at a given time between [0, 1] + // Get this sweep transform at a given time between [0, 1] b3Transform GetTransform(float32 t) const; // Advance to a new initial state. @@ -90,7 +90,7 @@ inline void b3Sweep::Advance(float32 t) t0 = t; } -// Multiply a b3Transform times a vector. If the b3Transform +// Multiply a transform times a vector. If the transform // represents a frame this returns the vector in terms // of the frame. inline b3Vec3 operator*(const b3Transform& T, const b3Vec3& v) @@ -98,7 +98,7 @@ inline b3Vec3 operator*(const b3Transform& T, const b3Vec3& v) return b3Mul(T.rotation, v) + T.position; } -// Multiply a b3Transform times another b3Transform (composed b3Transform). +// Multiply a transform times another transform (composed transform). // [A y][B x] = [AB Ax+y] // [0 1][0 1] [0 1 ] inline b3Transform operator*(const b3Transform& A, const b3Transform& B) @@ -109,13 +109,13 @@ inline b3Transform operator*(const b3Transform& A, const b3Transform& B) return C; } -// Multiply a b3Transform times a vector. +// Multiply a transform times a vector. inline b3Vec3 b3Mul(const b3Transform& T, const b3Vec3& v) { return b3Mul(T.rotation, v) + T.position; } -// Multiply a b3Transform times another b3Transform. +// Multiply a transform times another transform. // [A y][B x] = [AB Ax+y] // [0 1][0 1] [0 1 ] inline b3Transform b3Mul(const b3Transform& A, const b3Transform& B) @@ -126,8 +126,8 @@ inline b3Transform b3Mul(const b3Transform& A, const b3Transform& B) return C; } -// Multiply the transpose of one b3Transform (inverse -// b3Transform) times another b3Transform (composed b3Transform). +// Multiply the transpose of one transform (inverse +// transform) times another transform (composed transform). //[A^-1 -A^-1*y][B x] = [A^-1*B A^-1(x-y)] //[0 1 ][0 1] [0 1 ] inline b3Transform b3MulT(const b3Transform& A, const b3Transform& B) @@ -138,9 +138,9 @@ inline b3Transform b3MulT(const b3Transform& A, const b3Transform& B) return C; } -// Multiply the transpose of a b3Transform times a vector. -// If the b3Transform represents a frame then this transforms -// the vector from one frame to another (inverse b3Transform). +// Multiply the transpose of a transform times a vector. +// If the transform represents a frame then this transforms +// the vector from one frame to another (inverse transform). //[A^-1 -A^-1*y][x] = A^-1*x - A^-1*y = A^-1 * (x - y) //[0 1 ][1] inline b3Vec3 b3MulT(const b3Transform& A, const b3Vec3& v) @@ -148,7 +148,7 @@ inline b3Vec3 b3MulT(const b3Transform& A, const b3Vec3& v) return b3MulT(A.rotation, v - A.position); } -// Inverse b3Transform. +// Inverse transform. inline b3Transform b3Inverse(const b3Transform& T) { b3Transform B; diff --git a/include/bounce/common/math/vec2.h b/include/bounce/common/math/vec2.h index f2fe4a3..cf7dcd6 100644 --- a/include/bounce/common/math/vec2.h +++ b/include/bounce/common/math/vec2.h @@ -19,7 +19,7 @@ #ifndef B3_VEC2_H #define B3_VEC2_H -#include +#include // A 2D column vector. struct b3Vec2 diff --git a/include/bounce/common/math/vec3.h b/include/bounce/common/math/vec3.h index 54b9664..20c53f8 100644 --- a/include/bounce/common/math/vec3.h +++ b/include/bounce/common/math/vec3.h @@ -19,7 +19,7 @@ #ifndef B3_VEC_3_H #define B3_VEC_3_H -#include +#include // A 3D column vector. struct b3Vec3 diff --git a/include/bounce/common/memory/block_pool.h b/include/bounce/common/memory/block_pool.h index 22b3bde..583b6b6 100644 --- a/include/bounce/common/memory/block_pool.h +++ b/include/bounce/common/memory/block_pool.h @@ -19,7 +19,7 @@ #ifndef B3_BLOCK_POOL_H #define B3_BLOCK_POOL_H -#include +#include // Number of blocks per chunk. const u32 b3_blockCount = 32; diff --git a/include/bounce/common/memory/stack_allocator.h b/include/bounce/common/memory/stack_allocator.h index a1b3c45..2ac323f 100644 --- a/include/bounce/common/memory/stack_allocator.h +++ b/include/bounce/common/memory/stack_allocator.h @@ -19,13 +19,13 @@ #ifndef B3_STACK_ALLOCATOR_H #define B3_STACK_ALLOCATOR_H -#include +#include // Allocate 10 MiB from the stack. // Increase as you want. const u32 b3_maxStackSize = B3_MiB(10); -// An stack allocator. +// A stack allocator. class b3StackAllocator { public : diff --git a/include/bounce/common/settings.h b/include/bounce/common/settings.h index cd7be98..eb2bc57 100644 --- a/include/bounce/common/settings.h +++ b/include/bounce/common/settings.h @@ -60,7 +60,7 @@ typedef float float32; #define B3_AABB_MULTIPLIER (2.0f) // Collision and constraint tolerance. -#define B3_LINEAR_SLOP (0.005f) +#define B3_LINEAR_SLOP (0.01f) // Collision and constraint tolerance. #define B3_ANGULAR_SLOP (2.0f / 180.0f * B3_PI) diff --git a/include/bounce/common/template/array.h b/include/bounce/common/template/array.h index 42e4500..da21e5d 100644 --- a/include/bounce/common/template/array.h +++ b/include/bounce/common/template/array.h @@ -19,7 +19,7 @@ #ifndef B3_ARRAY_POD_H #define B3_ARRAY_POD_H -#include +#include // An array for bytes (POD). template diff --git a/include/bounce/common/template/list.h b/include/bounce/common/template/list.h index 3a1d336..396ee7c 100644 --- a/include/bounce/common/template/list.h +++ b/include/bounce/common/template/list.h @@ -19,7 +19,7 @@ #ifndef B3_LIST_H #define B3_LIST_H -#include +#include // A singly-linked list. template @@ -28,7 +28,7 @@ class b3List1 public: b3List1() { - m_head = nullptr; + m_head = NULL; m_count = 0; } @@ -58,7 +58,7 @@ class b3List2 public: b3List2() { - m_head = nullptr; + m_head = NULL; m_count = 0; } @@ -66,7 +66,7 @@ public: void PushFront(T* link) { - link->m_prev = nullptr; + link->m_prev = NULL; link->m_next = m_head; if (m_head) { diff --git a/include/bounce/common/template/object_array.h b/include/bounce/common/template/object_array.h index 2e61516..9360f49 100644 --- a/include/bounce/common/template/object_array.h +++ b/include/bounce/common/template/object_array.h @@ -19,7 +19,7 @@ #ifndef B3_OBJECT_ARRAY_H #define B3_OBJECT_ARRAY_H -#include +#include // An array for objects. template diff --git a/include/bounce/common/template/stack.h b/include/bounce/common/template/stack.h index 4908bec..9e9adc9 100644 --- a/include/bounce/common/template/stack.h +++ b/include/bounce/common/template/stack.h @@ -19,7 +19,7 @@ #ifndef B3_STACK_H #define B3_STACK_H -#include +#include // A growable stack for plain-old-data (POD). template @@ -39,7 +39,7 @@ public: { b3Free(m_elements); } - m_elements = nullptr; + m_elements = NULL; } const T& Top() const diff --git a/include/bounce/common/time.h b/include/bounce/common/time.h index 903876d..4625535 100644 --- a/include/bounce/common/time.h +++ b/include/bounce/common/time.h @@ -19,45 +19,195 @@ #ifndef B3_TIME_H #define B3_TIME_H -#include +#include + +#define B3_WINDOWS 1 +#define B3_MAC 2 +#define B3_UNIX 3 + +#if defined (_WIN32) +#define B3_PLATFORM B3_WINDOWS +#elif defined( __APPLE__ ) +#define B3_PLATFORM B3_MAC +#else +#define B3_PLATFORM B3_UNIX +#endif + +#if B3_PLATFORM == B3_WINDOWS + +#include // A timer class that accumulates time. -// Usefull for measuring elapsed times of -// sections of code. +// Usefull for measuring elapsed times between code sections. class b3Time { -public : - b3Time(); +public: + b3Time() + { + LARGE_INTEGER c; + QueryPerformanceCounter(&c); + m_c0 = c.QuadPart; + m_t0 = 0.0; + m_t = 0.0; + } - // Get the accumulated time in miliseconds - // from this timer. - float64 GetCurMilis() const; + // Get the accumulated time in miliseconds from this timer. + float64 GetCurrentMilis() const + { + return m_t; + } // Get the elapsed time since this timer was updated. - float64 GetElapsedMilis() const; + float64 GetElapsedMilis() const + { + return m_t - m_t0; + } - // Add the elapsed time since this function - // was called to this timer. - void Update(); + // Add the elapsed time since this function was called to this timer. + void Update() + { + static float64 inv_frequency = 0.0; + if (inv_frequency == 0.0) + { + LARGE_INTEGER c; + QueryPerformanceFrequency(&c); + + float64 cycles_per_s = float64(c.QuadPart); + float64 s_per_cycle = 1.0 / cycles_per_s; + float64 ms_per_cycle = 1000.0 * s_per_cycle; + inv_frequency = ms_per_cycle; + } + + LARGE_INTEGER c; + QueryPerformanceCounter(&c); + + float64 dt = inv_frequency * float64(c.QuadPart - m_c0); + m_c0 = c.QuadPart; + Add(dt); + } + + // Add time to this timer. + void Add(float64 dt) + { + m_t0 = m_t; + m_t += dt; + } - // Add a given ammout of time to this timer. - void UpdateBy(float64 dt); private: - static float64 m_invFrequency; - - u64 m_lastRealTime; - float64 m_lastTime; - float64 m_curTime; + u64 m_c0; + float64 m_t0; + float64 m_t; }; -inline float64 b3Time::GetCurMilis() const -{ - return m_curTime; -} +#elif B3_PLATFORM == B3_MAC -inline float64 b3Time::GetElapsedMilis() const -{ - return m_curTime - m_lastTime; -} +#include + +// A timer class that accumulates time. +// Usefull for measuring elapsed times between code sections. +class b3Time +{ +public: + b3Time() + { + m_c0 = mach_absolute_time(); + m_t0 = 0.0; + m_t = 0.0; + } + + // Get the accumulated time in miliseconds from this timer. + double GetCurrentMilis() const + { + return m_t; + } + + // Get the elapsed time since this timer was updated. + double GetElapsedMilis() const + { + return m_t - m_t0; + } + + // Add the elapsed time since this function was called to this timer. + void Update() + { + static double inv_frequency = 0.0; + if (inv_frequency == 0.0) + { + mach_timebase_info_data_t info; + mach_timebase_info(&info); + inv_frequency = double(info.numer) / (double(info.denom) * 1.0e6); + } + + uint64_t c = mach_absolute_time(); + double dt = inv_frequency * (double)(c - m_c0); + m_c0 = c; + Add(dt); + } + + // Add time to this timer. + void Add(double dt) + { + m_t0 = m_t; + m_t += dt; + } + +private: + uint64_t m_c0; + double m_t0; + double m_t; +}; + +#else + +#include + +// A timer class that accumulates time. +// Usefull for measuring elapsed times between code sections. +class b3Time +{ +public: + b3Time() + { + clock_gettime(CLOCK_MONOTONIC, &m_c0); + m_t0 = 0.0; + m_t = 0.0; + } + + // Get the accumulated time in miliseconds from this timer. + double GetCurrentMilis() const + { + return m_t; + } + + // Get the elapsed time since this timer was updated. + double GetElapsedMilis() const + { + return m_t - m_t0; + } + + // Add the elapsed time since this function was called to this timer. + void Update() + { + struct timespec c; + clock_gettime(CLOCK_MONOTONIC, &c); + double dt = (double)(c.tv_nsec - m_c0.tv_nsec) * 1.0e-6; + m_c0 = c; + Add(dt); + } + + // Add time to this timer. + void Add(double dt) + { + m_t0 = m_t; + m_t += dt; + } + +private: + struct timespec m_c0; + double m_t0; + double m_t; +}; + +#endif // B3_PLATFORM #endif diff --git a/include/bounce/dynamics/body.h b/include/bounce/dynamics/body.h index 3a39562..1087ffe 100644 --- a/include/bounce/dynamics/body.h +++ b/include/bounce/dynamics/body.h @@ -19,11 +19,11 @@ #ifndef B3_BODY_H #define B3_BODY_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include class b3World; class b3Shape; @@ -51,7 +51,7 @@ struct b3BodyDef fixedRotationX = false; fixedRotationY = false; fixedRotationZ = false; - userData = nullptr; + userData = NULL; position.SetZero(); orientation.SetIdentity(); linearVelocity.SetZero(); @@ -81,6 +81,13 @@ public: // A world manages the body destruction. ~b3Body() { } + // Get the type of the body. + b3BodyType GetType() const; + + // Set the type of the body. + // This will reset the current body inertial properties. + void SetType(b3BodyType type); + // Create a new shape for the body given the shape definition and return a pointer to its clone. // The shape passed to the definition it will be cloned and is not recommended modifying // it inside simulation callbacks. @@ -90,36 +97,20 @@ public: // Destroy a given shape from the body. void DestroyShape(b3Shape* shape); - // Destroy all shapes associated with the body. - void DestroyShapes(); - - // Destroy all contacts associated with the body. - void DestroyContacts(); - - // Destroy all joints connected to the body. - void DestroyJoints(); - // Get the shapes associated with the body. const b3List1& GetShapeList() const; b3List1& GetShapeList(); - // Get the type of the body. - b3BodyType GetType() const; - - // Set the type of the body. - // This will reset the current body inertial properties. - void SetType(b3BodyType type); - // Get the world the body belongs to. const b3World* GetWorld() const; b3World* GetWorld(); - // Get the body world b3Transform. + // Get the body world transform. const b3Transform& GetTransform() const; - // Set the body world b3Transform from a position, axis of rotation and an angle + // Set the body world transform from a position, axis of rotation and an angle // of rotation about the axis. - // However, manipulating a body b3Transform during the simulation may cause non-physical behaviour. + // However, manipulating a body transform during the simulation may cause non-physical behaviour. void SetTransform(const b3Vec3& position, const b3Vec3& axis, float32 angle); // Get the gravity scale of the body. One is used by default. @@ -186,7 +177,7 @@ public: // Get the rotational inertia of the body about the center of mass. Typically in kg/m^3. const b3Mat33& GetInertia() const; - // Get the total kinetic energy of the body. + // Get the total kinetic energy of the body in Joules (kilogram-meters squared per second squared). float32 GetKineticEnergy() const; // Transform a vector to the local space of this body. @@ -242,18 +233,25 @@ private: e_fixedRotationY = 0x0008, e_fixedRotationZ = 0x0010, }; - + + // Destroy all shapes associated with the body. + void DestroyShapes(); + + // Destroy all contacts associated with the body. + void DestroyContacts(); + + // Destroy all joints connected to the body. + void DestroyJoints(); + // Recalculate the mass of the body based on the shapes associated // with it. void ResetMass(); - // Synchronize this body b3Transform with its world + // Synchronize this body transform with its world // center of mass and orientation. void SynchronizeTransform(); - // Compute the body world inertial tensor. - // Compute the shapes world AABBs. - // Usually this is called after the body b3Transform is synchronized. + // Synchronize this body shape AABBs with the synchronized transform. void SynchronizeShapes(); // Check if this body should collide with another. @@ -267,7 +265,7 @@ private: // The shapes attached to this body. b3List1 m_shapeList; - // Bidirectional joint edges for this body + // Joint edges for this body joint graph. b3List2 m_jointEdges; // User associated data (usually an entity). @@ -275,13 +273,16 @@ private: // Body mass. float32 m_mass; + // Inverse body mass. float32 m_invMass; // Inertia about the body local center of mass. b3Mat33 m_I; + // Inverse inertia about the body local center of mass. b3Mat33 m_invI; + // Inverse inertia about the body world center of mass. b3Mat33 m_worldInvI; diff --git a/include/bounce/dynamics/contact_manager.h b/include/bounce/dynamics/contact_manager.h index 6154ccc..a32ffc9 100644 --- a/include/bounce/dynamics/contact_manager.h +++ b/include/bounce/dynamics/contact_manager.h @@ -19,9 +19,9 @@ #ifndef B3_CONTACT_MANAGER_H #define B3_CONTACT_MANAGER_H -#include -#include -#include +#include +#include +#include class b3Shape; class b3Contact; @@ -29,7 +29,7 @@ class b3ContactFilter; class b3ContactListener; struct b3MeshContactLink; -// This is used to avoid b3World pollution. +// Contact delegator for b3World. class b3ContactManager { public: @@ -38,6 +38,8 @@ public: // The broad-phase callback. void AddPair(void* proxyDataA, void* proxyDataB); + // Reference AABBs in mesh contacts need to be synchronized with the + // synchronized body transforms. void SynchronizeShapes(); void FindNewContacts(); @@ -45,7 +47,6 @@ public: void UpdateContacts(); b3Contact* Create(b3Shape* shapeA, b3Shape* shapeB); - void Destroy(b3Contact* c); b3BlockPool m_convexBlocks; diff --git a/include/bounce/dynamics/contacts/collide/clip.h b/include/bounce/dynamics/contacts/collide/clip.h index 27d9c81..ad3f7b2 100644 --- a/include/bounce/dynamics/contacts/collide/clip.h +++ b/include/bounce/dynamics/contacts/collide/clip.h @@ -19,8 +19,8 @@ #ifndef B3_CLIP_H #define B3_CLIP_H -#include -#include +#include +#include #define B3_NULL_EDGE (0xFF) diff --git a/include/bounce/dynamics/contacts/collide/collide.h b/include/bounce/dynamics/contacts/collide/collide.h index c83ec6a..062d7ac 100644 --- a/include/bounce/dynamics/contacts/collide/collide.h +++ b/include/bounce/dynamics/contacts/collide/collide.h @@ -19,11 +19,11 @@ #ifndef B3_COLLIDE_H #define B3_COLLIDE_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include class b3Shape; class b3SphereShape; diff --git a/include/bounce/dynamics/contacts/contact.h b/include/bounce/dynamics/contacts/contact.h index bc53509..a08ed85 100644 --- a/include/bounce/dynamics/contacts/contact.h +++ b/include/bounce/dynamics/contacts/contact.h @@ -19,9 +19,9 @@ #ifndef B3_CONTACT_H #define B3_CONTACT_H -#include -#include -#include +#include +#include +#include struct b3Manifold; struct b3WorldManifold; @@ -58,7 +58,7 @@ struct b3OverlappingPair // todo struct b3TOIEvent { - //float32 t; + float32 t; }; enum b3ContactType diff --git a/include/bounce/dynamics/contacts/contact_cluster.h b/include/bounce/dynamics/contacts/contact_cluster.h index c5cc7aa..6cb09c2 100644 --- a/include/bounce/dynamics/contacts/contact_cluster.h +++ b/include/bounce/dynamics/contacts/contact_cluster.h @@ -19,9 +19,9 @@ #ifndef B3_CONTACT_CLUSTER_H #define B3_CONTACT_CLUSTER_H -#include -#include -#include +#include +#include +#include #define B3_NULL_CLUSTER (-1) @@ -40,7 +40,7 @@ struct b3Observation { u32 manifold; u32 manifoldPoint; - b3Vec3 point; + b3Vec3 point; // normal i32 cluster; // normal }; diff --git a/include/bounce/dynamics/contacts/contact_solver.h b/include/bounce/dynamics/contacts/contact_solver.h index 5db172e..d35b501 100644 --- a/include/bounce/dynamics/contacts/contact_solver.h +++ b/include/bounce/dynamics/contacts/contact_solver.h @@ -19,10 +19,10 @@ #ifndef B3_CONTACT_SOLVER_H #define B3_CONTACT_SOLVER_H -#include -#include -#include -#include +#include +#include +#include +#include class b3StackAllocator; class b3Contact; diff --git a/include/bounce/dynamics/contacts/convex_contact.h b/include/bounce/dynamics/contacts/convex_contact.h index 62ba0ce..22eb9df 100644 --- a/include/bounce/dynamics/contacts/convex_contact.h +++ b/include/bounce/dynamics/contacts/convex_contact.h @@ -19,9 +19,9 @@ #ifndef B3_CONVEX_CONTACT_H #define B3_CONVEX_CONTACT_H -#include -#include -#include +#include +#include +#include class b3ConvexContact : public b3Contact { @@ -36,8 +36,6 @@ private: void Collide(); - void SynchronizeShapes(); - b3Manifold m_stackManifold; b3ConvexCache m_cache; }; diff --git a/include/bounce/dynamics/contacts/manifold.h b/include/bounce/dynamics/contacts/manifold.h index 5742092..00ac7cc 100644 --- a/include/bounce/dynamics/contacts/manifold.h +++ b/include/bounce/dynamics/contacts/manifold.h @@ -19,8 +19,8 @@ #ifndef B3_MANIFOLD_H #define B3_MANIFOLD_H -#include -#include +#include +#include #define B3_NULL_TRIANGLE (0xFFFFFFFF) diff --git a/include/bounce/dynamics/contacts/mesh_contact.h b/include/bounce/dynamics/contacts/mesh_contact.h index d8456a1..8587840 100644 --- a/include/bounce/dynamics/contacts/mesh_contact.h +++ b/include/bounce/dynamics/contacts/mesh_contact.h @@ -19,19 +19,23 @@ #ifndef B3_MESH_CONTACT_H #define B3_MESH_CONTACT_H -#include -#include -#include -#include +#include +#include +#include +#include +// This structure helps replicate the convex contact per convex-triangle pair scenario, +// but efficiently. There is no need to store a manifold here since they're reduced +// by the cluster algorithm. struct b3TriangleCache { - u32 index; + u32 index; // triangle index b3ConvexCache cache; }; class b3MeshContact; +// Links for the world mesh contact link list. struct b3MeshContactLink { b3MeshContact* m_c; @@ -60,16 +64,16 @@ private: void FindNewPairs(); + // Static tree callback. There is no midphase. bool Report(u32 proxyId); // Did the AABB move significantly? bool m_aabbMoved; - // The first shape AABB in the frame of the other shape. + // The AABB A relative to shape B's origin. b3AABB3 m_aabbA; - // Child shapes potentially overlapping with - // the first shape. + // Triangles potentially overlapping with the first shape. u32 m_triangleCapacity; b3TriangleCache* m_triangles; u32 m_triangleCount; @@ -77,8 +81,8 @@ private: // Contact manifolds. b3Manifold m_stackManifolds[B3_MAX_MANIFOLDS]; - // Links to the world mesh contact list. + // Link to the world mesh contact list. b3MeshContactLink m_link; }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/island.h b/include/bounce/dynamics/island.h index 9b1c504..1364fb3 100644 --- a/include/bounce/dynamics/island.h +++ b/include/bounce/dynamics/island.h @@ -19,7 +19,7 @@ #ifndef B3_ISLAND_H #define B3_ISLAND_H -#include +#include class b3StackAllocator; class b3Contact; @@ -90,4 +90,4 @@ private : b3Velocity* m_velocities; }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joint_manager.h b/include/bounce/dynamics/joint_manager.h index bef6662..af66e73 100644 --- a/include/bounce/dynamics/joint_manager.h +++ b/include/bounce/dynamics/joint_manager.h @@ -16,15 +16,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef B3_JOINT_MAN_H -#define B3_JOINT_MAN_H +#ifndef B3_JOINT_MANAGER_H +#define B3_JOINT_MANAGER_H -#include +#include struct b3JointDef; class b3Joint; -// This is used to avoid b3World pollution. +// Joint delegator for b3World. class b3JointManager { public: @@ -36,4 +36,4 @@ public: b3List2 m_jointList; }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joints/cone_joint.h b/include/bounce/dynamics/joints/cone_joint.h index 4719a1a..d51b20d 100644 --- a/include/bounce/dynamics/joints/cone_joint.h +++ b/include/bounce/dynamics/joints/cone_joint.h @@ -19,7 +19,7 @@ #ifndef B3_CONE_JOINT_H #define B3_CONE_JOINT_H -#include +#include struct b3ConeJointDef : public b3JointDef { @@ -32,36 +32,41 @@ struct b3ConeJointDef : public b3JointDef coneAngle = 0.0f; } - // Initialize this definition given an axis, anchor point, and cone angle limit in radians. + // Initialize this definition from bodies, cone axis, anchor point, and full cone angle in radians. void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& axis, const b3Vec3& anchor, float32 angle); - // The joint frame in the frame of body A. + // The joint frame relative to body A's frame. b3Transform localFrameA; - // The joint frame in the frame of body B. + // The joint frame relative to body B's frame. b3Transform localFrameB; - // Enable the joint limit. + // Enable cone angle limit. bool enableLimit; - // The cone angle limit in radians. + // The full cone angle in radians. float32 coneAngle; }; +// This joint constrains the bodies to share a common point (cone tip). +// The relative rotation about the shared axis is the joint angle. +// If the joint angle exceeds the half-cone angle then the axis is shared. +// You can limit the relative rotation with a lower angle limit. +// This joint can be used to create structures such as ragdolls. class b3ConeJoint : public b3Joint { public: - // Get the joint frame in the frame of body A. - const b3Transform& GetFrameA() const; + // Get the joint frame on body A in world coordinates. + b3Transform GetFrameA() const; - // Set the joint frame in the frame of body A. - void SetFrameA(const b3Transform& xf); + // Get the joint frame on body B in world coordinates. + b3Transform GetFrameB() const; - // Get the joint frame in the frame of body B. - const b3Transform& GetFrameB() const; - - // Set the joint frame in the frame of body B. - void SetFrameB(const b3Transform& xf); + // Get the joint frame relative to body A's frame. + const b3Transform& GetLocalFrameA() const; + + // Get the joint frame relative to body B's frame. + const b3Transform& GetLocalFrameB() const; // Is the joint limit enabled? bool IsLimitEnabled() const; @@ -69,14 +74,14 @@ public: // Set the joint limit enabled. void SetEnableLimit(bool bit); - // Get the lower cone angle limit. - float32 GetLowerLimit() const; + // Get the cone angle in radians. + float32 GetConeAngle() const; - // Set the lower cone angle limit. - void SetLimit(float32 lowerAngle); + // Set the cone angle in radians. + void SetConeAngle(float32 angle); // Draw this joint. - void Draw(b3Draw* b3Draw) const; + void Draw(b3Draw* draw) const; private: friend class b3Joint; friend class b3Body; @@ -95,10 +100,9 @@ private: // Solver shared b3Transform m_localFrameA; b3Transform m_localFrameB; - - bool m_enableLimit; float32 m_coneAngle; - + bool m_enableLimit; + // Solver temp u32 m_indexA; u32 m_indexB; @@ -122,4 +126,4 @@ private: b3LimitState m_limitState; }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joints/joint.h b/include/bounce/dynamics/joints/joint.h index 7f2dd22..f0df156 100644 --- a/include/bounce/dynamics/joints/joint.h +++ b/include/bounce/dynamics/joints/joint.h @@ -19,9 +19,9 @@ #ifndef B3_JOINT_H #define B3_JOINT_H -#include -#include -#include +#include +#include +#include class b3Draw; class b3Body; @@ -44,9 +44,9 @@ struct b3JointDef b3JointDef() { type = e_unknownJoint; - bodyA = nullptr; - bodyB = nullptr; - userData = nullptr; + bodyA = NULL; + bodyB = NULL; + userData = NULL; collideLinked = false; } @@ -57,6 +57,7 @@ struct b3JointDef bool collideLinked; }; +// A joint edge to a joint graph, where a body is a vertex and a joint an edge. struct b3JointEdge { b3Body* other; @@ -66,8 +67,7 @@ struct b3JointEdge b3JointEdge* m_next; }; -// This goes inside a joint. -// It holds two bodies that are linked. +// This is stored in a joint. It stores two bodies that are linked by the joint. struct b3LinkedPair { // To the body A joint edge list @@ -79,66 +79,54 @@ struct b3LinkedPair b3JointEdge edgeB; }; -// @note All the data members of the joint structure they will be initialized -// by the world. +// Base joint class. For simplicity, a joint is unique per body pair. +// There are many joint types, some of them provide motors and limits. class b3Joint { -public : - // Get the joint type. +public: + // Get this joint type. b3JointType GetType() const; - // Get the first body connected to the joint. + // Get the body A connected to this joint. const b3Body* GetBodyA() const; b3Body* GetBodyA(); - // Set the body to be connected to the joint as the first body. - virtual void SetBodyA(b3Body* bodyA); - - // Get the second body connected to the joint. + // Get the body B connected to this joint. const b3Body* GetBodyB() const; b3Body* GetBodyB(); - // Set the body to be connected to the joint as the second body. - virtual void SetBodyB(b3Body* bodyB); - - // Get the user specific data associated with the joint. + // Get the user data associated with this joint. void* GetUserData(); const void* GetUserData() const; // Set the user data to be associated with the joint. void SetUserData(void* data); - // Tell the world if the bodies linked by this joint - // should collide with each other. - void SetCollideLinked(bool flag); - - // Check if the bodies linked by this joint - // should collide with each other. + // Should the bodies linked by this joint collide with each other? bool CollideLinked() const; - + + // Set if the bodies linked by this joint should collide with each other. + void SetCollideLinked(bool bit); + // Dump this joint to the log file. virtual void Dump() const { - b3Log("Dump not implemented for this joint type.\n"); + b3Log("Dump feature not implemented for this joint type.\n"); } // Get the next joint in the world joint list. - b3Joint* GetNext(); const b3Joint* GetNext() const; - - // Create joint. - static b3Joint* Create(const b3JointDef* def); - - // Destroy joint. - static void Destroy(b3Joint* j); -protected : + b3Joint* GetNext(); +protected: friend class b3Body; friend class b3World; friend class b3Island; friend class b3JointManager; friend class b3JointSolver; - friend class b3List2; + + static b3Joint* Create(const b3JointDef* def); + static void Destroy(b3Joint* j); b3Joint() { } virtual ~b3Joint() { } @@ -181,9 +169,9 @@ inline b3Body* b3Joint::GetBodyA() return m_pair.bodyA; } -inline void b3Joint::SetBodyA(b3Body* bodyA) +inline const b3Body* b3Joint::GetBodyB() const { - m_pair.bodyA = bodyA; + return m_pair.bodyB; } inline b3Body* b3Joint::GetBodyB() @@ -191,21 +179,6 @@ inline b3Body* b3Joint::GetBodyB() return m_pair.bodyB; } -inline const b3Body* b3Joint::GetBodyB() const -{ - return m_pair.bodyB; -} - -inline void b3Joint::SetBodyB(b3Body* bodyB) -{ - m_pair.bodyB = bodyB; -} - -inline void b3Joint::SetUserData(void* data) -{ - m_userData = data; -} - inline void* b3Joint::GetUserData() { return m_userData; @@ -216,6 +189,11 @@ inline const void* b3Joint::GetUserData() const return m_userData; } +inline void b3Joint::SetUserData(void* data) +{ + m_userData = data; +} + inline void b3Joint::SetCollideLinked(bool bit) { m_collideLinked = bit; diff --git a/include/bounce/dynamics/joints/joint_solver.h b/include/bounce/dynamics/joints/joint_solver.h index e2c1a07..cdbd05b 100644 --- a/include/bounce/dynamics/joints/joint_solver.h +++ b/include/bounce/dynamics/joints/joint_solver.h @@ -19,7 +19,7 @@ #ifndef B3_JOINT_SOLVER_H #define B3_JOINT_SOLVER_H -#include +#include class b3Joint; @@ -32,18 +32,6 @@ struct b3Jacobian b3Vec3 angularB; }; -// 1x3 times 3x3. -inline b3Vec3 b3Mul(const b3Vec3& v, const b3Mat33& A) -{ - return b3Transpose(A) * v; -} - -// 1x3 times 3x1. -inline float32 b3Mul(const b3Vec3& v, const b3Vec3& w) -{ - return b3Dot(v, w); -} - struct b3JointSolverDef { float32 dt; diff --git a/include/bounce/dynamics/joints/mouse_joint.h b/include/bounce/dynamics/joints/mouse_joint.h index e47ff6d..14613e2 100644 --- a/include/bounce/dynamics/joints/mouse_joint.h +++ b/include/bounce/dynamics/joints/mouse_joint.h @@ -19,43 +19,46 @@ #ifndef B3_MOUSE_JOINT_H #define B3_MOUSE_JOINT_H -#include +#include +// Mouse joint definition defines a world target +// point and tunable parameters. struct b3MouseJointDef : public b3JointDef { b3MouseJointDef() { type = e_mouseJoint; - worldAnchorA.SetZero(); - localAnchorB.SetZero(); + target.SetZero(); maxForce = 0.0f; } - b3Vec3 worldAnchorA; - b3Vec3 localAnchorB; + // The initial world target point. Initially is assumed + // to be coincident to the body anchor (satisfied constraint). + b3Vec3 target; + + // Maximum joint reaction force in newtons. float32 maxForce; }; +// A mouse joint is used to make a local point on a body +// follow a defined world point. class b3MouseJoint : public b3Joint { -public : - // Get the world space anchor point on the first body (usually the mouse world space position). - b3Vec3 GetWorldAnchorA() const; +public: + // Get the world anchor point on body A. + b3Vec3 GetAnchorA() const; - // Set the world space anchor position on the first body. - void SetWorldAnchorA(const b3Vec3& v); + // Get the world target point on body B. + b3Vec3 GetAnchorB() const; - // Get the world space anchor point on the first body (usually the mouse world space position). - b3Vec3 GetWorldAnchorB() const; + // Get the world target point. + const b3Vec3& GetTarget() const; + + // Set the world target point. + void SetTarget(const b3Vec3& target); - // Get the local space anchor point on the second body (usually the ray cast intersection). - const b3Vec3& GetLocalAnchorB() const; - - // Set the mouse position on the space of the second body (usually the ray cast intersection). - void SetLocalAnchorB(const b3Vec3& v); - - // Implement b3Joint. - void Draw(b3Draw* b3Draw) const; + // Draw this joint. + void Draw(b3Draw* draw) const; private: friend class b3Joint; friend class b3JointManager; @@ -68,14 +71,12 @@ private: virtual void SolveVelocityConstraints(const b3SolverData* data); virtual bool SolvePositionConstraints(const b3SolverData* data); - // The two anchor points on each body. - // The first body has infinite mass. Therefore, - // we store the world space anchor point. - b3Vec3 m_worldAnchorA; + // Solver shared + b3Vec3 m_worldTargetA; b3Vec3 m_localAnchorB; - float32 m_maxForce; // maximum reaction force in Newtons + float32 m_maxForce; - // Constraint data for the solver. + // Solver temp u32 m_indexB; float32 m_mB; b3Mat33 m_iB; @@ -85,24 +86,4 @@ private: b3Vec3 m_C; }; -inline b3Vec3 b3MouseJoint::GetWorldAnchorA() const -{ - return m_worldAnchorA; -} - -inline void b3MouseJoint::SetWorldAnchorA(const b3Vec3& v) -{ - m_worldAnchorA = v; -} - -inline const b3Vec3& b3MouseJoint::GetLocalAnchorB() const -{ - return m_localAnchorB; -} - -inline void b3MouseJoint::SetLocalAnchorB(const b3Vec3& v) -{ - m_localAnchorB = v; -} - -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joints/revolute_joint.h b/include/bounce/dynamics/joints/revolute_joint.h index f5de3f5..14e4f8b 100644 --- a/include/bounce/dynamics/joints/revolute_joint.h +++ b/include/bounce/dynamics/joints/revolute_joint.h @@ -19,8 +19,8 @@ #ifndef B3_REVOLUTE_JOINT_H #define B3_REVOLUTE_JOINT_H -#include -#include +#include +#include struct b3RevoluteJointDef : public b3JointDef { @@ -37,13 +37,13 @@ struct b3RevoluteJointDef : public b3JointDef maxMotorTorque = 0.0f; } - // Initialize this definition given an axis, anchor point, and the lower and upper angle limits in radians. + // Initialize this definition from hinge axis, anchor point, and the lower and upper angle limits in radians. void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& axis, const b3Vec3& anchor, float32 lowerAngle, float32 upperAngle); - // The joint frame relative to the frame of body A. + // The joint frame relative body A's frame. b3Transform localFrameA; - // The joint frame relative to the frame of body B. + // The joint frame relative body B's frame. b3Transform localFrameB; // Enable the joint limit. @@ -65,27 +65,27 @@ struct b3RevoluteJointDef : public b3JointDef float32 maxMotorTorque; }; -// A revolute joint constrains two bodies to share a common point while they -// are free to rotate about the point and a given axis. -// The relative rotation about the shared axis -// is the joint angle. You can limit the relative rotation with -// a lower and upper angle limit. Also, you can use a motor -// to drive the relative rotation about the shared axis. +// A revolute joint constrains two bodies to share a point and an axis while +// they are free to rotate about the point and the axis. +// The relative rotation about the shared axis is the joint angle. +// You can limit the relative rotation with a lower and upper angle limit. +// You can use a motor to drive the relative rotation about the shared axis. // A maximum motor torque is provided so that infinite forces are not generated. +// This joint can be used to create structures such as doors. class b3RevoluteJoint : public b3Joint { public: - // Get the joint frame relative to the frame of body A. - const b3Transform& GetFrameA() const; + // Get the joint frame on body A in world coordinates. + b3Transform GetFrameA() const; - // Set the joint frame relative to the frame of body A. - void SetFrameA(const b3Transform& xf); + // Get the joint frame on body B in world coordinates. + b3Transform GetFrameB() const; - // Get the joint frame relative to the frame of body B. - const b3Transform& GetFrameB() const; - - // Set the joint frame relative to the frame of body B. - void SetFrameB(const b3Transform& xf); + // Get the joint frame relative body A's frame. + const b3Transform& GetLocalFrameA() const; + + // Get the joint frame relative body B's frame. + const b3Transform& GetLocalFrameB() const; // Is the joint limit enabled? bool IsLimitEnabled() const; @@ -96,7 +96,7 @@ public: // Get the lower angle limit. float32 GetLowerLimit() const; - // Get the upper limit. + // Get the upper angle limit. float32 GetUpperLimit() const; // Set the angle limits. @@ -108,20 +108,20 @@ public: // Set the joint motor enabled. void SetEnableMotor(bool bit); - // Get the desired motor speed (radians per second). + // Get the desired motor speed in radians per second. float32 GetMotorSpeed() const; - // Set the desired motor speed (radians per second). + // Set the desired motor speed in radians per second. void SetMotorSpeed(float32 speed); - // Get the maximum motor torque (Newton per meter). + // Get the maximum motor torque in Newton per meter. float32 GetMaxMotorTorque() const; - // Set the maximum motor torque (Newton per meter). + // Set the maximum motor torque in Newton per meter. void SetMaxMotorTorque(float32 torque); // Draw this joint. - void Draw(b3Draw* b3Draw) const; + void Draw(b3Draw* draw) const; private: friend class b3Joint; friend class b3JointManager; @@ -171,8 +171,8 @@ private: b3Vec3 m_rB; b3Vec3 m_nA; b3Vec3 m_nB; - b3Mat<5, 5> m_mass; - b3Vec<5> m_impulse; + b3Mat<5, 5> m_mass; // block solver + b3Vec<5> m_impulse; // block solver }; -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joints/sphere_joint.h b/include/bounce/dynamics/joints/sphere_joint.h index 5bbfde0..aa9fac7 100644 --- a/include/bounce/dynamics/joints/sphere_joint.h +++ b/include/bounce/dynamics/joints/sphere_joint.h @@ -19,7 +19,7 @@ #ifndef B3_SPHERE_JOINT_H #define B3_SPHERE_JOINT_H -#include +#include struct b3SphereJointDef : public b3JointDef { @@ -30,31 +30,29 @@ struct b3SphereJointDef : public b3JointDef localAnchorB.SetZero(); } - // Initialize this definition. + // Initialize this definition from bodies and world anchor point. void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& anchor); + // The anchor point relative to body A's origin b3Vec3 localAnchorA; + + // The anchor point relative to body B's origin b3Vec3 localAnchorB; }; -// A ball-in-socket joint. +// A sphere joint constrains the bodies to rotate relative to each +// other about a specified anchor point. class b3SphereJoint : public b3Joint { public: - // Get the local anchor point on body A. - const b3Vec3& GetLocalAnchorA() const; + // Get the anchor point on body A in world coordinates. + b3Vec3 GetAnchorA() const; - // Set the local anchor point on body A. - void SetLocalAnchorA(const b3Vec3& point); - - // Get the local anchor point on body B. - const b3Vec3& GetLocalAnchorB() const; + // Get the anchor point on body B in world coordinates. + b3Vec3 GetAnchorB() const; - // Set the local anchor point on body B. - void SetLocalAnchorB(const b3Vec3& point); - - // Implement b3Joint - void Draw(b3Draw* b3Draw) const; + // Draw this joint. + void Draw(b3Draw* draw) const; private: friend class b3Joint; friend class b3JointManager; @@ -67,12 +65,11 @@ private: virtual void SolveVelocityConstraints(const b3SolverData* data); virtual bool SolvePositionConstraints(const b3SolverData* data); - // The local joint frames on each body. + // Solver shared b3Vec3 m_localAnchorA; b3Vec3 m_localAnchorB; - // Temporary data copied from the joint solver - // to reduce cache misses. + // Solver temp u32 m_indexA; u32 m_indexB; float32 m_mA; @@ -80,7 +77,6 @@ private: b3Mat33 m_iA; b3Mat33 m_iB; - // Constraint data. b3Vec3 m_localCenterA; b3Vec3 m_localCenterB; b3Vec3 m_rA; @@ -89,24 +85,4 @@ private: b3Vec3 m_impulse; }; -inline const b3Vec3& b3SphereJoint::GetLocalAnchorA() const -{ - return m_localAnchorA; -} - -inline void b3SphereJoint::SetLocalAnchorA(const b3Vec3& point) -{ - m_localAnchorA = point; -} - -inline const b3Vec3& b3SphereJoint::GetLocalAnchorB() const -{ - return m_localAnchorB; -} - -inline void b3SphereJoint::SetLocalAnchorB(const b3Vec3& point) -{ - m_localAnchorB = point; -} - -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/joints/spring_joint.h b/include/bounce/dynamics/joints/spring_joint.h index e98ee72..f051610 100644 --- a/include/bounce/dynamics/joints/spring_joint.h +++ b/include/bounce/dynamics/joints/spring_joint.h @@ -19,7 +19,7 @@ #ifndef B3_SPRING_JOINT_H #define B3_SPRING_JOINT_H -#include +#include struct b3SpringJointDef : public b3JointDef { @@ -36,35 +36,65 @@ struct b3SpringJointDef : public b3JointDef // Initialize this definition from bodies and world anchors. void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& anchorA, const b3Vec3& anchorB); - // The joint anchor point relative to the frame of body A + // The anchor point relative to body A's origin b3Vec3 localAnchorA; - // The joint anchor point relative to the frame of body B + // The anchor point relative to body B's origin b3Vec3 localAnchorB; - // The spring rest length + // The spring rest length. float32 length; - // The mass-spring-damper frequency in units of hertz - // 0 = disable spring softness + // The mass-spring-damper frequency in Hz + // 0 = disable softness float32 frequencyHz; - // The damping ration in the interval [0, 1]. + // The damping ration in the interval [0, 1] // 0 = undamped spring // 1 = critical damping float32 dampingRatio; }; +// A spring joint constrains the bodies to rotate relative to each +// other about a specified spring position. +// The tunable soft parameters control how much/fast the bodies should translate +// relative to each other about the spring position. +// This joint can be used to create behaviours such as a car suspension. class b3SpringJoint : public b3Joint { -public : - // Get the local anchor point in the local space of the first body. +public: + // Get the anchor point on body A in world coordinates. + b3Vec3 GetAnchorA() const; + + // Get the anchor point on body B in world coordinates. + b3Vec3 GetAnchorB() const; + + // Get the anchor point relative to body A's origin. const b3Vec3& GetLocalAnchorA() const; - // Get the local anchor point in the local space of the second body. + // Get the anchor point relative to body B's origin. const b3Vec3& GetLocalAnchorB() const; - void Draw(b3Draw* b3Draw) const; + // Get the natural spring length. + float32 GetLength() const; + + // Set the natural spring length. + void SetLength(float32 length); + + // Get the damper frequency in Hz. + float32 GetFrequency() const; + + // Set the damper frequency in Hz. + void SetFrequency(float32 frequency); + + // Get the damping ratio. + float32 GetDampingRatio() const; + + // Set the damping ratio. + void SetDampingRatio(float32 ratio); + + // Draw this joint. + void Draw(b3Draw* draw) const; private: friend class b3Joint; friend class b3JointManager; @@ -103,14 +133,4 @@ private: float32 m_impulse; }; -inline const b3Vec3& b3SpringJoint::GetLocalAnchorA() const -{ - return m_localAnchorA; -} - -inline const b3Vec3& b3SpringJoint::GetLocalAnchorB() const -{ - return m_localAnchorB; -} - -#endif +#endif \ No newline at end of file diff --git a/include/bounce/dynamics/shapes/capsule_shape.h b/include/bounce/dynamics/shapes/capsule_shape.h index 026d0ef..398b679 100644 --- a/include/bounce/dynamics/shapes/capsule_shape.h +++ b/include/bounce/dynamics/shapes/capsule_shape.h @@ -19,7 +19,7 @@ #ifndef B3_CAPSULE_SHAPE_H #define B3_CAPSULE_SHAPE_H -#include +#include // A capsule defined along the up-axis. class b3CapsuleShape : public b3Shape diff --git a/include/bounce/dynamics/shapes/hull_shape.h b/include/bounce/dynamics/shapes/hull_shape.h index d2e1eb6..4324cd0 100644 --- a/include/bounce/dynamics/shapes/hull_shape.h +++ b/include/bounce/dynamics/shapes/hull_shape.h @@ -19,7 +19,7 @@ #ifndef B3_HULL_SHAPE_H #define B3_HULL_SHAPE_H -#include +#include struct b3Hull; diff --git a/include/bounce/dynamics/shapes/mesh_shape.h b/include/bounce/dynamics/shapes/mesh_shape.h index 9629e02..16b0a3a 100644 --- a/include/bounce/dynamics/shapes/mesh_shape.h +++ b/include/bounce/dynamics/shapes/mesh_shape.h @@ -19,7 +19,7 @@ #ifndef B3_MESH_SHAPE_H #define B3_MESH_SHAPE_H -#include +#include struct b3Mesh; diff --git a/include/bounce/dynamics/shapes/shape.h b/include/bounce/dynamics/shapes/shape.h index 2f72758..6569040 100644 --- a/include/bounce/dynamics/shapes/shape.h +++ b/include/bounce/dynamics/shapes/shape.h @@ -19,9 +19,9 @@ #ifndef B3_SHAPE_H #define B3_SHAPE_H -#include -#include -#include +#include +#include +#include struct b3ContactEdge; @@ -41,8 +41,8 @@ struct b3ShapeDef { b3ShapeDef() { - shape = nullptr; - userData = nullptr; + shape = NULL; + userData = NULL; isSensor = false; density = 0.0f; friction = 0.3f; @@ -59,15 +59,19 @@ struct b3ShapeDef struct b3MassData { + // The mass of the shape in kilograms. float32 mass; + + // The shape center of mass relative to the shape's origin. b3Vec3 center; + + // The rotational inertia of the shape about the shape's center of mass. b3Mat33 I; }; class b3Shape { public: - // A shape is created and initialized by an user and a body. b3Shape() { } virtual ~b3Shape() { } @@ -78,11 +82,7 @@ public: const b3Body* GetBody() const; b3Body* GetBody(); - // Get the frame of the shape relative to the world. - b3Transform GetTransform() const; - - // Calculate the mass data for this shape given the shape density, that is, - // the mass per unit volume. + // Calculate the mass data for this shape given the shape density. virtual void ComputeMass(b3MassData* data, float32 density) const = 0; // Compute the shape world AABB. @@ -91,26 +91,40 @@ public: // Test if a point is contained inside this shape. virtual bool TestPoint(const b3Vec3& point, const b3Transform& xf) const = 0; - // Compute the ray intersection point, normal, and fraction. + // Compute the ray intersection point, normal of surface, and fraction. virtual bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const = 0; - bool IsSensor() const; - void SetSensor(bool flag); + // Set if this shape is a sensor. + void SetSensor(bool bit); + // Is this shape a sensor? + bool IsSensor() const; + + // Get the shape density. float32 GetDensity() const; + + // Set the shape density. void SetDensity(float32 density); + // Get the shape coefficient of restitution. float32 GetRestitution() const; + + // Set the shape coefficient of restitution. + // This is a value in the range [0, 1]. void SetRestitution(float32 restitution); + // Get the shape coefficient of friction. float32 GetFriction() const; + + // Set the shape coefficient of friction. + // This is a value in the range [0, 1]. void SetFriction(float32 friction); + // Get the user data associated with this shape. void* GetUserData() const; - void SetUserData(void* data); - // Destroy the contacts associated with this shape. - void DestroyContacts(); + // Set the user data associated with this shape. + void SetUserData(void* data); // Dump this shape to the log file. void Dump(i32 bodyIndex) const; @@ -119,23 +133,31 @@ public: const b3Shape* GetNext() const; b3Shape* GetNext(); - // Create a shape. + float32 m_radius; +protected: + friend class b3World; + friend class b3Body; + friend class b3Contact; + friend class b3ContactManager; + friend class b3ContactSolver; + friend class b3List1; + static b3Shape* Create(const b3ShapeDef& def); - - // Destroy a shape. static void Destroy(b3Shape* shape); + // Convenience function. + // Destroy the contacts associated with this shape. + void DestroyContacts(); + b3ShapeType m_type; bool m_isSensor; void* m_userData; - i32 m_broadPhaseID; - - float32 m_radius; float32 m_density; float32 m_restitution; float32 m_friction; - - // Contact edges for this shape. + i32 m_broadPhaseID; + + // Contact edges for this shape contact graph. b3List2 m_contactEdges; // The parent body of this shape. diff --git a/include/bounce/dynamics/shapes/sphere_shape.h b/include/bounce/dynamics/shapes/sphere_shape.h index 63bd03f..6960601 100644 --- a/include/bounce/dynamics/shapes/sphere_shape.h +++ b/include/bounce/dynamics/shapes/sphere_shape.h @@ -19,7 +19,7 @@ #ifndef B3_SPHERE_SHAPE_H #define B3_SPHERE_SHAPE_H -#include +#include class b3SphereShape : public b3Shape { diff --git a/include/bounce/dynamics/time_step.h b/include/bounce/dynamics/time_step.h index 6f6c63e..937544f 100644 --- a/include/bounce/dynamics/time_step.h +++ b/include/bounce/dynamics/time_step.h @@ -19,9 +19,9 @@ #ifndef B3_TIME_STEP_H #define B3_TIME_STEP_H -#include -#include -#include +#include +#include +#include struct b3Position { diff --git a/include/bounce/dynamics/world.h b/include/bounce/dynamics/world.h index a06a01e..85569cb 100644 --- a/include/bounce/dynamics/world.h +++ b/include/bounce/dynamics/world.h @@ -19,12 +19,12 @@ #ifndef B3_WORLD_H #define B3_WORLD_H -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include struct b3BodyDef; class b3Body; @@ -34,18 +34,19 @@ class b3ContactListener; class b3ContactFilter; class b3Draw; -// Use a physics world to create/destroy rigid bodies, execute ray cast and AABB queries. +// Use a physics world to create/destroy rigid bodies, execute ray cast and volume queries. class b3World { public: b3World(); ~b3World(); - // Set the debug b3Draw interface. + // Set the debug draw interface. // The user must implement this interface to tell the world to - // b3Draw the physics entities. - void SetDebugDraw(b3Draw* b3Draw); + // draw the physics entities. + void SetDebugDraw(b3Draw* draw); + // Get the debug draw interface. b3Draw* GetDebugDraw(); // The filter passed can tell the world to disallow the contact creation between @@ -77,9 +78,9 @@ public: // Remove a joint from the world and deallocate it from the memory. void DestroyJoint(b3Joint* joint); - // Call the function below to simulate a physics step. + // Simulate a physics step. // The function parameters are the ammount of time to simulate, - // and the number of contact solver iterations. + // and the number of constraint solver iterations. void Step(float32 dt, u32 velocityIterations, u32 positionIterations); // Perform a ray cast with the world. @@ -87,13 +88,13 @@ public: // in the world. The ray cast output is the intercepted shape, the intersection // point in world space, the face normal on the shape associated with the point, // and the intersection fraction. - void CastRay(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const; + void RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const; // Perform a AABB cast with the world. // The query listener will be notified when two shape AABBs are overlapping. // If the listener returns false then the query is stopped immediately. // Otherwise, it continues searching for new overlapping shape AABBs. - void CastAABB(b3QueryListener* listener, const b3AABB3& aabb) const; + void QueryAABB(b3QueryListener* listener, const b3AABB3& aabb) const; // Get the list of bodies in this world. const b3List2& GetBodyList() const; @@ -110,7 +111,7 @@ public: // Get the time spent to finish executing each simulation module of the last physics step. const b3Profile& GetProfile() const; - // Tell the world to b3Draw the entities that belong to this world. + // Tell the world to draw the entities that belong to this world. void DebugDraw() const; void DrawShape(const b3Transform& xf, const b3Shape* shape) const; void DrawJoint(const b3Joint* joint) const; diff --git a/include/bounce/dynamics/world_listeners.h b/include/bounce/dynamics/world_listeners.h index c572fac..4b87efa 100644 --- a/include/bounce/dynamics/world_listeners.h +++ b/include/bounce/dynamics/world_listeners.h @@ -19,7 +19,7 @@ #ifndef B3_WORLD_LISTENERS_H #define B3_WORLD_LISTENERS_H -#include +#include class b3Shape; class b3Contact; diff --git a/include/bounce/quickhull/qh_hull.h b/include/bounce/quickhull/qh_hull.h index ed6403b..c72ab7b 100644 --- a/include/bounce/quickhull/qh_hull.h +++ b/include/bounce/quickhull/qh_hull.h @@ -19,8 +19,8 @@ #ifndef QH_HULL_H #define QH_HULL_H -#include -#include +#include +#include template struct qhList diff --git a/include/bounce/quickhull/qh_hull.inl b/include/bounce/quickhull/qh_hull.inl index fe6cb5c..a06b581 100644 --- a/include/bounce/quickhull/qh_hull.inl +++ b/include/bounce/quickhull/qh_hull.inl @@ -3,7 +3,7 @@ template inline void qhList::PushFront(T* link) { - link->prev = nullptr; + link->prev = NULL; link->next = head; if (head) { @@ -31,8 +31,8 @@ inline T* qhList::Remove(T* link) head = link->next; } - link->prev = nullptr; - link->next = nullptr; + link->prev = NULL; + link->next = NULL; --count; return next; @@ -78,7 +78,7 @@ inline qhHalfEdge* qhFace::FindTwin(const qhVertex* tail, const qhVertex* head) e = e->next; } while (e != edge); - return nullptr; + return NULL; } inline b3Vec3 b3Newell(const b3Vec3& a, const b3Vec3& b) @@ -128,7 +128,7 @@ inline qhHalfEdge* qhHull::FindTwin(const qhVertex* tail, const qhVertex* head) } face = face->next; } - return nullptr; + return NULL; } inline u32 qhGetMemorySize(u32 V) diff --git a/include/testbed/framework/debug_draw.h b/include/testbed/framework/debug_draw.h index e2f1cc3..bf579b2 100644 --- a/include/testbed/framework/debug_draw.h +++ b/include/testbed/framework/debug_draw.h @@ -19,7 +19,7 @@ #ifndef DEBUG_DRAW_H #define DEBUG_DRAW_H -#include +#include #include "mat44.h" struct DrawPoints; diff --git a/include/testbed/framework/mat44.h b/include/testbed/framework/mat44.h index 1ea3198..01977e2 100644 --- a/include/testbed/framework/mat44.h +++ b/include/testbed/framework/mat44.h @@ -19,7 +19,7 @@ #ifndef MAT44_H #define MAT44_H -#include +#include struct Vec4 { diff --git a/include/testbed/tests/box_stack.h b/include/testbed/tests/box_stack.h index 07ddbcb..3d04383 100644 --- a/include/testbed/tests/box_stack.h +++ b/include/testbed/tests/box_stack.h @@ -45,7 +45,7 @@ public: b3ShapeDef sdef; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; sdef.friction = 1.0f; b3Shape* shape = body->CreateShape(sdef); @@ -80,7 +80,7 @@ public: sdef.density = 0.5f; sdef.friction = 0.3f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } diff --git a/include/testbed/tests/cluster_test.h b/include/testbed/tests/cluster_test.h index bb594e1..8020eb1 100644 --- a/include/testbed/tests/cluster_test.h +++ b/include/testbed/tests/cluster_test.h @@ -19,7 +19,7 @@ #ifndef CLUSTER_H #define CLUSTER_H -#include +#include extern DebugDraw* g_debugDraw; extern Camera g_camera; diff --git a/include/testbed/tests/quadrics.h b/include/testbed/tests/quadrics.h index 36664f9..1f98d0d 100644 --- a/include/testbed/tests/quadrics.h +++ b/include/testbed/tests/quadrics.h @@ -19,7 +19,7 @@ #ifndef QUADRIC_H #define QUADRIC_H -#include +#include extern DebugDraw* g_debugDraw; extern Camera g_camera; @@ -113,6 +113,19 @@ public: ~Quadric() { + { + b3Free(m_coneHull.vertices); + b3Free(m_coneHull.edges); + b3Free(m_coneHull.faces); + b3Free(m_coneHull.planes); + } + + { + b3Free(m_cylinderHull.vertices); + b3Free(m_cylinderHull.edges); + b3Free(m_cylinderHull.faces); + b3Free(m_cylinderHull.planes); + } } static Test* Create() diff --git a/include/testbed/tests/quickhull_test.h b/include/testbed/tests/quickhull_test.h index 1a2e761..8c94e2b 100644 --- a/include/testbed/tests/quickhull_test.h +++ b/include/testbed/tests/quickhull_test.h @@ -19,7 +19,7 @@ #ifndef QHULL_H #define QHULL_H -#include +#include extern DebugDraw* g_debugDraw; extern Camera g_camera; @@ -48,7 +48,7 @@ struct Map return pair; } } - return nullptr; + return NULL; } b3StackArray m_pairs; diff --git a/include/testbed/tests/ray_cast.h b/include/testbed/tests/ray_cast.h index e0bf874..14271ab 100644 --- a/include/testbed/tests/ray_cast.h +++ b/include/testbed/tests/ray_cast.h @@ -89,7 +89,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -109,7 +109,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -129,7 +129,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -149,7 +149,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -169,7 +169,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -190,7 +190,7 @@ public: sdef.density = 0.0f; sdef.friction = 0.0f; sdef.shape = &hs; - sdef.userData = nullptr; + sdef.userData = NULL; b3Shape* shape = body->CreateShape(sdef); } @@ -206,35 +206,16 @@ public: { // Perform the ray cast RayCastListener listener; - m_world.CastRay(&listener, p1, p2); - - int hitId = listener.FindClosestHit(); + m_world.RayCast(&listener, p1, p2); + i32 hitId = listener.FindClosestHit(); if (hitId >= 0) { - // Hit // Replace current hit - RayCastHit rayHit = listener.m_hits[hitId]; - - b3Shape* shape = rayHit.m_shape; - - b3Body* bodyA = m_groundBody; - b3Body* bodyB = shape->GetBody(); - - // Ray hit point in world space - b3Vec3 worldPointA = rayHit.m_point; - - // xf from world space to the local space of the shape - b3Transform xf = shape->GetTransform(); - - // lp = xf^-1 * wp - b3Vec3 localPointA = b3MulT(xf, worldPointA); - - extern DebugDraw* g_debugDraw; - - g_debugDraw->DrawSegment(p1, worldPointA, b3Color(0.0f, 1.0f, 0.0f)); - g_debugDraw->DrawPoint(worldPointA, b3Color(1.0f, 0.0f, 0.0f)); - g_debugDraw->DrawSegment(worldPointA, worldPointA + rayHit.m_normal, b3Color(1.0f, 1.0f, 1.0f)); + RayCastHit hit = listener.m_hits[hitId]; + g_debugDraw->DrawSegment(p1, hit.m_point, b3Color(0.0f, 1.0f, 0.0f)); + g_debugDraw->DrawPoint(hit.m_point, b3Color(1.0f, 0.0f, 0.0f)); + g_debugDraw->DrawSegment(hit.m_point, hit.m_point + hit.m_normal, b3Color(1.0f, 1.0f, 1.0f)); } else { diff --git a/include/testbed/tests/test.h b/include/testbed/tests/test.h index ca15ee4..5d287ac 100644 --- a/include/testbed/tests/test.h +++ b/include/testbed/tests/test.h @@ -19,10 +19,10 @@ #ifndef TEST_H #define TEST_H -#include -#include -#include "..\framework\debug_draw.h" -#include +#include +#include +#include "../framework/debug_draw.h" +#include struct Settings { @@ -199,7 +199,6 @@ public: b3Profile m_maxProfile; RayCastHit m_rayHit; - b3Body* m_groundBody; b3BoxHull m_groundHull; b3BoxHull m_boxHull; b3BoxHull m_tallHull; diff --git a/premake5 b/premake5 new file mode 100644 index 0000000..d57048a Binary files /dev/null and b/premake5 differ diff --git a/premake5.lua b/premake5.lua index 121c29a..b54478f 100644 --- a/premake5.lua +++ b/premake5.lua @@ -2,7 +2,7 @@ -- Bounce premake script -- http://industriousone.com/premake --- paths as variables in the case files are moved +-- variable paths for the case files are moved solution_name = "bounce" working_dir = "." solution_dir = "build/" @@ -12,7 +12,8 @@ src_dir = "src/" obj_dir = "/obj/" bin_dir = "/bin/" -action = _ACTION +-- or "" to make --help work +action = _ACTION or "" -- premake main solution (solution_name) @@ -20,14 +21,6 @@ solution (solution_name) configurations { "debug", "release" } platforms { "x32", "x64" } - filter { "platforms:x32" } - system "windows" - architecture "x32" - - filter { "platforms:x64" } - system "windows" - architecture "x64" - -- note the use of "!" before objdir to force the specified path configuration "debug" targetdir ( solution_dir .. action .. bin_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) @@ -37,125 +30,187 @@ solution (solution_name) rtti "Off" flags { "FloatFast" } - configuration "release" + configuration "release" targetdir ( solution_dir .. action .. bin_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) objdir ( "!" .. solution_dir .. action .. obj_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) defines { "NDEBUG" } optimize "On" rtti "Off" flags { "FloatFast" } - - configuration "windows" - defines { "WIN32", "_WINDOWS" } - + + configuration { "vs*" } + defines { "_CRT_SECURE_NO_WARNINGS" } + + configuration { "windows" } + defines { "_WIN32", "WIN32", "_WINDOWS" } + project "bounce" kind "StaticLib" language "C++" location ( solution_dir .. action ) + includedirs { inc_dir } + vpaths { [""] = "bounce" } + buildoptions { "-std=c++11" } -- require C++11 + files { inc_dir .. "/bounce/**.h", inc_dir .. "/bounce/**.inl", src_dir .. "/bounce/**.cpp" } - includedirs { inc_dir } - vpaths { [""] = "bounce" } - project "glad" kind "StaticLib" language "C" location ( solution_dir .. action ) + includedirs { external_dir } + vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } + files { - external_dir .. "/glad/**.h", - external_dir .. "/glad/**.c" + external_dir .. "/glad/khrplatform.h", + external_dir .. "/glad/glad.h", + external_dir .. "/glad/glad.c" } - includedirs { external_dir } - defines { "_CRT_SECURE_NO_WARNINGS" } - vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } + + configuration { "not windows", "not macosx" } + files + { + external_dir .. "/glad/glad_glx.h", + external_dir .. "/glad/glad_glx.c" + } project "glfw" kind "StaticLib" language "C" location ( solution_dir .. action ) + includedirs { external_dir .. "/glfw" } + defines { "_GLFW_USE_CONFIG_H" } -- see glfw_config.h + vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } + + -- files - -- windows headers and sources + -- common + files + { + external_dir .. "/glfw/glfw_config.h", + external_dir .. "/glfw/glfw3.h", + external_dir .. "/glfw/glfw3native.h", + + external_dir .. "/glfw/context.c", + external_dir .. "/glfw/init.c", + external_dir .. "/glfw/input.c", + external_dir .. "/glfw/monitor.c", + external_dir .. "/glfw/vulkan.c", + external_dir .. "/glfw/window.c", + } + + -- windows configuration { "windows" } files { - external_dir .. "/glfw/egl_context.h", - external_dir .. "/glfw/glfw3.h", - external_dir .. "/glfw/glfw3native.h", - external_dir .. "/glfw/glfw_config.h", - external_dir .. "/glfw/wgl_context.h", - external_dir .. "/glfw/win32_joystick.h", external_dir .. "/glfw/win32_platform.h", - - external_dir .. "/glfw/context.c", - external_dir .. "/glfw/egl_context.c", - external_dir .. "/glfw/init.c", - external_dir .. "/glfw/input.c", - external_dir .. "/glfw/monitor.c", - external_dir .. "/glfw/vulkan.c", - external_dir .. "/glfw/wgl_context.c", + external_dir .. "/glfw/win32_joystick.h", + external_dir .. "/glfw/wgl_context.h", + external_dir .. "/glfw/egl_context.h", + external_dir .. "/glfw/win32_init.c", external_dir .. "/glfw/win32_joystick.c", external_dir .. "/glfw/win32_monitor.c", external_dir .. "/glfw/win32_time.c", external_dir .. "/glfw/win32_tls.c", external_dir .. "/glfw/win32_window.c", - external_dir .. "/glfw/window.c" + external_dir .. "/glfw/wgl_context.c", + external_dir .. "/glfw/egl_context.c", } - includedirs { external_dir .. "/glfw" } - defines { "_GLFW_USE_CONFIG_H", "_CRT_SECURE_NO_WARNINGS" } - vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } + + -- linux + configuration { "not windows", "not macosx" } + buildoptions { "-pthread" } + files + { + external_dir .. "/glfw/x11_platform.h", + external_dir .. "/glfw/xkb_unicode.h", + external_dir .. "/glfw/linux_joystick.h", + external_dir .. "/glfw/posix_time.h", + external_dir .. "/glfw/posix_tls.h", + external_dir .. "/glfw/glx_context.h", + external_dir .. "/glfw/egl_context.h", + + external_dir .. "/glfw/x11_init.c", + external_dir .. "/glfw/x11_monitor.c", + external_dir .. "/glfw/x11_window.c", + external_dir .. "/glfw/xkb_unicode.c", + external_dir .. "/glfw/linux_joystick.c", + external_dir .. "/glfw/posix_time.c", + external_dir .. "/glfw/posix_tls.c", + external_dir .. "/glfw/egl_context.c", + external_dir .. "/glfw/glx_context.c", + } project "imgui" kind "StaticLib" language "C++" location ( solution_dir .. action ) + includedirs { external_dir } + vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } + buildoptions { "-std=c++11" } -- require C++11 + files { external_dir .. "/imgui/**.h", external_dir .. "/imgui/**.cpp" } - includedirs { external_dir } - defines { "_CRT_SECURE_NO_WARNINGS" } - vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } - project "testbed" kind "ConsoleApp" language "C++" location ( solution_dir .. action ) + includedirs { external_dir, inc_dir } + vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } + buildoptions { "-std=c++11" } -- require C++11 + + --common files { inc_dir .. "/testbed/**.h", src_dir .. "/testbed/**.cpp" } - includedirs { external_dir, inc_dir } - - -- dependencies - links { "bounce", "glad", "glfw", "imgui" } - - -- windows dependencies + + links { "glfw", "glad", "imgui", "bounce" } + configuration { "windows" } links { "glu32", "opengl32", "winmm" } - vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } + configuration { "not windows", "not macosx" } + links + { + "GL", "GLU", "rt", "Xrandr", "Xinerama", "Xi", "Xcursor", + "m", "dl", "Xrender", "drm", "Xdamage", "X11-xcb", "xcb-glx", + "xcb-dri2", "xcb-dri3", "xcb-present", "xcb-sync", "xshmfence", + "Xxf86vm", "Xfixes", "Xext", "X11", "pthread", "xcb", "Xau", "Xdmcp" + } + -- build if os.is "windows" then newaction - { + { trigger = "solution", - description = "Make and open solution", + description = "Build solution", execute = function () - os.execute ( "premake5 clean" ) + os.execute ( "premake5 clean" ) os.execute ( "premake5 vs2015" ) - os.execute ( "start " .. solution_dir .. "vs2015/bounce.sln" ) end } + newaction + { + trigger = "doc", + description = "Build documentation", + execute = function () + os.execute ( "doxygen doxyfile" ) + os.execute ( "start doc\\api\\html\\index.html" ) + end + } end -- clean @@ -164,6 +219,7 @@ newaction trigger = "clean", description = "Clean solution", execute = function () - os.rmdir( solution_dir ) + os.rmdir( "doc" ) + os.rmdir( solution_dir ) end -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index 741f351..6c070ee 100644 --- a/readme.md +++ b/readme.md @@ -7,14 +7,14 @@ Here is how to control the Testbed. The Testbed is a collection of tests and exa Camera (as in Maya):
    -
  • Rotate the scene holding ALT + LMB
  • -
  • Translate the scene holding ALT + RMB
  • -
  • Zoom in/out the scene using ALT + Mouse Wheel
  • +
  • Rotate the scene holding LSHIFT + LMB
  • +
  • Translate the scene holding LSHIFT + RMB
  • +
  • Zoom in/out the scene using LSHIFT + Mouse Wheel
Bounce is released under the zlib license. -[Irlan Robson](http://irlan.net) +Irlan Robson

Features

@@ -32,15 +32,14 @@ Bounce is released under the zlib license.
  • Static tree "midphase"
  • SAT
  • GJK
  • -
  • Spheres, capsules, hulls
  • +
  • Spheres, capsules, hulls, triangle meshes
  • Optimized pair management
  • Dynamics

    -
  • Spheres, capsules, hulls, triangle meshes
  • -
  • Distance, spring, sphere, cone, revolute joint types
  • -
  • Joint motors, limits
  • Contact, friction, restitution
  • +
  • Mouse, spring, sphere, cone, revolute joint types
  • +
  • Joint motors, limits
  • Constraint graphs
  • Simulation islands and sleep management
  • Linear time solver
  • @@ -60,4 +59,4 @@ Bounce is released under the zlib license.

    Documentation

  • Doxygen API documentation
  • - \ No newline at end of file + diff --git a/src/bounce/collision/broad_phase.cpp b/src/bounce/collision/broad_phase.cpp index 0ca3fbf..4d7be99 100644 --- a/src/bounce/collision/broad_phase.cpp +++ b/src/bounce/collision/broad_phase.cpp @@ -16,18 +16,18 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3BroadPhase::b3BroadPhase() { m_moveBufferCapacity = 16; m_moveBuffer = (i32*)b3Alloc(m_moveBufferCapacity * sizeof(i32)); - memset(m_moveBuffer, NULL, m_moveBufferCapacity * sizeof(i32)); + memset(m_moveBuffer, 0, m_moveBufferCapacity * sizeof(i32)); m_moveBufferCount = 0; m_pairBufferCapacity = 16; m_pairBuffer = (b3Pair*)b3Alloc(m_pairBufferCapacity * sizeof(b3Pair)); - memset(m_pairBuffer, NULL, m_pairBufferCapacity * sizeof(b3Pair)); + memset(m_pairBuffer, 0, m_pairBufferCapacity * sizeof(b3Pair)); m_pairBufferCount = 0; } diff --git a/src/bounce/collision/distance.cpp b/src/bounce/collision/distance.cpp index 3d1575f..b0c2e15 100644 --- a/src/bounce/collision/distance.cpp +++ b/src/bounce/collision/distance.cpp @@ -16,10 +16,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include +#include +#include +#include +#include b3Vec3 b3ClosestPointOnPlane(const b3Vec3& P, const b3Plane& plane) { diff --git a/src/bounce/collision/gjk/gjk.cpp b/src/bounce/collision/gjk/gjk.cpp index 29ea195..a40a7c3 100644 --- a/src/bounce/collision/gjk/gjk.cpp +++ b/src/bounce/collision/gjk/gjk.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include // Implementation of the GJK (Gilbert-Johnson-Keerthi) algorithm // using Voronoi regions and Barycentric coordinates. diff --git a/src/bounce/collision/gjk/gjk_cache.cpp b/src/bounce/collision/gjk/gjk_cache.cpp index 50f7a7f..31678a3 100644 --- a/src/bounce/collision/gjk/gjk_cache.cpp +++ b/src/bounce/collision/gjk/gjk_cache.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; u32 b3_gjkCacheHits; diff --git a/src/bounce/collision/gjk/gjk_feature_pair.cpp b/src/bounce/collision/gjk/gjk_feature_pair.cpp index c13c585..df6c605 100644 --- a/src/bounce/collision/gjk/gjk_feature_pair.cpp +++ b/src/bounce/collision/gjk/gjk_feature_pair.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3GJKFeaturePair b3GetFeaturePair(const b3SimplexCache& cache) { diff --git a/src/bounce/collision/sat/sat.cpp b/src/bounce/collision/sat/sat.cpp index 64086ef..3eb2284 100644 --- a/src/bounce/collision/sat/sat.cpp +++ b/src/bounce/collision/sat/sat.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include // Implementation of the SAT (Separating Axis Test) for // convex hulls. Thanks to Dirk Gregorius for his presentation diff --git a/src/bounce/collision/sat/sat_edge_and_hull.cpp b/src/bounce/collision/sat/sat_edge_and_hull.cpp index e33e80e..aa1fd35 100644 --- a/src/bounce/collision/sat/sat_edge_and_hull.cpp +++ b/src/bounce/collision/sat/sat_edge_and_hull.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include float32 b3ProjectEdge(const b3Capsule* hull, const b3Plane& plane) { diff --git a/src/bounce/collision/sat/sat_vertex_and_hull.cpp b/src/bounce/collision/sat/sat_vertex_and_hull.cpp index 8327f1d..e7f8da8 100644 --- a/src/bounce/collision/sat/sat_vertex_and_hull.cpp +++ b/src/bounce/collision/sat/sat_vertex_and_hull.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include float32 b3ProjectVertex(const b3Sphere* hull, const b3Plane& plane) { diff --git a/src/bounce/collision/shapes/hull.cpp b/src/bounce/collision/shapes/hull.cpp index 0fcf919..964c4f4 100644 --- a/src/bounce/collision/shapes/hull.cpp +++ b/src/bounce/collision/shapes/hull.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include void b3Hull::Validate() const { @@ -28,22 +28,36 @@ void b3Hull::Validate() const void b3Hull::Validate(const b3Face* face) const { + bool ok = false; + const b3HalfEdge* begin = GetEdge(face->edge); + const b3HalfEdge* edge = begin; + do + { + if (GetFace(edge->face) == face) + { + ok = true; + break; + } + edge = edges + edge->next; + } while (edge != begin); + + B3_ASSERT(ok); + Validate(edges + face->edge); } void b3Hull::Validate(const b3HalfEdge* e) const { - u32 edgeIndex = (u32)(e - edges); + u8 edgeIndex = (u8)(e - edges); + const b3HalfEdge* twin = edges + e->twin; - B3_ASSERT(twin->twin == edgeIndex); + // Each edge must be followed by its twin. B3_ASSERT(b3Abs(twin - e) == 1); - - //B3_ASSERT(edges[e->prev].next == edgeIndex); - B3_ASSERT(e->origin != twin->origin); + B3_ASSERT(twin->twin == edgeIndex); u32 count = 0; - const b3HalfEdge* start = e; + const b3HalfEdge* begin = e; do { const b3HalfEdge* next = edges + e->next; @@ -51,5 +65,5 @@ void b3Hull::Validate(const b3HalfEdge* e) const e = twin; B3_ASSERT(count < edgeCount); ++count; - } while (e != start); -} + } while (e != begin); +} \ No newline at end of file diff --git a/src/bounce/collision/trees/dynamic_tree.cpp b/src/bounce/collision/trees/dynamic_tree.cpp index baf4d65..7c2fd24 100644 --- a/src/bounce/collision/trees/dynamic_tree.cpp +++ b/src/bounce/collision/trees/dynamic_tree.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3DynamicTree::b3DynamicTree() { @@ -25,7 +25,7 @@ b3DynamicTree::b3DynamicTree() // Preallocate 32 nodes. m_nodeCapacity = 32; m_nodes = (b3Node*) b3Alloc(m_nodeCapacity * sizeof(b3Node)); - memset(m_nodes, NULL, m_nodeCapacity * sizeof(b3Node)); + memset(m_nodes, 0, m_nodeCapacity * sizeof(b3Node)); m_nodeCount = 0; // Link the allocated nodes and make the first node @@ -67,7 +67,7 @@ i32 b3DynamicTree::AllocateNode() m_nodes[node].child1 = NULL_NODE; m_nodes[node].child2 = NULL_NODE; m_nodes[node].height = 0; - m_nodes[node].userData = nullptr; + m_nodes[node].userData = NULL; ++m_nodeCount; @@ -133,7 +133,7 @@ void b3DynamicTree::UpdateNode(i32 proxyId, const b3AABB3& aabb) InsertLeaf(proxyId); } -i32 b3DynamicTree::HeuristicSearch(const b3AABB3& leafAABB) const +i32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const { // To find a good branch node, the manhattan distance could be used as heuristic. // However, the current propagated node and the leaf node volume are incompletely considerable. @@ -215,7 +215,7 @@ void b3DynamicTree::InsertLeaf(i32 leaf) b3AABB3 leafAabb = m_nodes[leaf].aabb; // Search for the best branch node of this tree starting from the tree root node. - i32 sibling = HeuristicSearch(leafAabb); + i32 sibling = FindBest(leafAabb); i32 oldParent = m_nodes[sibling].parent; @@ -226,7 +226,7 @@ void b3DynamicTree::InsertLeaf(i32 leaf) m_nodes[sibling].parent = newParent; m_nodes[newParent].child2 = leaf; m_nodes[leaf].parent = newParent; - m_nodes[newParent].userData = nullptr; + m_nodes[newParent].userData = NULL; m_nodes[newParent].aabb = b3Combine(leafAabb, m_nodes[sibling].aabb); m_nodes[newParent].height = m_nodes[sibling].height + 1; @@ -362,7 +362,7 @@ void b3DynamicTree::Validate(i32 nodeID) const } } -void b3DynamicTree::Draw(b3Draw* b3Draw) const +void b3DynamicTree::Draw(b3Draw* draw) const { b3Color red = b3Color(1.0f, 0.0f, 0.0f); b3Color green = b3Color(0.0f, 1.0f, 0.0f); @@ -390,11 +390,11 @@ void b3DynamicTree::Draw(b3Draw* b3Draw) const const b3Node* node = m_nodes + nodeIndex; if (node->IsLeaf()) { - b3Draw->DrawAABB(node->aabb, purple); + draw->DrawAABB(node->aabb, purple); } else { - b3Draw->DrawAABB(node->aabb, red); + draw->DrawAABB(node->aabb, red); stack.Push(node->child1); stack.Push(node->child2); diff --git a/src/bounce/collision/trees/static_tree.cpp b/src/bounce/collision/trees/static_tree.cpp index bcb27c3..552a67e 100644 --- a/src/bounce/collision/trees/static_tree.cpp +++ b/src/bounce/collision/trees/static_tree.cpp @@ -16,13 +16,13 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include #include b3StaticTree::b3StaticTree() { - m_nodes = nullptr; + m_nodes = NULL; m_nodeCount = 0; } @@ -31,17 +31,46 @@ b3StaticTree::~b3StaticTree() b3Free(m_nodes); } -void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N) +struct b3Params { - B3_ASSERT(N > 0); + u32 node; + u32* indices; + u32 numObjects; +}; - // Leafs = N, Internals = N - 1, Total = 2N - 1, if we assume +struct b3SortPredicate +{ + const b3AABB3* bs; + u32 axis; + + bool operator()(const u32& i, const u32& j) const + { + const b3AABB3* b1 = bs + i; + const b3AABB3* b2 = bs + j; + + b3Vec3 c1 = b1->Centroid(); + b3Vec3 c2 = b2->Centroid(); + + if (c1[axis] < c2[axis]) + { + return true; + } + + return false; + } +}; + +void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 n) +{ + B3_ASSERT(n > 0); + + // Leafs = n, Internals = n - 1, Total = 2n - 1, if we assume // each leaf node contains exactly 1 object. const u32 kMinObjectsPerLeaf = 1; - u32 internalCapacity = N - 1; - u32 leafCapacity = N; - u32 nodeCapacity = 2 * N - 1; + u32 internalCapacity = n - 1; + u32 leafCapacity = n; + u32 nodeCapacity = 2 * n - 1; u32 internalCount = 0; u32 leafCount = 0; @@ -49,42 +78,13 @@ void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N) m_nodes = (b3Node*)b3Alloc(nodeCapacity * sizeof(b3Node)); m_nodeCount = 1; - struct b3Params - { - u32 node; - u32* indices; - u32 numObjects; - }; - - struct b3SortPredicate - { - const b3AABB3* bs; - u32 axis; - - bool operator()(const u32& i, const u32& j) const - { - const b3AABB3* b1 = bs + i; - const b3AABB3* b2 = bs + j; - - b3Vec3 c1 = b1->Centroid(); - b3Vec3 c2 = b2->Centroid(); - - if (c1[axis] < c2[axis]) - { - return true; - } - - return false; - } - }; - b3Stack stack; { b3Params params; params.node = 0; params.indices = ids; - params.numObjects = N; + params.numObjects = n; stack.Push(params); } @@ -189,7 +189,7 @@ void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N) B3_ASSERT(m_nodeCount == nodeCapacity); } -void b3StaticTree::Draw(b3Draw* b3Draw) const +void b3StaticTree::Draw(b3Draw* draw) const { b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f); b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f); @@ -215,11 +215,11 @@ void b3StaticTree::Draw(b3Draw* b3Draw) const const b3Node* node = m_nodes + nodeIndex; if (node->IsLeaf()) { - b3Draw->DrawAABB(node->aabb, purple); + draw->DrawAABB(node->aabb, purple); } else { - b3Draw->DrawAABB(node->aabb, red); + draw->DrawAABB(node->aabb, red); stack.Push(node->child1); stack.Push(node->child2); diff --git a/src/bounce/common/math/mat.cpp b/src/bounce/common/math/mat.cpp index 6005db5..db118f0 100644 --- a/src/bounce/common/math/mat.cpp +++ b/src/bounce/common/math/mat.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include b3Vec2 b3Mat22::Solve(const b3Vec2& b) const { diff --git a/src/bounce/common/memory/block_pool.cpp b/src/bounce/common/memory/block_pool.cpp index 4abb1fc..307c39f 100644 --- a/src/bounce/common/memory/block_pool.cpp +++ b/src/bounce/common/memory/block_pool.cpp @@ -16,14 +16,14 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3BlockPool::b3BlockPool(u32 blockSize) { m_blockSize = blockSize; m_chunkSize = b3_blockCount * m_blockSize; - m_chunks = nullptr; + m_chunks = NULL; m_chunkCount = 0; // Pre-allocate some chunks @@ -42,7 +42,7 @@ b3BlockPool::b3BlockPool(u32 blockSize) current->next = (b3Block*)((u8*)chunk->freeBlocks + (i + 1) * blockSize); } b3Block* last = (b3Block*)((u8*)chunk->freeBlocks + (b3_blockCount - 1) * blockSize); - last->next = nullptr; + last->next = NULL; // Push back the new chunk of the singly-linked list of chunks. chunk->next = m_chunks; @@ -90,7 +90,7 @@ void* b3BlockPool::Allocate() current->next = (b3Block*)((u8*)chunk->freeBlocks + (i + 1) * m_blockSize); } b3Block* last = (b3Block*)((u8*)chunk->freeBlocks + (b3_blockCount - 1) * m_blockSize); - last->next = nullptr; + last->next = NULL; // Push back the new chunk of the singly-linked list of chunks. chunk->next = m_chunks; diff --git a/src/bounce/common/memory/stack_allocator.cpp b/src/bounce/common/memory/stack_allocator.cpp index 7a0d8be..f158ff9 100644 --- a/src/bounce/common/memory/stack_allocator.cpp +++ b/src/bounce/common/memory/stack_allocator.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3StackAllocator::b3StackAllocator() { diff --git a/src/bounce/common/settings.cpp b/src/bounce/common/settings.cpp index f800954..2bea79b 100644 --- a/src/bounce/common/settings.cpp +++ b/src/bounce/common/settings.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include #include #include #include diff --git a/src/bounce/common/time.cpp b/src/bounce/common/time.cpp deleted file mode 100644 index 0e99e8e..0000000 --- a/src/bounce/common/time.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -*/ - -#include - -// This file contains platform dependent code -// and may not compile depending of the OS. - -#if (_WIN32 == 1) - -#include - -float64 GetCyclesPerSecond() -{ - LARGE_INTEGER integer; - QueryPerformanceFrequency(&integer); - return float64(integer.QuadPart); -} - -u64 GetCycleCount() -{ - LARGE_INTEGER integer; - QueryPerformanceCounter(&integer); - return integer.QuadPart; -} - -#endif - -float64 b3Time::m_invFrequency = 0.0; - -b3Time::b3Time() -{ - m_lastTime = 0; - m_curTime = 0; - - if (m_invFrequency == 0.0) - { - float64 cyclesPerSec = GetCyclesPerSecond(); - float64 secPerCycles = 1.0 / cyclesPerSec; - float64 milisecPerCycles = 1000.0 * secPerCycles; - m_invFrequency = milisecPerCycles; - } - - m_lastRealTime = GetCycleCount(); -} - -void b3Time::Update() -{ - // Retrieve the current time in units of cycles. - u64 curTime = GetCycleCount(); - u64 dt = curTime - m_lastRealTime; - m_lastRealTime = curTime; - - float64 dtMs = m_invFrequency * float64(dt); - - UpdateBy(dtMs); -} - -void b3Time::UpdateBy(float64 delta) -{ - m_lastTime = m_curTime; - m_curTime += delta; -} diff --git a/src/bounce/dynamics/body.cpp b/src/bounce/dynamics/body.cpp index 5893976..e0eb06d 100644 --- a/src/bounce/dynamics/body.cpp +++ b/src/bounce/dynamics/body.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include b3Body::b3Body(const b3BodyDef& def, b3World* world) { @@ -107,7 +107,7 @@ b3Shape* b3Body::CreateShape(const b3ShapeDef& def) } // Compute the world AABB of the new shape and assign a broad-phase proxy to it. - b3Transform xf = shape->GetTransform(); + b3Transform xf = m_xf; b3AABB3 aabb; shape->ComputeAABB(&aabb, xf); diff --git a/src/bounce/dynamics/contact_manager.cpp b/src/bounce/dynamics/contact_manager.cpp index d61dab7..88b970a 100644 --- a/src/bounce/dynamics/contact_manager.cpp +++ b/src/bounce/dynamics/contact_manager.cpp @@ -16,19 +16,19 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include b3ContactManager::b3ContactManager() : m_convexBlocks(sizeof(b3ConvexContact)), m_meshBlocks(sizeof(b3MeshContact)) { - m_contactListener = nullptr; - m_contactFilter = nullptr; + m_contactListener = NULL; + m_contactFilter = NULL; } void b3ContactManager::AddPair(void* dataA, void* dataB) @@ -123,7 +123,7 @@ void b3ContactManager::AddPair(void* dataA, void* dataB) // Add the contact to the world contact list. m_contactList.PushFront(c); - if (c->m_type == b3ContactType::e_meshContact) + if (c->m_type == e_meshContact) { // Add the contact to the world mesh contact list. b3MeshContact* mc = (b3MeshContact*)c; @@ -237,7 +237,7 @@ b3Contact* b3ContactManager::Create(b3Shape* shapeA, b3Shape* shapeB) B3_ASSERT(typeA <= typeB); - b3Contact* c = nullptr; + b3Contact* c = NULL; if (typeA != e_meshShape && typeB != e_meshShape) { void* block = m_convexBlocks.Allocate(); @@ -267,7 +267,7 @@ b3Contact* b3ContactManager::Create(b3Shape* shapeA, b3Shape* shapeB) void b3ContactManager::Destroy(b3Contact* c) { - // Report to the contact listener that the contact will be destroyed. + // Report to the contact listener the contact will be destroyed. if (m_contactListener) { if (c->IsOverlapping()) @@ -297,7 +297,7 @@ void b3ContactManager::Destroy(b3Contact* c) { b3MeshContact* mc = (b3MeshContact*)c; - // Remove the contact from the world mesh contact list. + // Remove the mesh contact from the world mesh contact list. m_meshContactList.Remove(&mc->m_link); mc->~b3MeshContact(); diff --git a/src/bounce/dynamics/contacts/collide/clip.cpp b/src/bounce/dynamics/contacts/collide/clip.cpp index 9a3698a..650e7b1 100644 --- a/src/bounce/dynamics/contacts/collide/clip.cpp +++ b/src/bounce/dynamics/contacts/collide/clip.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include void b3BuildEdge(b3ClipVertex vOut[2], const b3Capsule* hull) diff --git a/src/bounce/dynamics/contacts/collide/collide.cpp b/src/bounce/dynamics/contacts/collide/collide.cpp index fb703e1..02b56b5 100644 --- a/src/bounce/dynamics/contacts/collide/collide.cpp +++ b/src/bounce/dynamics/contacts/collide/collide.cpp @@ -16,16 +16,16 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include void b3ShapeGJKProxy::Set(const b3Shape* shape, u32 index) { @@ -171,8 +171,8 @@ void b3CollideShapeAndShape(b3Manifold& manifold, static const b3CollideFunction s_CollideMatrix[e_maxShapes][e_maxShapes] = { { &b3CollideSphereAndSphereShapes, &b3CollideSphereAndCapsuleShapes, &b3CollideSphereAndHullShapes }, - { nullptr, &b3CollideCapsuleAndCapsuleShapes, &b3CollideCapsuleAndHullShapes }, - { nullptr, nullptr, &b3CollideHullAndHullShapes }, + { NULL, &b3CollideCapsuleAndCapsuleShapes, &b3CollideCapsuleAndHullShapes }, + { NULL, NULL, &b3CollideHullAndHullShapes }, }; b3ShapeType typeA = shapeA->GetType(); diff --git a/src/bounce/dynamics/contacts/collide/collide_capsule_and_hull.cpp b/src/bounce/dynamics/contacts/collide/collide_capsule_and_hull.cpp index a21ace5..bfa2265 100644 --- a/src/bounce/dynamics/contacts/collide/collide_capsule_and_hull.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_capsule_and_hull.cpp @@ -16,13 +16,13 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include void b3BuildEdgeContact(b3Manifold& manifold, const b3Transform& xf1, const b3Capsule* hull1, diff --git a/src/bounce/dynamics/contacts/collide/collide_capsules.cpp b/src/bounce/dynamics/contacts/collide/collide_capsules.cpp index f1ef7b0..9f21e52 100644 --- a/src/bounce/dynamics/contacts/collide/collide_capsules.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_capsules.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include bool b3AreParalell(const b3Capsule& hullA, const b3Capsule& hullB) { diff --git a/src/bounce/dynamics/contacts/collide/collide_hulls.cpp b/src/bounce/dynamics/contacts/collide/collide_hulls.cpp index d11fe0c..073de7e 100644 --- a/src/bounce/dynamics/contacts/collide/collide_hulls.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_hulls.cpp @@ -16,12 +16,12 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include void b3BuildEdgeContact(b3Manifold& manifold, const b3Transform& xfA, const b3Hull* hullA, diff --git a/src/bounce/dynamics/contacts/collide/collide_hulls_cache.cpp b/src/bounce/dynamics/contacts/collide/collide_hulls_cache.cpp index 61ec2d0..9380638 100644 --- a/src/bounce/dynamics/contacts/collide/collide_hulls_cache.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_hulls_cache.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include extern u32 b3_convexCacheHits; diff --git a/src/bounce/dynamics/contacts/collide/collide_sphere_and_capsule.cpp b/src/bounce/dynamics/contacts/collide/collide_sphere_and_capsule.cpp index f903c8a..1418de7 100644 --- a/src/bounce/dynamics/contacts/collide/collide_sphere_and_capsule.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_sphere_and_capsule.cpp @@ -16,12 +16,12 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include void b3CollideSphereAndCapsule(b3Manifold& manifold, const b3Transform& xfA, const b3SphereShape* sA, diff --git a/src/bounce/dynamics/contacts/collide/collide_sphere_and_hull.cpp b/src/bounce/dynamics/contacts/collide/collide_sphere_and_hull.cpp index 65b5639..ebdafe7 100644 --- a/src/bounce/dynamics/contacts/collide/collide_sphere_and_hull.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_sphere_and_hull.cpp @@ -16,12 +16,12 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include void b3CollideSphereAndHull(b3Manifold& manifold, const b3Transform& xf1, const b3SphereShape* s1, diff --git a/src/bounce/dynamics/contacts/collide/collide_spheres.cpp b/src/bounce/dynamics/contacts/collide/collide_spheres.cpp index 5d9c2bc..79b527f 100644 --- a/src/bounce/dynamics/contacts/collide/collide_spheres.cpp +++ b/src/bounce/dynamics/contacts/collide/collide_spheres.cpp @@ -16,10 +16,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include +#include +#include +#include +#include void b3CollideSphereAndSphere(b3Manifold& manifold, const b3Transform& xf1, const b3SphereShape* s1, diff --git a/src/bounce/dynamics/contacts/contact.cpp b/src/bounce/dynamics/contacts/contact.cpp index a2968c1..5270f8f 100644 --- a/src/bounce/dynamics/contacts/contact.cpp +++ b/src/bounce/dynamics/contacts/contact.cpp @@ -16,12 +16,12 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include const b3Manifold* b3Contact::GetManifold(u32 index) const { @@ -41,10 +41,10 @@ void b3Contact::GetWorldManifold(b3WorldManifold* out, u32 index) const b3Manifold* m = m_manifolds + index; const b3Shape* shapeA = GetShapeA(); - b3Transform xfA = shapeA->GetTransform(); + b3Transform xfA = shapeA->GetBody()->GetTransform(); const b3Shape* shapeB = GetShapeB(); - b3Transform xfB = shapeB->GetTransform(); + b3Transform xfB = shapeB->GetBody()->GetTransform(); out->Initialize(m, xfA, shapeA->m_radius, xfB, shapeB->m_radius); } @@ -54,12 +54,12 @@ void b3Contact::Update(b3ContactListener* listener) b3Shape* shapeA = GetShapeA(); b3Body* bodyA = shapeA->GetBody(); i32 proxyA = shapeA->m_broadPhaseID; - b3Transform xfA = shapeA->GetTransform(); + b3Transform xfA = bodyA->GetTransform(); b3Shape* shapeB = GetShapeB(); b3Body* bodyB = shapeB->GetBody(); i32 proxyB = shapeB->m_broadPhaseID; - b3Transform xfB = shapeB->GetTransform(); + b3Transform xfB = bodyB->GetTransform(); b3World* world = bodyA->GetWorld(); @@ -134,7 +134,7 @@ void b3Contact::Update(b3ContactListener* listener) } // Notify the contact listener the new contact state. - if (listener != nullptr) + if (listener != NULL) { if (wasOverlapping == false && isOverlapping == true) { diff --git a/src/bounce/dynamics/contacts/contact_cluster.cpp b/src/bounce/dynamics/contacts/contact_cluster.cpp index eb4dee8..b44f5ad 100644 --- a/src/bounce/dynamics/contacts/contact_cluster.cpp +++ b/src/bounce/dynamics/contacts/contact_cluster.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include inline void AddCluster(b3Array& clusters, const b3Vec3& centroid) { diff --git a/src/bounce/dynamics/contacts/contact_solver.cpp b/src/bounce/dynamics/contacts/contact_solver.cpp index 632fe92..86270ef 100644 --- a/src/bounce/dynamics/contacts/contact_solver.cpp +++ b/src/bounce/dynamics/contacts/contact_solver.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include // This solver implements PGS for solving velocity constraints and // NGS for solving position constraints. diff --git a/src/bounce/dynamics/contacts/convex_contact.cpp b/src/bounce/dynamics/contacts/convex_contact.cpp index 8712ef7..58859a6 100644 --- a/src/bounce/dynamics/contacts/convex_contact.cpp +++ b/src/bounce/dynamics/contacts/convex_contact.cpp @@ -16,9 +16,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include +#include b3ConvexContact::b3ConvexContact(b3Shape* shapeA, b3Shape* shapeB) { @@ -35,10 +36,10 @@ b3ConvexContact::b3ConvexContact(b3Shape* shapeA, b3Shape* shapeB) bool b3ConvexContact::TestOverlap() { b3Shape* shapeA = GetShapeA(); - b3Transform xfA = shapeA->GetTransform(); + b3Transform xfA = shapeA->GetBody()->GetTransform(); b3Shape* shapeB = GetShapeB(); - b3Transform xfB = shapeB->GetTransform(); + b3Transform xfB = shapeB->GetBody()->GetTransform(); return b3TestOverlap(xfA, 0, shapeA, xfB, 0, shapeB, &m_cache); } @@ -46,16 +47,14 @@ bool b3ConvexContact::TestOverlap() void b3ConvexContact::Collide() { b3Shape* shapeA = GetShapeA(); - b3Transform xfA = shapeA->GetTransform(); + b3Body* bodyA = shapeA->GetBody(); + b3Transform xfA = bodyA->GetTransform(); b3Shape* shapeB = GetShapeB(); - b3Transform xfB = shapeB->GetTransform(); + b3Body* bodyB = shapeB->GetBody(); + b3Transform xfB = bodyB->GetTransform(); B3_ASSERT(m_manifoldCount == 0); b3CollideShapeAndShape(m_stackManifold, xfA, shapeA, xfB, shapeB, &m_cache); m_manifoldCount = 1; -} - -void b3ConvexContact::SynchronizeShapes() -{ } \ No newline at end of file diff --git a/src/bounce/dynamics/contacts/manifold.cpp b/src/bounce/dynamics/contacts/manifold.cpp index ea7f7a1..018c5bb 100644 --- a/src/bounce/dynamics/contacts/manifold.cpp +++ b/src/bounce/dynamics/contacts/manifold.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include void b3Manifold::GuessImpulses() { diff --git a/src/bounce/dynamics/contacts/mesh_contact.cpp b/src/bounce/dynamics/contacts/mesh_contact.cpp index ce8dd17..46ba790 100644 --- a/src/bounce/dynamics/contacts/mesh_contact.cpp +++ b/src/bounce/dynamics/contacts/mesh_contact.cpp @@ -16,16 +16,16 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include b3MeshContact::b3MeshContact(b3Shape* shapeA, b3Shape* shapeB) { @@ -35,11 +35,12 @@ b3MeshContact::b3MeshContact(b3Shape* shapeA, b3Shape* shapeB) m_manifolds = m_stackManifolds; m_manifoldCount = 0; - b3Transform xfA = shapeA->GetTransform(); - b3Transform xfB = shapeB->GetTransform(); + b3Transform xfA = shapeA->GetBody()->GetTransform(); + b3Transform xfB = shapeB->GetBody()->GetTransform(); b3Transform xf = b3MulT(xfB, xfA); - + + // The fat aabb relative to shape B's frame. b3AABB3 fatAABB; shapeA->ComputeAABB(&fatAABB, xf); fatAABB.Extend(B3_AABB_EXTENSION); @@ -65,16 +66,16 @@ void b3MeshContact::SynchronizeShapes() b3Transform xfA = bodyA->m_xf; b3Shape* shapeB = GetShapeB(); - b3Transform xfB = shapeB->GetTransform(); + b3Body* bodyB = shapeB->GetBody(); + b3Transform xfB = bodyB->GetTransform(); b3Sweep* sweepA = &bodyA->m_sweep; b3Transform xfA0; xfA0.position = sweepA->worldCenter0; xfA0.rotation = b3ConvertQuatToRot(sweepA->orientation0); - // Calculate the displacement of the body A. - // using its position at the last time step and the current position. - // Could use displacement = velocity * dt. + // Calculate the displacement of body A using its position at the last + // time step and the current position. b3Vec3 displacement = xfA.position - xfA0.position; // Compute the AABB in the reference frame of shape B. @@ -83,8 +84,7 @@ void b3MeshContact::SynchronizeShapes() b3AABB3 aabb; shapeA->ComputeAABB(&aabb, xf); - // Update the AABB with the new (transformed) AABB and - // buffer move. + // Update the AABB with the new (transformed) AABB and buffer move. m_aabbMoved = MoveAABB(aabb, displacement); } @@ -191,11 +191,13 @@ bool b3MeshContact::Report(u32 proxyId) bool b3MeshContact::TestOverlap() { b3Shape* shapeA = GetShapeA(); - b3Transform xfA = shapeA->GetTransform(); + b3Body* bodyA = shapeA->GetBody(); + b3Transform xfA = bodyA->GetTransform(); u32 indexA = 0; b3Shape* shapeB = GetShapeB(); - b3Transform xfB = shapeB->GetTransform(); + b3Body* bodyB = shapeB->GetBody(); + b3Transform xfB = bodyB->GetTransform(); b3MeshShape* meshShapeB = (b3MeshShape*)shapeB; const b3Mesh* meshB = meshShapeB->m_mesh; @@ -222,15 +224,17 @@ void b3MeshContact::Collide() b3Shape* shapeA = GetShapeA(); b3Body* bodyA = shapeA->GetBody(); - b3Transform xfA = shapeA->GetTransform(); + b3Transform xfA = bodyA->GetTransform(); b3Shape* shapeB = GetShapeB(); + b3Body* bodyB = shapeB->GetBody(); b3MeshShape* meshShapeB = (b3MeshShape*)shapeB; - b3Transform xfB = shapeB->GetTransform(); + b3Transform xfB = bodyB->GetTransform(); b3World* world = bodyA->GetWorld(); b3StackAllocator* allocator = &world->m_stackAllocator; + // Create one manifold per triangle. b3Manifold* tempManifolds = (b3Manifold*)allocator->Allocate(m_triangleCount * sizeof(b3Manifold)); u32 tempCount = 0; @@ -263,7 +267,8 @@ void b3MeshContact::Collide() ++tempCount; } + // Send contact manifolds for clustering. This is an important optimization. B3_ASSERT(m_manifoldCount == 0); m_manifoldCount = b3Clusterize(m_stackManifolds, tempManifolds, tempCount, xfA, shapeA->m_radius, xfB, B3_HULL_RADIUS); allocator->Free(tempManifolds); -} +} \ No newline at end of file diff --git a/src/bounce/dynamics/draw_world.cpp b/src/bounce/dynamics/draw_world.cpp index d3e14ee..1e77d7b 100644 --- a/src/bounce/dynamics/draw_world.cpp +++ b/src/bounce/dynamics/draw_world.cpp @@ -16,29 +16,29 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include void b3World::DebugDraw() const { @@ -108,7 +108,7 @@ void b3World::DebugDraw() const const b3Manifold* m = manifolds + i; b3WorldManifold wm; - wm.Initialize(m, shapeA->GetTransform(), shapeA->m_radius, shapeB->GetTransform(), shapeB->m_radius); + wm.Initialize(m, shapeA->GetBody()->GetTransform(), shapeA->m_radius, shapeB->GetBody()->GetTransform(), shapeB->m_radius); if (wm.pointCount > 0) { diff --git a/src/bounce/dynamics/island.cpp b/src/bounce/dynamics/island.cpp index 47b4701..51e8668 100644 --- a/src/bounce/dynamics/island.cpp +++ b/src/bounce/dynamics/island.cpp @@ -16,15 +16,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include b3Island::b3Island(b3StackAllocator* allocator, u32 bodyCapacity, u32 contactCapacity, u32 jointCapacity) { diff --git a/src/bounce/dynamics/joint_manager.cpp b/src/bounce/dynamics/joint_manager.cpp index 028ac73..b81c579 100644 --- a/src/bounce/dynamics/joint_manager.cpp +++ b/src/bounce/dynamics/joint_manager.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include b3JointManager::b3JointManager() { @@ -33,7 +33,7 @@ b3Joint* b3JointManager::Create(const b3JointDef* def) B3_ASSERT(bodyA != bodyB); if (bodyA == bodyB) { - return nullptr; + return NULL; } // Allocate the new joint. diff --git a/src/bounce/dynamics/joints/cone_joint.cpp b/src/bounce/dynamics/joints/cone_joint.cpp index 059ee41..673fc7f 100644 --- a/src/bounce/dynamics/joints/cone_joint.cpp +++ b/src/bounce/dynamics/joints/cone_joint.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include -// C = dot(u2, u1) - cos(0.5 * angle) > 0 +// C = dot(u2, u1) - cos(angle / 2) > 0 // Cdot = dot(u2, omega1 x u1) + dot(u1, omega2 x u2) // Cycle: // dot(u1 x u2, omega1) + dot(u2 x u1, omega2) = @@ -28,6 +28,9 @@ // n = u2 x u1 // J = [0 -n 0 n] +// Stable C: +// C = angle / 2 - atan2( norm(u2 x u1), dot(u2, u1) ) > 0 + void b3ConeJointDef::Initialize(b3Body* bA, b3Body* bB, const b3Vec3& axis, const b3Vec3& anchor, float32 angle) { @@ -109,7 +112,7 @@ void b3ConeJoint::InitializeConstraints(const b3SolverData* data) float32 mass = b3Dot((m_iA + m_iB) * m_limitAxis, m_limitAxis); m_limitMass = mass > 0.0f ? 1.0f / mass : 0.0f; - // C = cone - angle >= 0 + // C = cone / 2 - angle >= 0 float32 cosine = b3Dot(u2, u1); float32 sine = b3Length(m_limitAxis); float32 angle = atan2(sine, cosine); @@ -185,23 +188,12 @@ void b3ConeJoint::SolveVelocityConstraints(const b3SolverData* data) // Solve limit constraint. if (m_enableLimit && m_limitState != e_inactiveLimit) { - float32 impulse = 0.0f; + float32 Cdot = b3Dot(m_limitAxis, wB - wA); + float32 impulse = -m_limitMass * Cdot; + float32 oldImpulse = m_limitImpulse; + m_limitImpulse = b3Max(m_limitImpulse + impulse, 0.0f); + impulse = m_limitImpulse - oldImpulse; - if (m_limitState == e_equalLimits) - { - float32 Cdot = b3Dot(m_limitAxis, wB - wA); - impulse = -m_limitMass * Cdot; - m_limitImpulse += impulse; - } - else if (m_limitState == e_atLowerLimit) - { - float32 Cdot = b3Dot(m_limitAxis, wB - wA); - impulse = -m_limitMass * Cdot; - float32 oldImpulse = m_limitImpulse; - m_limitImpulse = b3Max(m_limitImpulse + impulse, 0.0f); - impulse = m_limitImpulse - oldImpulse; - } - b3Vec3 P = impulse * m_limitAxis; wA -= m_iA * P; @@ -258,12 +250,12 @@ bool b3ConeJoint::SolvePositionConstraints(const b3SolverData* data) float32 limitError = 0.0f; if (m_enableLimit) { - // Compute Jacobian + // Compute fresh Jacobian b3Vec3 u1 = b3Mul(qA, m_localFrameA.rotation.y); b3Vec3 u2 = b3Mul(qB, m_localFrameB.rotation.y); b3Vec3 limitAxis = b3Cross(u2, u1); - // Compute effective mass. + // Compute fresh effective mass. float32 mass = b3Dot((iA + iB) * limitAxis, limitAxis); float32 limitMass = mass > 0.0f ? 1.0f / mass : 0.0f; @@ -301,26 +293,26 @@ bool b3ConeJoint::SolvePositionConstraints(const b3SolverData* data) return linearError <= B3_LINEAR_SLOP && limitError <= B3_ANGULAR_SLOP; } -const b3Transform& b3ConeJoint::GetFrameA() const +b3Transform b3ConeJoint::GetFrameA() const +{ + return GetBodyA()->GetWorldFrame(m_localFrameA); +} + +b3Transform b3ConeJoint::GetFrameB() const +{ + return GetBodyB()->GetWorldFrame(m_localFrameB); +} + +const b3Transform& b3ConeJoint::GetLocalFrameA() const { return m_localFrameA; } -void b3ConeJoint::SetFrameA(const b3Transform& frame) -{ - m_localFrameA = frame; -} - -const b3Transform& b3ConeJoint::GetFrameB() const +const b3Transform& b3ConeJoint::GetLocalFrameB() const { return m_localFrameB; } -void b3ConeJoint::SetFrameB(const b3Transform& frame) -{ - m_localFrameB = frame; -} - bool b3ConeJoint::IsLimitEnabled() const { return m_enableLimit; @@ -338,14 +330,14 @@ void b3ConeJoint::SetEnableLimit(bool bit) } } -float32 b3ConeJoint::GetLowerLimit() const +float32 b3ConeJoint::GetConeAngle() const { return m_coneAngle; } -void b3ConeJoint::SetLimit(float32 angle) +void b3ConeJoint::SetConeAngle(float32 angle) { - if (angle != m_coneAngle || angle != m_coneAngle) + if (angle != m_coneAngle) { GetBodyA()->SetAwake(true); GetBodyB()->SetAwake(true); @@ -354,10 +346,10 @@ void b3ConeJoint::SetLimit(float32 angle) } } -void b3ConeJoint::Draw(b3Draw* b3Draw) const +void b3ConeJoint::Draw(b3Draw* draw) const { - b3Transform xfA = GetBodyA()->GetWorldFrame(m_localFrameA); - b3Draw->DrawTransform(xfA); - b3Transform xfB = GetBodyB()->GetWorldFrame(m_localFrameB); - b3Draw->DrawTransform(xfB); -} + b3Transform xfA = GetFrameA(); + draw->DrawTransform(xfA); + b3Transform xfB = GetFrameB(); + draw->DrawTransform(xfB); +} \ No newline at end of file diff --git a/src/bounce/dynamics/joints/joint.cpp b/src/bounce/dynamics/joints/joint.cpp index d633f7d..7fb43dd 100644 --- a/src/bounce/dynamics/joints/joint.cpp +++ b/src/bounce/dynamics/joints/joint.cpp @@ -16,16 +16,16 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include b3Joint* b3Joint::Create(const b3JointDef* def) { - b3Joint* joint = nullptr; + b3Joint* joint = NULL; switch (def->type) { case e_mouseJoint: diff --git a/src/bounce/dynamics/joints/joint_solver.cpp b/src/bounce/dynamics/joints/joint_solver.cpp index 4bfac9c..f247d5c 100644 --- a/src/bounce/dynamics/joints/joint_solver.cpp +++ b/src/bounce/dynamics/joints/joint_solver.cpp @@ -16,8 +16,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include b3JointSolver::b3JointSolver(const b3JointSolverDef* def) { diff --git a/src/bounce/dynamics/joints/mouse_joint.cpp b/src/bounce/dynamics/joints/mouse_joint.cpp index 1e2fa44..2a9f923 100644 --- a/src/bounce/dynamics/joints/mouse_joint.cpp +++ b/src/bounce/dynamics/joints/mouse_joint.cpp @@ -16,15 +16,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include b3MouseJoint::b3MouseJoint(const b3MouseJointDef* def) { m_type = e_mouseJoint; - m_worldAnchorA = def->worldAnchorA; - m_localAnchorB = def->localAnchorB; + m_worldTargetA = def->target; + m_localAnchorB = def->bodyB->GetLocalPoint(def->target); m_maxForce = def->maxForce; m_impulse.SetZero(); } @@ -42,7 +42,7 @@ void b3MouseJoint::InitializeConstraints(const b3SolverData* data) b3Vec3 worldAnchorB = b3Mul(qB, m_localAnchorB) + xB; - m_C = worldAnchorB - m_worldAnchorA; + m_C = worldAnchorB - m_worldTargetA; m_rB = worldAnchorB - xB; b3Mat33 M = b3Diagonal(m_mB); @@ -54,7 +54,7 @@ void b3MouseJoint::InitializeConstraints(const b3SolverData* data) void b3MouseJoint::WarmStart(const b3SolverData* data) { data->velocities[m_indexB].v += m_mB * m_impulse; - data->velocities[m_indexB].w += b3Mul(m_iB, b3Cross(m_rB, m_impulse)); + data->velocities[m_indexB].w += m_iB * b3Cross(m_rB, m_impulse); } void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data) @@ -80,7 +80,7 @@ void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data) impulse = m_impulse - oldImpulse; vB += m_mB * impulse; - wB += b3Mul(m_iB, b3Cross(m_rB, impulse)); + wB += m_iB * b3Cross(m_rB, impulse); data->velocities[m_indexB].v = vB; data->velocities[m_indexB].w = wB; @@ -88,27 +88,41 @@ void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data) bool b3MouseJoint::SolvePositionConstraints(const b3SolverData* data) { - // There is no position correction for spring joints. + // There is no position correction for this constraint. + // todo Implement Buda spring? return true; } -// Get the world space anchor point on the first body (usually the mouse world space position). -b3Vec3 b3MouseJoint::GetWorldAnchorB() const +b3Vec3 b3MouseJoint::GetAnchorA() const { - return b3Mul(GetBodyB()->GetTransform(), m_localAnchorB); + return m_worldTargetA; } -void b3MouseJoint::Draw(b3Draw* b3Draw) const +b3Vec3 b3MouseJoint::GetAnchorB() const { - b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f); - b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f); - b3Color yellow = b3Color(1.0f, 1.0f, 0.0f, 1.0f); + return GetBodyB()->GetWorldPoint(m_localAnchorB); +} + +const b3Vec3& b3MouseJoint::GetTarget() const +{ + return m_worldTargetA; +} + +void b3MouseJoint::SetTarget(const b3Vec3& target) +{ + m_worldTargetA = target; +} + +void b3MouseJoint::Draw(b3Draw* draw) const +{ + b3Color red(1.0f, 0.0f, 0.0f); + b3Color green(0.0f, 1.0f, 0.0f); + b3Color yellow(1.0f, 1.0f, 0.0f); - b3Transform xfB = GetBodyB()->m_xf; - b3Vec3 worldAnchorA = m_worldAnchorA; - b3Vec3 worldAnchorB = b3Mul(xfB, m_localAnchorB); + b3Vec3 a = GetAnchorA(); + b3Vec3 b = GetAnchorB(); - b3Draw->DrawPoint(worldAnchorA, green); - b3Draw->DrawPoint(worldAnchorB, red); - b3Draw->DrawSegment(worldAnchorA, worldAnchorB, yellow); -} + draw->DrawPoint(a, green); + draw->DrawPoint(b, red); + draw->DrawSegment(a, b, yellow); +} \ No newline at end of file diff --git a/src/bounce/dynamics/joints/revolute_joint.cpp b/src/bounce/dynamics/joints/revolute_joint.cpp index b7e2e8e..29b74bd 100644 --- a/src/bounce/dynamics/joints/revolute_joint.cpp +++ b/src/bounce/dynamics/joints/revolute_joint.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include // C1 = p2 - p1 // C2 = dot(u2, w1) @@ -35,7 +35,7 @@ // [0 -n1 0 n1] // [0 -n2 0 n2] -// W = [i1 0 0] +// W = [i1 0 0 0] // [0 m1 0 0] // [0 0 i2 0] // [0 0 0 m2] @@ -359,8 +359,7 @@ void b3RevoluteJoint::SolveVelocityConstraints(const b3SolverData* data) Cdot[3] = Cdot2; Cdot[4] = Cdot3; - // Copy the effective mass so it can be destroyed in the - // linear solver. + // Copy the matrix so it can be destroyed in the linear solver. b3Mat<5, 5> mass = m_mass; b3Vec<5> impulse = -Cdot; if (b3Solve(impulse.e, mass.e, 5)) @@ -566,26 +565,26 @@ bool b3RevoluteJoint::SolvePositionConstraints(const b3SolverData* data) limitError <= B3_ANGULAR_SLOP; } -const b3Transform& b3RevoluteJoint::GetFrameA() const +b3Transform b3RevoluteJoint::GetFrameA() const +{ + return GetBodyA()->GetWorldFrame(m_localFrameA); +} + +b3Transform b3RevoluteJoint::GetFrameB() const +{ + return GetBodyB()->GetWorldFrame(m_localFrameB); +} + +const b3Transform& b3RevoluteJoint::GetLocalFrameA() const { return m_localFrameA; } -void b3RevoluteJoint::SetFrameA(const b3Transform& frame) -{ - m_localFrameA = frame; -} - -const b3Transform& b3RevoluteJoint::GetFrameB() const +const b3Transform& b3RevoluteJoint::GetLocalFrameB() const { return m_localFrameB; } -void b3RevoluteJoint::SetFrameB(const b3Transform& frame) -{ - m_localFrameB = frame; -} - bool b3RevoluteJoint::IsLimitEnabled() const { return m_enableLimit; @@ -666,10 +665,10 @@ void b3RevoluteJoint::SetMaxMotorTorque(float32 torque) m_maxMotorTorque = torque; } -void b3RevoluteJoint::Draw(b3Draw* b3Draw) const +void b3RevoluteJoint::Draw(b3Draw* draw) const { - b3Transform xfA = GetBodyA()->GetWorldFrame(m_localFrameA); - b3Draw->DrawTransform(xfA); - b3Transform xfB = GetBodyB()->GetWorldFrame(m_localFrameB); - b3Draw->DrawTransform(xfB); -} + b3Transform xfA = GetFrameA(); + b3Transform xfB = GetFrameB(); + draw->DrawTransform(xfA); + draw->DrawTransform(xfB); +} \ No newline at end of file diff --git a/src/bounce/dynamics/joints/sphere_joint.cpp b/src/bounce/dynamics/joints/sphere_joint.cpp index d402cb8..a42cc1e 100644 --- a/src/bounce/dynamics/joints/sphere_joint.cpp +++ b/src/bounce/dynamics/joints/sphere_joint.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include void b3SphereJointDef::Initialize(b3Body* bA, b3Body* bB, const b3Vec3& anchor) { @@ -147,12 +147,22 @@ bool b3SphereJoint::SolvePositionConstraints(const b3SolverData* data) return b3Length(C) <= B3_LINEAR_SLOP; } -void b3SphereJoint::Draw(b3Draw* b3Draw) const +b3Vec3 b3SphereJoint::GetAnchorA() const { - b3Vec3 pA = GetBodyA()->GetWorldPoint(m_localAnchorA); - b3Draw->DrawPoint(pA, b3Color(1.0f, 0.0f, 0.0f, 1.0f)); - b3Vec3 pB = GetBodyB()->GetWorldPoint(m_localAnchorB); - b3Draw->DrawPoint(pB, b3Color(0.0f, 1.0f, 0.0f, 1.0f)); - - b3Draw->DrawSegment(pA, pB, b3Color(1.0f, 1.0f, 0.0f, 1.0f)); + return GetBodyA()->GetWorldPoint(m_localAnchorA); +} + +b3Vec3 b3SphereJoint::GetAnchorB() const +{ + return GetBodyB()->GetWorldPoint(m_localAnchorB); +} + +void b3SphereJoint::Draw(b3Draw* draw) const +{ + b3Vec3 a = GetAnchorA(); + b3Vec3 b = GetAnchorB(); + + draw->DrawPoint(a, b3Color(1.0f, 0.0f, 0.0f)); + draw->DrawPoint(b, b3Color(0.0f, 1.0f, 0.0f)); + draw->DrawSegment(a, b, b3Color(1.0f, 1.0f, 0.0f)); } diff --git a/src/bounce/dynamics/joints/spring_joint.cpp b/src/bounce/dynamics/joints/spring_joint.cpp index 03c2279..e786c64 100644 --- a/src/bounce/dynamics/joints/spring_joint.cpp +++ b/src/bounce/dynamics/joints/spring_joint.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include // C = ||x2 + r2 - x1 - r1|| - length // Cdot = dot(n, v2 + w2 x r2 - v1 - w1 x r1) @@ -44,6 +44,56 @@ b3SpringJoint::b3SpringJoint(const b3SpringJointDef* def) m_impulse = 0.0f; } +b3Vec3 b3SpringJoint::GetAnchorA() const +{ + return GetBodyA()->GetWorldPoint(m_localAnchorA); +} + +b3Vec3 b3SpringJoint::GetAnchorB() const +{ + return GetBodyB()->GetWorldPoint(m_localAnchorB); +} + +const b3Vec3& b3SpringJoint::GetLocalAnchorA() const +{ + return m_localAnchorA; +} + +const b3Vec3& b3SpringJoint::GetLocalAnchorB() const +{ + return m_localAnchorB; +} + +float32 b3SpringJoint::GetLength() const +{ + return m_length; +} + +void b3SpringJoint::SetLength(float32 length) +{ + m_length = length; +} + +float32 b3SpringJoint::GetFrequency() const +{ + return m_frequencyHz; +} + +void b3SpringJoint::SetFrequency(float32 frequency) +{ + m_frequencyHz = frequency; +} + +float32 b3SpringJoint::GetDampingRatio() const +{ + return m_dampingRatio; +} + +void b3SpringJoint::SetDampingRatio(float32 ratio) +{ + m_dampingRatio = ratio; +} + void b3SpringJoint::InitializeConstraints(const b3SolverData* data) { b3Body* m_bodyA = GetBodyA(); @@ -66,7 +116,7 @@ void b3SpringJoint::InitializeConstraints(const b3SolverData* data) b3Vec3 xB = data->positions[m_indexB].x; b3Quat qB = data->positions[m_indexB].q; - // Handle singularity + // Singularity check. m_n = xB + m_rB - xA - m_rA; float32 length = b3Length(m_n); if (length > B3_LINEAR_SLOP) @@ -199,16 +249,16 @@ bool b3SpringJoint::SolvePositionConstraints(const b3SolverData* data) return b3Abs(C) < B3_LINEAR_SLOP; } -void b3SpringJoint::Draw(b3Draw* b3Draw) const +void b3SpringJoint::Draw(b3Draw* draw) const { b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f); b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f); b3Color blue = b3Color(0.0f, 0.0f, 1.0f, 1.0f); - b3Vec3 pA = GetBodyA()->GetWorldPoint(m_localAnchorA); - b3Vec3 pB = GetBodyB()->GetWorldPoint(m_localAnchorB); + b3Vec3 a = GetBodyA()->GetWorldPoint(m_localAnchorA); + b3Vec3 b = GetBodyB()->GetWorldPoint(m_localAnchorB); - b3Draw->DrawPoint(pA, green); - b3Draw->DrawPoint(pB, green); - b3Draw->DrawSegment(pA, pB, blue); + draw->DrawPoint(a, green); + draw->DrawPoint(b, green); + draw->DrawSegment(a, b, blue); } diff --git a/src/bounce/dynamics/shapes/capsule_shape.cpp b/src/bounce/dynamics/shapes/capsule_shape.cpp index 04affc0..b5e6c80 100644 --- a/src/bounce/dynamics/shapes/capsule_shape.cpp +++ b/src/bounce/dynamics/shapes/capsule_shape.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3CapsuleShape::b3CapsuleShape() { diff --git a/src/bounce/dynamics/shapes/hull_shape.cpp b/src/bounce/dynamics/shapes/hull_shape.cpp index 5fbe5a9..9a81633 100644 --- a/src/bounce/dynamics/shapes/hull_shape.cpp +++ b/src/bounce/dynamics/shapes/hull_shape.cpp @@ -16,15 +16,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include b3HullShape::b3HullShape() { m_type = e_hullShape; m_radius = B3_HULL_RADIUS; - m_hull = nullptr; + m_hull = NULL; } b3HullShape::~b3HullShape() diff --git a/src/bounce/dynamics/shapes/mesh_shape.cpp b/src/bounce/dynamics/shapes/mesh_shape.cpp index feb6045..d8730db 100644 --- a/src/bounce/dynamics/shapes/mesh_shape.cpp +++ b/src/bounce/dynamics/shapes/mesh_shape.cpp @@ -16,14 +16,14 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include +#include +#include b3MeshShape::b3MeshShape() { m_type = e_meshShape; m_radius = B3_HULL_RADIUS; - m_mesh = nullptr; + m_mesh = NULL; } b3MeshShape::~b3MeshShape() @@ -161,7 +161,7 @@ bool b3MeshShape::RayCast(b3RayCastOutput* output, const b3RayCastInput& input, callback.hit = false; callback.output.fraction = B3_MAX_FLOAT; - m_mesh->tree.QueryRay(&callback, subInput); + m_mesh->tree.RayCast(&callback, subInput); output->fraction = callback.output.fraction; output->normal = b3Mul(xf.rotation, callback.output.normal); diff --git a/src/bounce/dynamics/shapes/shape.cpp b/src/bounce/dynamics/shapes/shape.cpp index f0bb5b4..e4a7e3d 100644 --- a/src/bounce/dynamics/shapes/shape.cpp +++ b/src/bounce/dynamics/shapes/shape.cpp @@ -16,18 +16,18 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include void b3Shape::SetSensor(bool flag) { @@ -41,11 +41,6 @@ void b3Shape::SetSensor(bool flag) } } -b3Transform b3Shape::GetTransform() const -{ - return m_body->GetTransform(); -} - void b3Shape::DestroyContacts() { b3World* world = m_body->GetWorld(); @@ -195,7 +190,7 @@ void b3Shape::Dump(i32 bodyIndex) const b3Shape* b3Shape::Create(const b3ShapeDef& def) { - b3Shape* shape = nullptr; + b3Shape* shape = NULL; switch (def.shape->GetType()) { case e_sphereShape: diff --git a/src/bounce/dynamics/shapes/sphere_shape.cpp b/src/bounce/dynamics/shapes/sphere_shape.cpp index 1324438..b6d4115 100644 --- a/src/bounce/dynamics/shapes/sphere_shape.cpp +++ b/src/bounce/dynamics/shapes/sphere_shape.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include b3SphereShape::b3SphereShape() { diff --git a/src/bounce/dynamics/world.cpp b/src/bounce/dynamics/world.cpp index 6db8d1d..2e48715 100644 --- a/src/bounce/dynamics/world.cpp +++ b/src/bounce/dynamics/world.cpp @@ -16,15 +16,15 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include extern u32 b3_allocCalls; extern u32 b3_maxAllocCalls; @@ -33,7 +33,7 @@ b3World::b3World() : m_bodyBlocks(sizeof(b3Body)) { b3_allocCalls = 0; b3_maxAllocCalls = 0; - m_debugDraw = nullptr; + m_debugDraw = NULL; memset(&m_profile, 0, sizeof(b3Profile)); m_flags = e_clearForcesFlag; @@ -329,7 +329,7 @@ void b3World::Solve(float32 dt, u32 velocityIterations, u32 positionIterations) } } -struct b3CastRayCallback +struct b3RayCastCallback { float32 Report(const b3RayCastInput& input, i32 proxyId) { @@ -338,7 +338,7 @@ struct b3CastRayCallback b3Shape* shape = (b3Shape*)userData; // Calculate transformation from shape local space to world space. - b3Transform xf = shape->GetTransform(); + b3Transform xf = shape->GetBody()->GetTransform(); b3RayCastOutput output; bool hit = shape->RayCast(&output, input, xf); @@ -364,20 +364,20 @@ struct b3CastRayCallback const b3BroadPhase* broadPhase; }; -void b3World::CastRay(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const +void b3World::RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const { b3RayCastInput input; input.p1 = p1; input.p2 = p2; input.maxFraction = 1.0f; - b3CastRayCallback callback; + b3RayCastCallback callback; callback.listener = listener; callback.broadPhase = &m_contactMan.m_broadPhase; - m_contactMan.m_broadPhase.QueryRay(&callback, input); + m_contactMan.m_broadPhase.RayCast(&callback, input); } -struct b3CastAABBCallback +struct b3QueryAABBCallback { bool Report(i32 proxyID) { @@ -389,9 +389,9 @@ struct b3CastAABBCallback const b3BroadPhase* broadPhase; }; -void b3World::CastAABB(b3QueryListener* listener, const b3AABB3& aabb) const +void b3World::QueryAABB(b3QueryListener* listener, const b3AABB3& aabb) const { - b3CastAABBCallback callback; + b3QueryAABBCallback callback; callback.listener = listener; callback.broadPhase = &m_contactMan.m_broadPhase; m_contactMan.m_broadPhase.QueryAABB(&callback, aabb); diff --git a/src/bounce/quickhull/qh_hull.cpp b/src/bounce/quickhull/qh_hull.cpp index 70f01a5..518abe3 100644 --- a/src/bounce/quickhull/qh_hull.cpp +++ b/src/bounce/quickhull/qh_hull.cpp @@ -16,9 +16,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include +#include +#include +#include float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array& vertices) { @@ -76,31 +76,31 @@ void qhHull::Construct(void* memory, const b3Array& vs) // Euler's formula // V - E + F = 2 - m_freeVertices = nullptr; + m_freeVertices = NULL; qhVertex* vertices = (qhVertex*)memory; for (u32 i = 0; i < V; ++i) { FreeVertex(vertices + i); } - m_freeEdges = nullptr; + m_freeEdges = NULL; qhHalfEdge* edges = (qhHalfEdge*)((u8*)vertices + V * sizeof(qhVertex)); for (u32 i = 0; i < HE; ++i) { FreeEdge(edges + i); } - m_freeFaces = nullptr; + m_freeFaces = NULL; qhFace* faces = (qhFace*)((u8*)edges + HE * sizeof(qhHalfEdge)); for (u32 i = 0; i < F; ++i) { qhFace* f = faces + i; - f->conflictList.head = nullptr; + f->conflictList.head = NULL; f->conflictList.count = 0; FreeFace(f); } - m_faceList.head = nullptr; + m_faceList.head = NULL; m_faceList.count = 0; m_iteration = 0; @@ -295,7 +295,7 @@ bool qhHull::BuildInitialHull(const b3Array& vertices) // Discard internal points since they can't be in the hull. float32 d0 = m_tolerance; - qhFace* f0 = nullptr; + qhFace* f0 = NULL; for (u32 j = 0; j < 4; ++j) { @@ -324,7 +324,7 @@ qhVertex* qhHull::NextVertex() { // Find the point furthest from the current hull. float32 d0 = m_tolerance; - qhVertex* v0 = nullptr; + qhVertex* v0 = NULL; qhFace* f = m_faceList.head; while (f) @@ -479,7 +479,7 @@ qhHalfEdge* qhHull::AddAdjoiningTriangle(qhVertex* eye, qhHalfEdge* horizonEdge) e1->tail = v1; e1->prev = e3; e1->next = e2; - e1->twin = nullptr; + e1->twin = NULL; e1->face = face; e2->tail = v2; @@ -492,10 +492,10 @@ qhHalfEdge* qhHull::AddAdjoiningTriangle(qhVertex* eye, qhHalfEdge* horizonEdge) e3->tail = v3; e3->prev = e2; e3->next = e1; - e3->twin = nullptr; + e3->twin = NULL; e3->face = face; - horizonEdge->twin = nullptr; + horizonEdge->twin = NULL; face->edge = e1; face->center = (v1->position + v2->position + v3->position) / 3.0f; @@ -511,8 +511,8 @@ void qhHull::AddNewFaces(b3Array& newFaces, qhVertex* eye, const b3Arra { newFaces.Reserve(horizon.Count()); - qhHalfEdge* beginEdge = nullptr; - qhHalfEdge* prevEdge = nullptr; + qhHalfEdge* beginEdge = NULL; + qhHalfEdge* prevEdge = NULL; { qhHalfEdge* edge = horizon[0]; @@ -571,7 +571,7 @@ void qhHull::AddNewFaces(b3Array& newFaces, qhVertex* eye, const b3Arra // Use tolerance and discard internal points. float32 max = m_tolerance; - qhFace* iMax = nullptr; + qhFace* iMax = NULL; for (u32 i = 0; i < newFaces.Count(); ++i) { @@ -587,7 +587,7 @@ void qhHull::AddNewFaces(b3Array& newFaces, qhVertex* eye, const b3Arra if (iMax) { qhVertex* v0 = v; - v->conflictFace = nullptr; + v->conflictFace = NULL; v = f->conflictList.Remove(v); iMax->conflictList.PushFront(v0); v0->conflictFace = iMax; @@ -595,7 +595,7 @@ void qhHull::AddNewFaces(b3Array& newFaces, qhVertex* eye, const b3Arra else { qhVertex* v0 = v; - v->conflictFace = nullptr; + v->conflictFace = NULL; v = f->conflictList.Remove(v); FreeVertex(v0); } @@ -739,7 +739,7 @@ bool qhHull::IsConsistent() const return true; } -void qhHull::Draw(b3Draw* b3Draw) const +void qhHull::Draw(b3Draw* draw) const { qhFace* face = m_faceList.head; while (face) @@ -750,12 +750,12 @@ void qhHull::Draw(b3Draw* b3Draw) const qhVertex* v = face->conflictList.head; while (v) { - b3Draw->DrawPoint(v->position, b3Color(1.0f, 1.0f, 0.0f)); - b3Draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f)); + draw->DrawPoint(v->position, b3Color(1.0f, 1.0f, 0.0f)); + draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f)); v = v->next; } - b3Draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f)); + draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f)); b3StackArray polygon; qhHalfEdge* edge = face->edge; @@ -765,7 +765,7 @@ void qhHull::Draw(b3Draw* b3Draw) const edge = edge->next; } while (edge != face->edge); - b3Draw->DrawSolidPolygon(polygon.Elements(), polygon.Count(), b3Color(0.0f, 0.0f, 1.0f, 1.0f)); + draw->DrawSolidPolygon(polygon.Elements(), polygon.Count(), b3Color(0.0f, 0.0f, 1.0f, 1.0f)); face = face->next; } diff --git a/src/testbed/framework/debug_draw.cpp b/src/testbed/framework/debug_draw.cpp index c19f912..96ef492 100644 --- a/src/testbed/framework/debug_draw.cpp +++ b/src/testbed/framework/debug_draw.cpp @@ -16,10 +16,14 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include +#include + +#include +#include +#include +#include + +#include extern Camera g_camera; @@ -594,7 +598,7 @@ struct DrawShapes while (s) { DrawShape(s, xf); - s = s->m_next; + s = s->GetNext(); } glDisable(GL_COLOR_MATERIAL); @@ -798,4 +802,4 @@ void DebugDraw::Submit() m_triangles->Submit(); m_lines->Submit(); m_points->Submit(); -} \ No newline at end of file +} diff --git a/src/testbed/framework/main.cpp b/src/testbed/framework/main.cpp index b9b60e1..36576de 100644 --- a/src/testbed/framework/main.cpp +++ b/src/testbed/framework/main.cpp @@ -16,11 +16,11 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include GLFWwindow* g_window; Settings g_settings; @@ -29,7 +29,7 @@ Camera g_camera; DebugDraw* g_debugDraw; bool g_leftDown; bool g_rightDown; -bool g_altDown; +bool g_shiftDown; b3Vec2 g_ps0; void WindowSize(int w, int h) @@ -51,7 +51,7 @@ void MouseMove(GLFWwindow* w, double x, double y) float32 nx = b3Clamp(dp.x, -1.0f, 1.0f); float32 ny = b3Clamp(dp.y, -1.0f, 1.0f); - if (g_altDown) + if (g_shiftDown) { if (g_leftDown) { @@ -83,7 +83,7 @@ void MouseMove(GLFWwindow* w, double x, double y) void MouseWheel(GLFWwindow* w, double dx, double dy) { float32 n = b3Clamp(float32(dy), -1.0f, 1.0f); - if (g_altDown) + if (g_shiftDown) { g_camera.m_zoom += 0.5f * -n; } @@ -106,7 +106,7 @@ void MouseButton(GLFWwindow* w, int button, int action, int mods) { g_leftDown = true; - if (g_altDown == false) + if (g_shiftDown == false) { g_test->MouseLeftDown(pw); } @@ -125,7 +125,7 @@ void MouseButton(GLFWwindow* w, int button, int action, int mods) { g_leftDown = false; - if (g_altDown == false) + if (g_shiftDown == false) { g_test->MouseLeftUp(pw); } @@ -150,13 +150,13 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods) { case GLFW_PRESS: { - if (button == GLFW_KEY_LEFT_ALT) + if (button == GLFW_KEY_LEFT_SHIFT) { - g_altDown = true; + g_shiftDown = true; g_test->KeyDown(button); } - if (g_altDown) + if (g_shiftDown) { if (button == GLFW_KEY_DOWN) { @@ -167,11 +167,6 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods) { g_camera.m_zoom -= 0.05f; } - - if (button == GLFW_KEY_R) - { - g_settings.lastTestID = -1; - } } else { @@ -182,12 +177,12 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods) } case GLFW_RELEASE: { - if (button == GLFW_KEY_LEFT_ALT) + if (button == GLFW_KEY_LEFT_SHIFT) { - g_altDown = false; + g_shiftDown = false; } - if (g_altDown == false) + if (g_shiftDown == false) { g_test->KeyUp(button); } @@ -247,7 +242,7 @@ void Interface() } ImVec2 buttonSize = ImVec2(-1, 0); - if (ImGui::Button("Restart (R)", buttonSize)) + if (ImGui::Button("Restart", buttonSize)) { g_settings.lastTestID = -1; } @@ -345,13 +340,6 @@ void Run() ImGui_ImplGlfwGL3_NewFrame(); - Step(); - - if (g_settings.drawShapes) - { - g_debugDraw->Submit(g_test->m_world); - } - if (g_settings.drawGrid) { u32 n = 20; @@ -397,9 +385,16 @@ void Run() g_debugDraw->DrawSegment(p1, p2, color2); } } - + + Step(); + g_debugDraw->Submit(); + if (g_settings.drawShapes) + { + g_debugDraw->Submit(g_test->m_world); + } + Interface(); ImGui::Render(); @@ -411,53 +406,65 @@ void Run() } int main(int argc, char** args) -{ - // Create g_window +{ if (glfwInit() == 0) { fprintf(stderr, "Failed to initialize GLFW\n"); return -1; } - + + // Create g_window extern b3Version b3_version; char title[256]; - sprintf_s(title, "Bounce Testbed Version %d.%d.%d", b3_version.major, b3_version.minor, b3_version.revision); - + sprintf(title, "Bounce Testbed Version %d.%d.%d", b3_version.major, b3_version.minor, b3_version.revision); + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + g_window = glfwCreateWindow(1024, 768, title, NULL, NULL); - - g_leftDown = false; - g_rightDown = false; - g_altDown = false; - g_ps0.SetZero(); - - glfwMakeContextCurrent(g_window); - glfwSwapInterval(1); + if (g_window == NULL) + { + fprintf(stderr, "Failed to opengl GLFW window\n"); + glfwTerminate(); + return -1; + } + + glfwMakeContextCurrent(g_window); glfwSetCursorPosCallback(g_window, MouseMove); glfwSetScrollCallback(g_window, MouseWheel); glfwSetMouseButtonCallback(g_window, MouseButton); glfwSetKeyCallback(g_window, KeyButton); glfwSetCharCallback(g_window, Char); - + glfwSwapInterval(1); if (gladLoadGL() == 0) { fprintf(stderr, "Error: %d\n", glad_glGetError()); + glfwTerminate(); exit(EXIT_FAILURE); } + printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); + + g_leftDown = false; + g_rightDown = false; + g_shiftDown = false; + g_ps0.SetZero(); + // Create UI CreateInterface(); // Create renderer g_debugDraw = new DebugDraw(); - // Run the g_tests - g_test = nullptr; + // Run the testbed + g_test = NULL; Run(); + // Destroy the last test if (g_test) { delete g_test; - g_test = nullptr; + g_test = NULL; } // Destroy renderer diff --git a/src/testbed/framework/test.cpp b/src/testbed/framework/test.cpp index df5b477..96a3547 100644 --- a/src/testbed/framework/test.cpp +++ b/src/testbed/framework/test.cpp @@ -16,7 +16,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#include extern u32 b3_allocCalls, b3_maxAllocCalls; extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; @@ -49,9 +49,8 @@ Test::Test() g_camera.m_center.SetZero(); g_settings.drawGrid = false; - m_rayHit.m_shape = nullptr; - m_mouseJoint = nullptr; - m_groundBody = nullptr; + m_rayHit.m_shape = NULL; + m_mouseJoint = NULL; { b3Transform xf; @@ -363,20 +362,23 @@ void Test::MouseMove(const Ray3& pw) float32 w1 = 1.0f - hitFraction; float32 w2 = hitFraction; - b3Vec3 worldPointA = w1 * pw.Start() + w2 * pw.End(); - m_mouseJoint->SetWorldAnchorA(worldPointA); + b3Vec3 target = w1 * pw.Start() + w2 * pw.End(); + m_mouseJoint->SetTarget(target); } } void Test::MouseLeftDown(const Ray3& pw) { // Clear the current hit - m_rayHit.m_shape = nullptr; + m_rayHit.m_shape = NULL; if (m_mouseJoint) { + b3Body* groundBody = m_mouseJoint->GetBodyA(); + m_world.DestroyJoint(m_mouseJoint); - m_mouseJoint = nullptr; - m_world.DestroyBody(m_groundBody); + m_mouseJoint = NULL; + + m_world.DestroyBody(groundBody); } b3Vec3 p1 = pw.Start(); @@ -384,7 +386,7 @@ void Test::MouseLeftDown(const Ray3& pw) // Perform the ray cast RayCastListener listener; - m_world.CastRay(&listener, p1, p2); + m_world.RayCast(&listener, p1, p2); int hitId = listener.FindClosestHit(); @@ -400,40 +402,28 @@ void Test::MouseLeftDown(const Ray3& pw) void Test::MouseLeftUp(const Ray3& pw) { - m_rayHit.m_shape = nullptr; + m_rayHit.m_shape = NULL; if (m_mouseJoint) { + b3Body* groundBody = m_mouseJoint->GetBodyA(); + m_world.DestroyJoint(m_mouseJoint); - m_mouseJoint = nullptr; - m_world.DestroyBody(m_groundBody); + m_mouseJoint = NULL; + + m_world.DestroyBody(groundBody); } } void Test::RayHit() { b3BodyDef bdef; - m_groundBody = m_world.CreateBody(bdef); - - b3Shape* shape = m_rayHit.m_shape; - - b3Body* bodyA = m_groundBody; - b3Body* bodyB = shape->GetBody(); - - // Ray hit point in world space - b3Vec3 worldPointA = m_rayHit.m_point; - - // xf from world space to the local space of the shape - b3Transform xf = shape->GetTransform(); - - // Ray hit point in world space - // lp = xf^-1 * wp - b3Vec3 localPointA = b3MulT(xf, worldPointA); - + b3Body* bodyA = m_world.CreateBody(bdef); + b3Body* bodyB = m_rayHit.m_shape->GetBody(); + b3MouseJointDef def; def.bodyA = bodyA; def.bodyB = bodyB; - def.worldAnchorA = worldPointA; - def.localAnchorB = localPointA; + def.target = m_rayHit.m_point; def.maxForce = 2000.0f * bodyB->GetMass(); m_mouseJoint = (b3MouseJoint*)m_world.CreateJoint(def); diff --git a/src/testbed/framework/test_entries.cpp b/src/testbed/framework/test_entries.cpp index 2dc78ef..a4f174a 100644 --- a/src/testbed/framework/test_entries.cpp +++ b/src/testbed/framework/test_entries.cpp @@ -16,36 +16,36 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include TestEntry g_tests[e_testCount] = {