diff --git a/RecastDemo/Include/AppData.h b/RecastDemo/Include/AppData.h index 65a1bd07..5744ab9d 100644 --- a/RecastDemo/Include/AppData.h +++ b/RecastDemo/Include/AppData.h @@ -7,12 +7,6 @@ #include "Sample.h" #include "TestCase.h" -#ifdef __APPLE__ -# include -#else -# include -#endif - #include #include #include @@ -87,72 +81,9 @@ struct AppData float markerPosition[3] = {0, 0, 0}; bool markerPositionSet = false; - ~AppData() - { - delete sample; - sample = nullptr; - delete inputGeometry; - inputGeometry = nullptr; - } - - void resetCamera() - { - // Reset camera and fog to match the mesh bounds. - if (inputGeometry) - { - const float* boundsMin = inputGeometry->getNavMeshBoundsMin(); - const float* boundsMax = inputGeometry->getNavMeshBoundsMax(); - - camr = sqrtf( - rcSqr(boundsMax[0] - boundsMin[0]) + rcSqr(boundsMax[1] - boundsMin[1]) + - rcSqr(boundsMax[2] - boundsMin[2])) / - 2; - cameraPos[0] = (boundsMax[0] + boundsMin[0]) / 2 + camr; - cameraPos[1] = (boundsMax[1] + boundsMin[1]) / 2 + camr; - cameraPos[2] = (boundsMax[2] + boundsMin[2]) / 2 + camr; - camr *= 3; - } - cameraEulers[0] = 45; - cameraEulers[1] = -45; - glFogf(GL_FOG_START, camr * 0.1f); - glFogf(GL_FOG_END, camr * 1.25f); - } - - void UpdateWindowSize() - { - SDL_GetWindowSize(window, &width, &height); - SDL_GL_GetDrawableSize(window, &drawableWidth, &drawableHeight); - - glViewport(0, 0, drawableWidth, drawableHeight); - glGetIntegerv(GL_VIEWPORT, viewport); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(50.0f, static_cast(width) / static_cast(height), 1.0f, camr); - glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix); - } - - void UpdateUIScale() - { - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2(static_cast(width), static_cast(height)); - io.DisplayFramebufferScale = ImVec2( - static_cast(drawableWidth) / static_cast(width), - static_cast(drawableHeight) / static_cast(height)); - } - - void WorldToScreen(float x, float y, float z, float* screenX, float* screenY) - { - GLdouble modelviewMatrix[16]; - glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix); - - GLdouble winX, winY, winZ; - gluProject(x, y, z, modelviewMatrix, projectionMatrix, viewport, &winX, &winY, &winZ); - - float dpiScaleX = float(drawableWidth) / float(width); - float dpiScaleY = float(drawableHeight) / float(height); - - *screenX = winX / dpiScaleX; - *screenY = height - (winY / dpiScaleY); - } + ~AppData(); + void resetCamera(); + void UpdateWindowSize(); + void UpdateUIScale(); + void WorldToScreen(float x, float y, float z, float* screenX, float* screenY); }; diff --git a/RecastDemo/Source/AppData.cpp b/RecastDemo/Source/AppData.cpp new file mode 100644 index 00000000..bbd98983 --- /dev/null +++ b/RecastDemo/Source/AppData.cpp @@ -0,0 +1,76 @@ +#include "AppData.h" + +#ifdef __APPLE__ +# include +#else +# include +#endif + +AppData::~AppData() +{ + delete sample; + sample = nullptr; + delete inputGeometry; + inputGeometry = nullptr; +} + +void AppData::resetCamera() +{ + // Reset camera and fog to match the mesh bounds. + if (inputGeometry) + { + const float* boundsMin = inputGeometry->getNavMeshBoundsMin(); + const float* boundsMax = inputGeometry->getNavMeshBoundsMax(); + + camr = sqrtf( + rcSqr(boundsMax[0] - boundsMin[0]) + rcSqr(boundsMax[1] - boundsMin[1]) + + rcSqr(boundsMax[2] - boundsMin[2])) / + 2; + cameraPos[0] = (boundsMax[0] + boundsMin[0]) / 2 + camr; + cameraPos[1] = (boundsMax[1] + boundsMin[1]) / 2 + camr; + cameraPos[2] = (boundsMax[2] + boundsMin[2]) / 2 + camr; + camr *= 3; + } + cameraEulers[0] = 45; + cameraEulers[1] = -45; + glFogf(GL_FOG_START, camr * 0.1f); + glFogf(GL_FOG_END, camr * 1.25f); +} + +void AppData::UpdateWindowSize() +{ + SDL_GetWindowSize(window, &width, &height); + SDL_GL_GetDrawableSize(window, &drawableWidth, &drawableHeight); + + glViewport(0, 0, drawableWidth, drawableHeight); + glGetIntegerv(GL_VIEWPORT, viewport); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(50.0f, static_cast(width) / static_cast(height), 1.0f, camr); + glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix); +} + +void AppData::UpdateUIScale() +{ + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2(static_cast(width), static_cast(height)); + io.DisplayFramebufferScale = ImVec2( + static_cast(drawableWidth) / static_cast(width), + static_cast(drawableHeight) / static_cast(height)); +} + +void AppData::WorldToScreen(float x, float y, float z, float* screenX, float* screenY) +{ + GLdouble modelviewMatrix[16]; + glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix); + + GLdouble winX, winY, winZ; + gluProject(x, y, z, modelviewMatrix, projectionMatrix, viewport, &winX, &winY, &winZ); + + float dpiScaleX = float(drawableWidth) / float(width); + float dpiScaleY = float(drawableHeight) / float(height); + + *screenX = winX / dpiScaleX; + *screenY = height - (winY / dpiScaleY); +} diff --git a/RecastDemo/Source/Sample_TempObstacles.cpp b/RecastDemo/Source/Sample_TempObstacles.cpp index 969f4294..b75851bd 100644 --- a/RecastDemo/Source/Sample_TempObstacles.cpp +++ b/RecastDemo/Source/Sample_TempObstacles.cpp @@ -21,11 +21,6 @@ #include #include #include -#ifdef __APPLE__ -# include -#else -# include -#endif #include "PartitionedMesh.h" #include "DetourCommon.h" #include "DetourDebugDraw.h" diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index f96692da..314fafc7 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -24,11 +24,6 @@ #include #include #include -#ifdef __APPLE__ -# include -#else -# include -#endif #include "PartitionedMesh.h" #include "DetourDebugDraw.h" #include "DetourNavMesh.h" diff --git a/RecastDemo/Source/TestCase.cpp b/RecastDemo/Source/TestCase.cpp index e1e68faa..c9579cd4 100644 --- a/RecastDemo/Source/TestCase.cpp +++ b/RecastDemo/Source/TestCase.cpp @@ -29,11 +29,6 @@ #include #include #include -#ifdef __APPLE__ -# include -#else -# include -#endif #include "PerfTimer.h" #include diff --git a/RecastDemo/Source/Tool_Crowd.cpp b/RecastDemo/Source/Tool_Crowd.cpp index 0fa9d794..a15b32a9 100644 --- a/RecastDemo/Source/Tool_Crowd.cpp +++ b/RecastDemo/Source/Tool_Crowd.cpp @@ -21,16 +21,10 @@ #include "SDL.h" #include "SDL_opengl.h" +#include #include #include #include -#ifdef __APPLE__ -# include -#else -# include - -# include -#endif #include "DetourCommon.h" #include "DetourCrowd.h" #include "DetourDebugDraw.h" diff --git a/RecastDemo/Source/Tool_NavMeshTester.cpp b/RecastDemo/Source/Tool_NavMeshTester.cpp index ce694f72..b8064ef5 100644 --- a/RecastDemo/Source/Tool_NavMeshTester.cpp +++ b/RecastDemo/Source/Tool_NavMeshTester.cpp @@ -29,11 +29,6 @@ #include #include -#ifdef __APPLE__ -# include -#else -# include -#endif // Uncomment this to dump all the requests in stdout. #define DUMP_REQS diff --git a/RecastDemo/Source/Tool_OffMeshConnection.cpp b/RecastDemo/Source/Tool_OffMeshConnection.cpp index 9bdfe2d4..0bacc519 100644 --- a/RecastDemo/Source/Tool_OffMeshConnection.cpp +++ b/RecastDemo/Source/Tool_OffMeshConnection.cpp @@ -21,16 +21,9 @@ #include "DetourDebugDraw.h" #include "InputGeom.h" #include "Recast.h" -#include "SDL_opengl.h" #include "Sample.h" #include "imguiHelpers.h" -#ifdef __APPLE__ -# include -#else -# include -#endif - #include #include