From d534b4dc1483f5923a3b08de75495f75fc23bd5c Mon Sep 17 00:00:00 2001 From: Graham Pentheny Date: Sat, 12 Jul 2025 15:02:54 -0400 Subject: [PATCH] WIP DearImGui conversion --- RecastDemo/Include/CrowdTool.h | 5 +- RecastDemo/Include/InputGeom.h | 4 +- RecastDemo/Include/Sample.h | 2 +- RecastDemo/Include/imguiHelpers.h | 15 ++ RecastDemo/Source/ConvexVolumeTool.cpp | 70 +++--- RecastDemo/Source/CrowdTool.cpp | 239 ++++++++++---------- RecastDemo/Source/InputGeom.cpp | 4 +- RecastDemo/Source/NavMeshPruneTool.cpp | 25 +- RecastDemo/Source/NavMeshTesterTool.cpp | 120 +++++----- RecastDemo/Source/OffMeshConnectionTool.cpp | 3 +- RecastDemo/Source/Sample.cpp | 96 ++++---- RecastDemo/Source/Sample_SoloMesh.cpp | 64 +++--- RecastDemo/Source/Sample_TempObstacles.cpp | 33 ++- RecastDemo/Source/Sample_TileMesh.cpp | 3 +- RecastDemo/Source/TestCase.cpp | 3 +- RecastDemo/Source/ValueHistory.cpp | 2 +- RecastDemo/Source/main.cpp | 145 ++---------- 17 files changed, 366 insertions(+), 467 deletions(-) create mode 100644 RecastDemo/Include/imguiHelpers.h diff --git a/RecastDemo/Include/CrowdTool.h b/RecastDemo/Include/CrowdTool.h index 7e08cb85..60c3cdbf 100644 --- a/RecastDemo/Include/CrowdTool.h +++ b/RecastDemo/Include/CrowdTool.h @@ -28,7 +28,6 @@ struct CrowdToolParams { - bool m_expandSelectedDebugDraw = true; bool m_showCorners = false; bool m_showCollisionSegments = false; bool m_showPath = false; @@ -36,19 +35,17 @@ struct CrowdToolParams bool m_showOpt = false; bool m_showNeis = false; - bool m_expandDebugDraw = false; bool m_showLabels = false; bool m_showGrid = false; bool m_showNodes = false; bool m_showPerfGraph = false; bool m_showDetailAll = false; - bool m_expandOptions = true; bool m_anticipateTurns = true; bool m_optimizeVis = true; bool m_optimizeTopo = true; bool m_obstacleAvoidance = true; - float m_obstacleAvoidanceType = 3.0f; + int m_obstacleAvoidanceType = 1; bool m_separation = false; float m_separationWeight = 2.0f; }; diff --git a/RecastDemo/Include/InputGeom.h b/RecastDemo/Include/InputGeom.h index 3c7b9015..02dc4f04 100644 --- a/RecastDemo/Include/InputGeom.h +++ b/RecastDemo/Include/InputGeom.h @@ -21,6 +21,8 @@ #include "ChunkyTriMesh.h" #include "MeshLoaderObj.h" +#include + static constexpr int MAX_CONVEXVOL_PTS = 12; struct ConvexVolume { @@ -54,7 +56,7 @@ struct BuildSettings float edgeMaxLen = 0; /// Edge max error in voxels float edgeMaxError = 0; - float vertsPerPoly = 0; + int vertsPerPoly = 0; /// Detail sample distance in voxels float detailSampleDist = 0; /// Detail sample max error in voxel heights. diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 3cfe107a..61f2c809 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -125,7 +125,7 @@ protected: float regionMergeSize; float edgeMaxLen; float edgeMaxError; - float vertsPerPoly; + int vertsPerPoly; float detailSampleDist; float detailSampleMaxError; int partitionType; diff --git a/RecastDemo/Include/imguiHelpers.h b/RecastDemo/Include/imguiHelpers.h new file mode 100644 index 00000000..f547dd04 --- /dev/null +++ b/RecastDemo/Include/imguiHelpers.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +inline void DrawScreenspaceText(float x, float y, ImU32 color, const char* text, bool centered = false) +{ + if (centered) + { + const ImVec2 textSize = ImGui::CalcTextSize(text); + x -= textSize.x * 0.5f; + } + + ImGui::GetForegroundDrawList()->AddText({x, y}, color, text); +} + diff --git a/RecastDemo/Source/ConvexVolumeTool.cpp b/RecastDemo/Source/ConvexVolumeTool.cpp index 5f2b72fe..46842db2 100644 --- a/RecastDemo/Source/ConvexVolumeTool.cpp +++ b/RecastDemo/Source/ConvexVolumeTool.cpp @@ -21,7 +21,9 @@ #include "InputGeom.h" #include "Recast.h" #include "Sample.h" -#include "imgui.h" +#include "imguiHelpers.h" + +#include #include @@ -116,49 +118,46 @@ bool pointInPoly(int nvert, const float* verts, const float* p) void ConvexVolumeTool::handleMenu() { -#if 0 - imguiSlider("Shape Height", &boxHeight, 0.1f, 20.0f, 0.1f); - imguiSlider("Shape Descent", &boxDescent, 0.1f, 20.0f, 0.1f); - imguiSlider("Poly Offset", &polyOffset, 0.0f, 10.0f, 0.1f); + ImGui::SliderFloat("##Shape Height", &boxHeight, 0.1f, 20.0f, "Shape Height = %f"); + ImGui::SliderFloat("##Shape Descent", &boxDescent, 0.1f, 20.0f, "Shape Descent = %f"); + ImGui::SliderFloat("##Poly Offset", &polyOffset, 0.0f, 10.0f, "Poly Offset = %f"); - imguiSeparator(); + ImGui::Text("Area Type"); - imguiLabel("Area Type"); - imguiIndent(); - if (imguiCheck("Ground", areaType == SAMPLE_POLYAREA_GROUND)) + ImGui::Indent(); + if (ImGui::RadioButton("Ground", areaType == SAMPLE_POLYAREA_GROUND)) { areaType = SAMPLE_POLYAREA_GROUND; } - if (imguiCheck("Water", areaType == SAMPLE_POLYAREA_WATER)) + if (ImGui::RadioButton("Water", areaType == SAMPLE_POLYAREA_WATER)) { areaType = SAMPLE_POLYAREA_WATER; } - if (imguiCheck("Road", areaType == SAMPLE_POLYAREA_ROAD)) + if (ImGui::RadioButton("Road", areaType == SAMPLE_POLYAREA_ROAD)) { areaType = SAMPLE_POLYAREA_ROAD; } - if (imguiCheck("Door", areaType == SAMPLE_POLYAREA_DOOR)) + if (ImGui::RadioButton("Door", areaType == SAMPLE_POLYAREA_DOOR)) { areaType = SAMPLE_POLYAREA_DOOR; } - if (imguiCheck("Grass", areaType == SAMPLE_POLYAREA_GRASS)) + if (ImGui::RadioButton("Grass", areaType == SAMPLE_POLYAREA_GRASS)) { areaType = SAMPLE_POLYAREA_GRASS; } - if (imguiCheck("Jump", areaType == SAMPLE_POLYAREA_JUMP)) + if (ImGui::RadioButton("Jump", areaType == SAMPLE_POLYAREA_JUMP)) { areaType = SAMPLE_POLYAREA_JUMP; } - imguiUnindent(); + ImGui::Unindent(); - imguiSeparator(); + ImGui::Separator(); - if (imguiButton("Clear Shape")) + if (ImGui::Button("Clear Shape")) { numPoints = 0; numHull = 0; } -#endif } void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shift) @@ -296,32 +295,27 @@ void ConvexVolumeTool::handleRender() void ConvexVolumeTool::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* view) { -#if 0 // Tool help const int h = view[3]; if (!numPoints) { - imguiDrawText( - 280, - h - 40, - IMGUI_ALIGN_LEFT, - "LMB: Create new shape. SHIFT+LMB: Delete existing shape (click inside a shape).", - imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText( + 280.0f, + static_cast(h) - 40.0f, + IM_COL32(255, 255, 255, 192), + "LMB: Create new shape. SHIFT+LMB: Delete existing shape (click inside a shape)."); } else { - imguiDrawText( - 280, - h - 40, - IMGUI_ALIGN_LEFT, - "Click LMB to add new points. Click on the red point to finish the shape.", - imguiRGBA(255, 255, 255, 192)); - imguiDrawText( - 280, - h - 60, - IMGUI_ALIGN_LEFT, - "The shape will be convex hull of all added points.", - imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText( + 280.0f, + static_cast(h) - 40.0f, + IM_COL32(255, 255, 255, 192), + "Click LMB to add new points. Click on the red point to finish the shape."); + DrawScreenspaceText( + 280.0f, + static_cast(h) - 60.0f, + IM_COL32(255, 255, 255, 192), + "The shape will be convex hull of all added points."); } -#endif } diff --git a/RecastDemo/Source/CrowdTool.cpp b/RecastDemo/Source/CrowdTool.cpp index cd401230..72d2c29d 100644 --- a/RecastDemo/Source/CrowdTool.cpp +++ b/RecastDemo/Source/CrowdTool.cpp @@ -37,7 +37,7 @@ #include "InputGeom.h" #include "Sample.h" #include "SampleInterfaces.h" -#include "imgui.h" +#include "imguiHelpers.h" #ifdef WIN32 # define snprintf _snprintf @@ -503,12 +503,9 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view) GLdouble x, y, z; // Draw start and end point labels - if (m_targetRef && - gluProject((GLdouble)m_targetPos[0], (GLdouble)m_targetPos[1], (GLdouble)m_targetPos[2], model, proj, view, &x, &y, &z)) + if (m_targetRef && gluProject(m_targetPos[0], m_targetPos[1], m_targetPos[2], model, proj, view, &x, &y, &z)) { -#if 0 - imguiDrawText((int)x, (int)(y + 25), IMGUI_ALIGN_CENTER, "TARGET", imguiRGBA(0, 0, 0, 220)); -#endif + DrawScreenspaceText(static_cast(x), static_cast(y), IM_COL32(0, 0, 0, 220), "TARGET", true); } char label[32]; @@ -542,9 +539,7 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view) { const float heuristic = node->total; // - node->cost; snprintf(label, 32, "%.2f", heuristic); -#if 0 - imguiDrawText((int)x, (int)y + 15, IMGUI_ALIGN_CENTER, label, imguiRGBA(0, 0, 0, 220)); -#endif + DrawScreenspaceText(static_cast(x), static_cast(y) + 15, IM_COL32(0, 0, 0, 220), label, true); } } } @@ -560,15 +555,16 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view) for (int i = 0; i < crowd->getAgentCount(); ++i) { const dtCrowdAgent* ag = crowd->getAgent(i); - if (!ag->active) { continue; } + if (!ag->active) + { + continue; + } const float* pos = ag->npos; const float h = ag->params.height; - if (gluProject((GLdouble)pos[0], (GLdouble)pos[1] + h, (GLdouble)pos[2], model, proj, view, &x, &y, &z)) + if (gluProject(pos[0], static_cast(pos[1]) + h, pos[2], model, proj, view, &x, &y, &z)) { snprintf(label, 32, "%d", i); -#if 0 - imguiDrawText((int)x, (int)y + 15, IMGUI_ALIGN_CENTER, label, imguiRGBA(0, 0, 0, 220)); -#endif + DrawScreenspaceText(static_cast(x), static_cast(y) + 15, IM_COL32(0, 0, 0, 220), label, true); } } } @@ -589,11 +585,15 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view) for (int j = 0; j < ag->nneis; ++j) { const dtCrowdAgent* nei = crowd->getAgent(ag->neis[j].idx); - if (!nei->active) { continue; } + if (!nei->active) + { + continue; + } - if (gluProject((GLdouble)nei->npos[0], - (GLdouble)nei->npos[1] + radius, - (GLdouble)nei->npos[2], + if (gluProject( + nei->npos[0], + static_cast(nei->npos[1]) + radius, + nei->npos[2], model, proj, view, @@ -602,9 +602,7 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view) &z)) { snprintf(label, 32, "%.3f", ag->neis[j].dist); -#if 0 - imguiDrawText((int)x, (int)y + 15, IMGUI_ALIGN_CENTER, label, imguiRGBA(255, 255, 255, 220)); -#endif + DrawScreenspaceText(static_cast(x), static_cast(y) + 15, IM_COL32(255, 255, 255, 220), label, true); } } } @@ -651,7 +649,7 @@ void CrowdToolState::addAgent(const float* p) if (m_toolParams.m_optimizeTopo) { ap.updateFlags |= DT_CROWD_OPTIMIZE_TOPO; } if (m_toolParams.m_obstacleAvoidance) { ap.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE; } if (m_toolParams.m_separation) { ap.updateFlags |= DT_CROWD_SEPARATION; } - ap.obstacleAvoidanceType = (unsigned char)m_toolParams.m_obstacleAvoidanceType; + ap.obstacleAvoidanceType = static_cast(m_toolParams.m_obstacleAvoidanceType); ap.separationWeight = m_toolParams.m_separationWeight; int idx = crowd->addAgent(p, &ap); @@ -785,7 +783,7 @@ void CrowdToolState::updateAgentParams() if (m_toolParams.m_obstacleAvoidance) { updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE; } if (m_toolParams.m_separation) { updateFlags |= DT_CROWD_SEPARATION; } - obstacleAvoidanceType = (unsigned char)m_toolParams.m_obstacleAvoidanceType; + obstacleAvoidanceType = static_cast(m_toolParams.m_obstacleAvoidanceType); dtCrowdAgentParams params; @@ -850,99 +848,92 @@ void CrowdTool::reset() {} void CrowdTool::handleMenu() { -#if 0 - if (!m_state) { return; } + if (!m_state) + { + return; + } + + if (ImGui::RadioButton("Create Agents", m_mode == ToolMode::CREATE)) + { + m_mode = ToolMode::CREATE; + } + if (ImGui::RadioButton("Move Target", m_mode == ToolMode::MOVE_TARGET)) + { + m_mode = ToolMode::MOVE_TARGET; + } + if (ImGui::RadioButton("Select Agent", m_mode == ToolMode::SELECT)) + { + m_mode = ToolMode::SELECT; + } + if (ImGui::RadioButton("Toggle Polys", m_mode == ToolMode::TOGGLE_POLYS)) + { + m_mode = ToolMode::TOGGLE_POLYS; + } + + ImGui::Separator(); + CrowdToolParams* params = m_state->getToolParams(); - if (imguiCheck("Create Agents", m_mode == ToolMode::CREATE)) { m_mode = ToolMode::CREATE; } - if (imguiCheck("Move Target", m_mode == ToolMode::MOVE_TARGET)) { m_mode = ToolMode::MOVE_TARGET; } - if (imguiCheck("Select Agent", m_mode == ToolMode::SELECT)) { m_mode = ToolMode::SELECT; } - if (imguiCheck("Toggle Polys", m_mode == ToolMode::TOGGLE_POLYS)) { m_mode = ToolMode::TOGGLE_POLYS; } - - imguiSeparatorLine(); - - if (imguiCollapse("Options", 0, params->m_expandOptions)) { params->m_expandOptions = !params->m_expandOptions; } - - if (params->m_expandOptions) + if (ImGui::TreeNode("Options")) { - imguiIndent(); - if (imguiCheck("Optimize Visibility", params->m_optimizeVis)) - { - params->m_optimizeVis = !params->m_optimizeVis; - m_state->updateAgentParams(); - } - if (imguiCheck("Optimize Topology", params->m_optimizeTopo)) - { - params->m_optimizeTopo = !params->m_optimizeTopo; - m_state->updateAgentParams(); - } - if (imguiCheck("Anticipate Turns", params->m_anticipateTurns)) - { - params->m_anticipateTurns = !params->m_anticipateTurns; - m_state->updateAgentParams(); - } - if (imguiCheck("Obstacle Avoidance", params->m_obstacleAvoidance)) - { - params->m_obstacleAvoidance = !params->m_obstacleAvoidance; - m_state->updateAgentParams(); - } - if (imguiSlider("Avoidance Quality", ¶ms->m_obstacleAvoidanceType, 0.0f, 3.0f, 1.0f)) - { - m_state->updateAgentParams(); - } - if (imguiCheck("Separation", params->m_separation)) - { - params->m_separation = !params->m_separation; - m_state->updateAgentParams(); - } - if (imguiSlider("Separation Weight", ¶ms->m_separationWeight, 0.0f, 20.0f, 0.01f)) { m_state->updateAgentParams(); } + bool paramsChanged = false; + paramsChanged |= ImGui::Checkbox("Optimize Visibility", ¶ms->m_optimizeVis); + paramsChanged |= ImGui::Checkbox("Optimize Topology", ¶ms->m_optimizeTopo); + paramsChanged |= ImGui::Checkbox("Anticipate Turns", ¶ms->m_anticipateTurns); + paramsChanged |= ImGui::Checkbox("Obstacle Avoidance", ¶ms->m_obstacleAvoidance); + paramsChanged |= ImGui::SliderInt("Avoidance Quality", ¶ms->m_obstacleAvoidanceType, 0, 3); + paramsChanged |= ImGui::Checkbox("Separation", ¶ms->m_separation); + paramsChanged |= ImGui::SliderFloat("Separation Weight", ¶ms->m_separationWeight, 0.0f, 20.0f); - imguiUnindent(); + if (paramsChanged) + { + m_state->updateAgentParams(); + } + ImGui::TreePop(); } - if (imguiCollapse("Selected Debug Draw", 0, params->m_expandSelectedDebugDraw)) + if (ImGui::TreeNode("Selected Debug Draw")) { - params->m_expandSelectedDebugDraw = !params->m_expandSelectedDebugDraw; + ImGui::Checkbox("Show Corners", ¶ms->m_showCorners); + ImGui::Checkbox("Show Collision Segments", ¶ms->m_showCollisionSegments); + ImGui::Checkbox("Show Path", ¶ms->m_showPath); + ImGui::Checkbox("Show VO", ¶ms->m_showVO); + ImGui::Checkbox("Show Path Optimization", ¶ms->m_showOpt); + ImGui::Checkbox("Show Neighbours", ¶ms->m_showNeis); + ImGui::TreePop(); } - if (params->m_expandSelectedDebugDraw) + if (ImGui::TreeNode("Debug Draw")) { - imguiIndent(); - if (imguiCheck("Show Corners", params->m_showCorners)) { params->m_showCorners = !params->m_showCorners; } - if (imguiCheck("Show Collision Segs", params->m_showCollisionSegments)) - { - params->m_showCollisionSegments = !params->m_showCollisionSegments; - } - if (imguiCheck("Show Path", params->m_showPath)) { params->m_showPath = !params->m_showPath; } - if (imguiCheck("Show VO", params->m_showVO)) { params->m_showVO = !params->m_showVO; } - if (imguiCheck("Show Path Optimization", params->m_showOpt)) { params->m_showOpt = !params->m_showOpt; } - if (imguiCheck("Show Neighbours", params->m_showNeis)) { params->m_showNeis = !params->m_showNeis; } - imguiUnindent(); + ImGui::Checkbox("Show Labels", ¶ms->m_showLabels); + ImGui::Checkbox("Show Prox Grid", ¶ms->m_showGrid); + ImGui::Checkbox("Show Nodes", ¶ms->m_showNodes); + ImGui::Checkbox("Show Perf Graph", ¶ms->m_showPerfGraph); + ImGui::Checkbox("Show Detail All", ¶ms->m_showDetailAll); + ImGui::TreePop(); } - - if (imguiCollapse("Debug Draw", 0, params->m_expandDebugDraw)) { params->m_expandDebugDraw = !params->m_expandDebugDraw; } - - if (params->m_expandDebugDraw) - { - imguiIndent(); - if (imguiCheck("Show Labels", params->m_showLabels)) { params->m_showLabels = !params->m_showLabels; } - if (imguiCheck("Show Prox Grid", params->m_showGrid)) { params->m_showGrid = !params->m_showGrid; } - if (imguiCheck("Show Nodes", params->m_showNodes)) { params->m_showNodes = !params->m_showNodes; } - if (imguiCheck("Show Perf Graph", params->m_showPerfGraph)) { params->m_showPerfGraph = !params->m_showPerfGraph; } - if (imguiCheck("Show Detail All", params->m_showDetailAll)) { params->m_showDetailAll = !params->m_showDetailAll; } - imguiUnindent(); - } -#endif } void CrowdTool::handleClick(const float* s, const float* p, bool shift) { - if (!m_sample) { return; } - if (!m_state) { return; } + if (!m_sample) + { + return; + } + if (!m_state) + { + return; + } InputGeom* geom = m_sample->getInputGeom(); - if (!geom) { return; } + if (!geom) + { + return; + } dtCrowd* crowd = m_sample->getCrowd(); - if (!crowd) { return; } + if (!crowd) + { + return; + } if (m_mode == ToolMode::CREATE) { @@ -1011,9 +1002,8 @@ void CrowdTool::handleRender() {} void CrowdTool::handleRenderOverlay(double* proj, double* model, int* view) { -#if 0 - rcIgnoreUnused(model); - rcIgnoreUnused(proj); + (void)model; + (void)proj; // Tool help const int h = view[3]; @@ -1021,32 +1011,45 @@ void CrowdTool::handleRenderOverlay(double* proj, double* model, int* view) if (m_mode == ToolMode::CREATE) { - imguiDrawText(280, ty, IMGUI_ALIGN_LEFT, "LMB: add agent. Shift+LMB: remove agent.", imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText( + 280, + static_cast(ty), + IM_COL32(255, 255, 255, 192), + "LMB: add agent. Shift+LMB: remove agent."); } else if (m_mode == ToolMode::MOVE_TARGET) { - imguiDrawText( - 280, ty, IMGUI_ALIGN_LEFT, "LMB: set move target. Shift+LMB: adjust set velocity.", imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText( + 280, + static_cast(ty), + IM_COL32(255, 255, 255, 192), + "LMB: set move target. Shift+LMB: adjust set velocity."); ty -= 20; - imguiDrawText(280, - ty, - IMGUI_ALIGN_LEFT, - "Setting velocity will move the agents without pathfinder.", - imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText( + 280, + static_cast(ty), + IM_COL32(255, 255, 255, 192), + "Setting velocity will move the agents without pathfinder."); } else if (m_mode == ToolMode::SELECT) { - imguiDrawText(280, ty, IMGUI_ALIGN_LEFT, "LMB: select agent.", imguiRGBA(255, 255, 255, 192)); + DrawScreenspaceText(280, static_cast(ty), IM_COL32(255, 255, 255, 192), "LMB: select agent."); } - ty -= 20; - imguiDrawText( - 280, ty, IMGUI_ALIGN_LEFT, "SPACE: Run/Pause simulation. 1: Step simulation.", imguiRGBA(255, 255, 255, 192)); - ty -= 20; + ty -= 20; + DrawScreenspaceText( + 280, + static_cast(ty), + IM_COL32(255, 255, 255, 192), + "SPACE: Run/Pause simulation. 1: Step simulation."); + + ty -= 20; if (m_state && m_state->isRunning()) { - imguiDrawText(280, ty, IMGUI_ALIGN_LEFT, "- RUNNING -", imguiRGBA(255, 32, 16, 255)); + DrawScreenspaceText(280, static_cast(ty), IM_COL32(255, 32, 16, 255), "- RUNNING -"); + } + else + { + DrawScreenspaceText(280, static_cast(ty), IM_COL32(255, 255, 255, 128), "- PAUSED -"); } - else { imguiDrawText(280, ty, IMGUI_ALIGN_LEFT, "- PAUSED -", imguiRGBA(255, 255, 255, 128)); } -#endif } diff --git a/RecastDemo/Source/InputGeom.cpp b/RecastDemo/Source/InputGeom.cpp index d318453b..35fb9f89 100644 --- a/RecastDemo/Source/InputGeom.cpp +++ b/RecastDemo/Source/InputGeom.cpp @@ -295,7 +295,7 @@ bool InputGeom::loadGeomSet(rcContext* ctx, char* buffer, size_t bufferLen) hasBuildSettings = true; sscanf( row + 1, - "%f %f %f %f %f %f %f %f %f %f %f %f %f %d %f %f %f %f %f %f %f", + "%f %f %f %f %f %f %f %f %f %f %d %f %f %d %f %f %f %f %f %f %f", &buildSettings.cellSize, &buildSettings.cellHeight, &buildSettings.agentHeight, @@ -375,7 +375,7 @@ bool InputGeom::saveGeomSet(const BuildSettings* settings) { fprintf( fp, - "s %f %f %f %f %f %f %f %f %f %f %f %f %f %d %f %f %f %f %f %f %f\n", + "s %f %f %f %f %f %f %f %f %f %f %d %f %f %d %f %f %f %f %f %f %f\n", settings->cellSize, settings->cellHeight, settings->agentHeight, diff --git a/RecastDemo/Source/NavMeshPruneTool.cpp b/RecastDemo/Source/NavMeshPruneTool.cpp index 4356fb42..bf7ed55c 100644 --- a/RecastDemo/Source/NavMeshPruneTool.cpp +++ b/RecastDemo/Source/NavMeshPruneTool.cpp @@ -24,7 +24,9 @@ #include "DetourNavMesh.h" #include "InputGeom.h" #include "Sample.h" -#include "imgui.h" +#include "imguiHelpers.h" + +#include #include #include @@ -215,29 +217,28 @@ void NavMeshPruneTool::reset() void NavMeshPruneTool::handleMenu() { - dtNavMesh* nav = sample->getNavMesh(); - if (!nav) - { - return; - } if (!flags) { return; } -#if 0 - if (imguiButton("Clear Selection")) + dtNavMesh* nav = sample->getNavMesh(); + if (!nav) + { + return; + } + + if (ImGui::Button("Clear Selection")) { flags->clearAllFlags(); } - if (imguiButton("Prune Unselected")) + if (ImGui::Button("Prune Unselected")) { disableUnvisitedPolys(nav, flags); delete flags; flags = nullptr; } -#endif } void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift) @@ -325,7 +326,5 @@ void NavMeshPruneTool::handleRender() void NavMeshPruneTool::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* view) { -#if 0 - imguiDrawText(280, view[3] - 40, IMGUI_ALIGN_LEFT, "LMB: Click fill area.", imguiRGBA(255, 255, 255, 192)); -#endif + DrawScreenspaceText(280.0f, static_cast(view[3]) - 40.0f, IM_COL32(255, 255, 255, 192), "LMB: Click fill area."); } diff --git a/RecastDemo/Source/NavMeshTesterTool.cpp b/RecastDemo/Source/NavMeshTesterTool.cpp index 10a0732c..bc9252c8 100644 --- a/RecastDemo/Source/NavMeshTesterTool.cpp +++ b/RecastDemo/Source/NavMeshTesterTool.cpp @@ -37,7 +37,9 @@ #include "Recast.h" #include "RecastDebugDraw.h" #include "Sample.h" -#include "imgui.h" +#include "imguiHelpers.h" + +#include #ifdef WIN32 # define snprintf _snprintf @@ -214,85 +216,84 @@ void NavMeshTesterTool::init(Sample* sample) void NavMeshTesterTool::handleMenu() { -#if 0 - if (imguiCheck("Pathfind Follow", m_toolMode == TOOLMODE_PATHFIND_FOLLOW)) + if (ImGui::RadioButton("Pathfind Follow", m_toolMode == TOOLMODE_PATHFIND_FOLLOW)) { m_toolMode = TOOLMODE_PATHFIND_FOLLOW; recalc(); } - if (imguiCheck("Pathfind Straight", m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)) + if (ImGui::RadioButton("Pathfind Straight", m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)) { m_toolMode = TOOLMODE_PATHFIND_STRAIGHT; recalc(); } if (m_toolMode == TOOLMODE_PATHFIND_STRAIGHT) { - imguiIndent(); - imguiLabel("Vertices at crossings"); - if (imguiCheck("None", m_straightPathOptions == 0)) + ImGui::Indent(); + ("Vertices at crossings"); + if (ImGui::RadioButton("None", m_straightPathOptions == 0)) { m_straightPathOptions = 0; recalc(); } - if (imguiCheck("Area", m_straightPathOptions == DT_STRAIGHTPATH_AREA_CROSSINGS)) + if (ImGui::RadioButton("Area", m_straightPathOptions == DT_STRAIGHTPATH_AREA_CROSSINGS)) { m_straightPathOptions = DT_STRAIGHTPATH_AREA_CROSSINGS; recalc(); } - if (imguiCheck("All", m_straightPathOptions == DT_STRAIGHTPATH_ALL_CROSSINGS)) + if (ImGui::RadioButton("All", m_straightPathOptions == DT_STRAIGHTPATH_ALL_CROSSINGS)) { m_straightPathOptions = DT_STRAIGHTPATH_ALL_CROSSINGS; recalc(); } - imguiUnindent(); + ImGui::Unindent(); } - if (imguiCheck("Pathfind Sliced", m_toolMode == TOOLMODE_PATHFIND_SLICED)) + if (ImGui::RadioButton("Pathfind Sliced", m_toolMode == TOOLMODE_PATHFIND_SLICED)) { m_toolMode = TOOLMODE_PATHFIND_SLICED; recalc(); } - imguiSeparator(); + ImGui::Separator(); - if (imguiCheck("Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL)) + if (ImGui::RadioButton("Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL)) { m_toolMode = TOOLMODE_DISTANCE_TO_WALL; recalc(); } - imguiSeparator(); + ImGui::Separator(); - if (imguiCheck("Raycast", m_toolMode == TOOLMODE_RAYCAST)) + if (ImGui::RadioButton("Raycast", m_toolMode == TOOLMODE_RAYCAST)) { m_toolMode = TOOLMODE_RAYCAST; recalc(); } - imguiSeparator(); + ImGui::Separator(); - if (imguiCheck("Find Polys in Circle", m_toolMode == TOOLMODE_FIND_POLYS_IN_CIRCLE)) + if (ImGui::RadioButton("Find Polys in Circle", m_toolMode == TOOLMODE_FIND_POLYS_IN_CIRCLE)) { m_toolMode = TOOLMODE_FIND_POLYS_IN_CIRCLE; recalc(); } - if (imguiCheck("Find Polys in Shape", m_toolMode == TOOLMODE_FIND_POLYS_IN_SHAPE)) + if (ImGui::RadioButton("Find Polys in Shape", m_toolMode == TOOLMODE_FIND_POLYS_IN_SHAPE)) { m_toolMode = TOOLMODE_FIND_POLYS_IN_SHAPE; recalc(); } - imguiSeparator(); + ImGui::Separator(); - if (imguiCheck("Find Local Neighbourhood", m_toolMode == TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD)) + if (ImGui::RadioButton("Find Local Neighbourhood", m_toolMode == TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD)) { m_toolMode = TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD; recalc(); } - imguiSeparator(); + ImGui::Separator(); - if (imguiButton("Set Random Start")) + if (ImGui::Button("Set Random Start")) { dtStatus status = m_navQuery->findRandomPoint(&m_filter, frand, &m_startRef, m_spos); if (dtStatusSucceed(status)) @@ -301,7 +302,9 @@ void NavMeshTesterTool::handleMenu() recalc(); } } - if (imguiButton("Set Random End", m_sposSet)) + + ImGui::BeginDisabled(!m_sposSet); + if (ImGui::Button("Set Random End")) { if (m_sposSet) { @@ -320,10 +323,11 @@ void NavMeshTesterTool::handleMenu() } } } + ImGui::EndDisabled(); - imguiSeparator(); + ImGui::Separator(); - if (imguiButton("Make Random Points")) + if (ImGui::Button("Make Random Points")) { m_randPointsInCircle = false; m_nrandPoints = 0; @@ -339,7 +343,8 @@ void NavMeshTesterTool::handleMenu() } } } - if (imguiButton("Make Random Points Around", m_sposSet)) + ImGui::BeginDisabled(!m_sposSet); + if (ImGui::Button("Make Random Points Around")) { if (m_sposSet) { @@ -365,62 +370,70 @@ void NavMeshTesterTool::handleMenu() } } } + ImGui::EndDisabled(); - imguiSeparator(); + ImGui::Separator(); - imguiLabel("Include Flags"); + ImGui::Text("Include Flags"); - imguiIndent(); - if (imguiCheck("Walk", (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_WALK) != 0)) + ImGui::Indent(); + bool walk = (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_WALK) != 0; + if (ImGui::Checkbox("Walk", &walk)) { m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ SAMPLE_POLYFLAGS_WALK); recalc(); } - if (imguiCheck("Swim", (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_SWIM) != 0)) + bool swim = (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_SWIM) != 0; + if (ImGui::Checkbox("Swim", &swim)) { m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ SAMPLE_POLYFLAGS_SWIM); recalc(); } - if (imguiCheck("Door", (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_DOOR) != 0)) + bool door = (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_DOOR) != 0; + if (ImGui::Checkbox("Door", &door)) { m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ SAMPLE_POLYFLAGS_DOOR); recalc(); } - if (imguiCheck("Jump", (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_JUMP) != 0)) + bool jump = (m_filter.getIncludeFlags() & SAMPLE_POLYFLAGS_JUMP) != 0; + if (ImGui::Checkbox("Jump", &jump)) { m_filter.setIncludeFlags(m_filter.getIncludeFlags() ^ SAMPLE_POLYFLAGS_JUMP); recalc(); } - imguiUnindent(); + ImGui::Unindent(); - imguiSeparator(); - imguiLabel("Exclude Flags"); + ImGui::Separator(); + ImGui::Text("Exclude Flags"); - imguiIndent(); - if (imguiCheck("Walk", (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_WALK) != 0)) + ImGui::Indent(); + bool excludeWalk = (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_WALK) != 0; + if (ImGui::Checkbox("Walk", &excludeWalk)) { m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ SAMPLE_POLYFLAGS_WALK); recalc(); } - if (imguiCheck("Swim", (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_SWIM) != 0)) + bool excludeSwim = (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_SWIM) != 0; + if (ImGui::Checkbox("Swim", &excludeSwim)) { m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ SAMPLE_POLYFLAGS_SWIM); recalc(); } - if (imguiCheck("Door", (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_DOOR) != 0)) + bool excludeDoor = (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_DOOR) != 0; + if (ImGui::Checkbox("Door", &excludeDoor)) { m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ SAMPLE_POLYFLAGS_DOOR); recalc(); } - if (imguiCheck("Jump", (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_JUMP) != 0)) + bool excludeJump = (m_filter.getExcludeFlags() & SAMPLE_POLYFLAGS_JUMP) != 0; + if (ImGui::Checkbox("Jump", &excludeJump)) { m_filter.setExcludeFlags(m_filter.getExcludeFlags() ^ SAMPLE_POLYFLAGS_JUMP); recalc(); } - imguiUnindent(); + ImGui::Unindent(); - imguiSeparator(); -#endif + ImGui::Separator(); } void NavMeshTesterTool::handleClick(const float* /*s*/, const float* p, bool shift) @@ -1484,28 +1497,25 @@ void NavMeshTesterTool::handleRender() void NavMeshTesterTool::handleRenderOverlay(double* proj, double* model, int* view) { -#if 0 GLdouble x, y, z; // Draw start and end point labels - if (m_sposSet && gluProject((GLdouble)m_spos[0], (GLdouble)m_spos[1], (GLdouble)m_spos[2], model, proj, view, &x, &y, &z)) + if (m_sposSet && gluProject(m_spos[0], m_spos[1], m_spos[2], model, proj, view, &x, &y, &z)) { - imguiDrawText((int)x, (int)(y - 25), IMGUI_ALIGN_CENTER, "Start", imguiRGBA(0, 0, 0, 220)); + DrawScreenspaceText(static_cast(x), static_cast(y) - 25, IM_COL32(0, 0, 0, 220), "Start", true); } - if (m_eposSet && gluProject((GLdouble)m_epos[0], (GLdouble)m_epos[1], (GLdouble)m_epos[2], model, proj, view, &x, &y, &z)) + if (m_eposSet && gluProject(m_epos[0], m_epos[1], m_epos[2], model, proj, view, &x, &y, &z)) { - imguiDrawText((int)x, (int)(y - 25), IMGUI_ALIGN_CENTER, "End", imguiRGBA(0, 0, 0, 220)); + DrawScreenspaceText(static_cast(x), static_cast(y) - 25, IM_COL32(0, 0, 0, 220), "End", true); } // Tool help const int h = view[3]; - imguiDrawText( + DrawScreenspaceText( 280, - h - 40, - IMGUI_ALIGN_LEFT, - "LMB+SHIFT: Set start location LMB: Set end location", - imguiRGBA(255, 255, 255, 192)); -#endif + static_cast(h) - 40, + IM_COL32(255, 255, 255, 192), + "LMB+SHIFT: Set start location LMB: Set end location"); } void NavMeshTesterTool::drawAgent(const float* pos, float r, float h, float c, const unsigned int col) diff --git a/RecastDemo/Source/OffMeshConnectionTool.cpp b/RecastDemo/Source/OffMeshConnectionTool.cpp index 55511b78..e6a4f066 100644 --- a/RecastDemo/Source/OffMeshConnectionTool.cpp +++ b/RecastDemo/Source/OffMeshConnectionTool.cpp @@ -31,7 +31,8 @@ #include "OffMeshConnectionTool.h" #include "Recast.h" #include "Sample.h" -#include "imgui.h" + +#include #ifdef WIN32 # define snprintf _snprintf diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index 46a1a537..5900c8df 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -27,8 +27,8 @@ #include "RecastDebugDraw.h" #include "SDL.h" #include "SDL_opengl.h" -#include "imgui.h" +#include #include #include @@ -143,8 +143,7 @@ void Sample::handleMeshChanged(InputGeom* geom) { inputGeometry = geom; - const BuildSettings* buildSettings = geom->getBuildSettings(); - if (buildSettings) + if (const BuildSettings* buildSettings = geom->getBuildSettings()) { cellSize = buildSettings->cellSize; cellHeight = buildSettings->cellHeight; @@ -156,7 +155,6 @@ void Sample::handleMeshChanged(InputGeom* geom) regionMergeSize = buildSettings->regionMergeSize; edgeMaxLen = buildSettings->edgeMaxLen; edgeMaxError = buildSettings->edgeMaxError; - vertsPerPoly = buildSettings->vertsPerPoly; detailSampleDist = buildSettings->detailSampleDist; detailSampleMaxError = buildSettings->detailSampleMaxError; partitionType = buildSettings->partitionType; @@ -175,7 +173,6 @@ void Sample::collectSettings(BuildSettings& settings) settings.regionMergeSize = regionMergeSize; settings.edgeMaxLen = edgeMaxLen; settings.edgeMaxError = edgeMaxError; - settings.vertsPerPoly = vertsPerPoly; settings.detailSampleDist = detailSampleDist; settings.detailSampleMaxError = detailSampleMaxError; settings.partitionType = partitionType; @@ -193,7 +190,7 @@ void Sample::resetCommonSettings() regionMergeSize = 20; edgeMaxLen = 12.0f; edgeMaxError = 1.3f; - vertsPerPoly = 6.0f; + vertsPerPoly = 6; detailSampleDist = 6.0f; detailSampleMaxError = 1.0f; partitionType = SAMPLE_PARTITION_WATERSHED; @@ -201,77 +198,62 @@ void Sample::resetCommonSettings() void Sample::handleCommonSettings() { -#if 0 - imguiLabel("Rasterization"); - imguiSlider("Cell Size", &cellSize, 0.1f, 1.0f, 0.01f); - imguiSlider("Cell Height", &cellHeight, 0.1f, 1.0f, 0.01f); + ImGui::SeparatorText("Rasterization"); + ImGui::SliderFloat("##Cell Size", &cellSize, 0.1f, 1.0f, "Cell Size = %.3f"); + ImGui::SliderFloat("##Cell Height", &cellHeight, 0.1f, 1.0f, "Cell Height = %.3f"); if (inputGeometry) { - const float* bmin = inputGeometry->getNavMeshBoundsMin(); - const float* bmax = inputGeometry->getNavMeshBoundsMax(); - int gw = 0, gh = 0; - rcCalcGridSize(bmin, bmax, cellSize, &gw, &gh); - char text[64]; - snprintf(text, 64, "Voxels %d x %d", gw, gh); - imguiValue(text); + int gridWidth = 0; + int gridHeight = 0; + rcCalcGridSize( + inputGeometry->getNavMeshBoundsMin(), + inputGeometry->getNavMeshBoundsMax(), + cellSize, + &gridWidth, + &gridHeight); + ImGui::Text("Voxels %d x %d", gridWidth, gridHeight); } - imguiSeparator(); - imguiLabel("Agent"); - imguiSlider("Height", &agentHeight, 0.1f, 5.0f, 0.1f); - imguiSlider("Radius", &agentRadius, 0.0f, 5.0f, 0.1f); - imguiSlider("Max Climb", &agentMaxClimb, 0.1f, 5.0f, 0.1f); - imguiSlider("Max Slope", &agentMaxSlope, 0.0f, 90.0f, 1.0f); + ImGui::SeparatorText("Agent"); + ImGui::SliderFloat("##Height", &agentHeight, 0.1f, 5.0f, "Height = %.3f"); + ImGui::SliderFloat("##Radius", &agentRadius, 0.0f, 5.0f, "Radius = %.3f"); + ImGui::SliderFloat("##Max Climb", &agentMaxClimb, 0.1f, 5.0f, "Max Climb = %.3f"); + ImGui::SliderFloat("##Max Slope", &agentMaxSlope, 0.0f, 90.0f, "Max Slope = %.3f"); - imguiSeparator(); - imguiLabel("Region"); - imguiSlider("Min Region Size", ®ionMinSize, 0.0f, 150.0f, 1.0f); - imguiSlider("Merged Region Size", ®ionMergeSize, 0.0f, 150.0f, 1.0f); + ImGui::SeparatorText("Region"); + ImGui::SliderFloat("##Min Region Size", ®ionMinSize, 0.0f, 150.0f, "Min Region Size = %.3f"); + ImGui::SliderFloat("##Merged Region Size", ®ionMergeSize, 0.0f, 150.0f, "Merged Region Size = %.3f"); - imguiSeparator(); - imguiLabel("Partitioning"); - if (imguiCheck("Watershed", partitionType == SAMPLE_PARTITION_WATERSHED)) + ImGui::SeparatorText("Partitioning"); + if (ImGui::RadioButton("Watershed", partitionType == SAMPLE_PARTITION_WATERSHED)) { partitionType = SAMPLE_PARTITION_WATERSHED; } - if (imguiCheck("Monotone", partitionType == SAMPLE_PARTITION_MONOTONE)) + if (ImGui::RadioButton("Monotone", partitionType == SAMPLE_PARTITION_MONOTONE)) { partitionType = SAMPLE_PARTITION_MONOTONE; } - if (imguiCheck("Layers", partitionType == SAMPLE_PARTITION_LAYERS)) + if (ImGui::RadioButton("Layers", partitionType == SAMPLE_PARTITION_LAYERS)) { partitionType = SAMPLE_PARTITION_LAYERS; } - imguiSeparator(); - imguiLabel("Filtering"); - if (imguiCheck("Low Hanging Obstacles", filterLowHangingObstacles)) - { - filterLowHangingObstacles = !filterLowHangingObstacles; - } - if (imguiCheck("Ledge Spans", filterLedgeSpans)) - { - filterLedgeSpans = !filterLedgeSpans; - } - if (imguiCheck("Walkable Low Height Spans", filterWalkableLowHeightSpans)) - { - filterWalkableLowHeightSpans = !filterWalkableLowHeightSpans; - } + ImGui::SeparatorText("Filtering"); + ImGui::Checkbox("Low Hanging Obstacles", &filterLowHangingObstacles); + ImGui::Checkbox("Ledge Spans", &filterLedgeSpans); + ImGui::Checkbox("Walkable Low Height Spans", &filterWalkableLowHeightSpans); - imguiSeparator(); - imguiLabel("Polygonization"); - imguiSlider("Max Edge Length", &edgeMaxLen, 0.0f, 50.0f, 1.0f); - imguiSlider("Max Edge Error", &edgeMaxError, 0.1f, 3.0f, 0.1f); - imguiSlider("Verts Per Poly", &vertsPerPoly, 3.0f, 12.0f, 1.0f); + ImGui::SeparatorText("Polygonization"); + ImGui::SliderFloat("Max Edge Length", &edgeMaxLen, 0.0f, 50.0f); + ImGui::SliderFloat("Max Edge Error", &edgeMaxError, 0.1f, 3.0f); + ImGui::SliderInt("Verts Per Poly", &vertsPerPoly, 3, 12); - imguiSeparator(); - imguiLabel("Detail Mesh"); - imguiSlider("Sample Distance", &detailSampleDist, 0.0f, 16.0f, 1.0f); - imguiSlider("Max Sample Error", &detailSampleMaxError, 0.0f, 16.0f, 1.0f); + ImGui::SeparatorText("Detail Mesh"); + ImGui::SliderFloat("Sample Distance", &detailSampleDist, 0.0f, 16.0f); + ImGui::SliderFloat("Max Sample Error", &detailSampleMaxError, 0.0f, 16.0f); - imguiSeparator(); -#endif + ImGui::Separator(); } void Sample::handleClick(const float* rayStartPos, const float* rayHitPos, bool shift) diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index ec8967b4..2df8a3f9 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -27,7 +27,6 @@ #include "DetourDebugDraw.h" #include "DetourNavMesh.h" #include "DetourNavMeshBuilder.h" -#include "imgui.h" #include "InputGeom.h" #include "NavMeshPruneTool.h" #include "NavMeshTesterTool.h" @@ -38,6 +37,8 @@ #include "Sample.h" #include "SDL_opengl.h" +#include + #ifdef WIN32 # define snprintf _snprintf #endif @@ -67,73 +68,65 @@ void Sample_SoloMesh::handleSettings() { handleCommonSettings(); -#if 0 - imguiSeparator(); + ImGui::Separator(); - imguiIndent(); - imguiIndent(); + ImGui::Indent(); + ImGui::Indent(); - if (imguiButton("Save")) + if (ImGui::Button("Save")) { saveAll("solo_navmesh.bin", navMesh); } - if (imguiButton("Load")) + if (ImGui::Button("Load")) { dtFreeNavMesh(navMesh); navMesh = loadAll("solo_navmesh.bin"); navQuery->init(navMesh, 2048); } - imguiUnindent(); - imguiUnindent(); + ImGui::Unindent(); + ImGui::Unindent(); - char message[64]; - snprintf(message, 64, "Build Time: %.1fms", totalBuildTimeMs); - imguiLabel(message); + ImGui::Text("Build Time: %.1fms", totalBuildTimeMs); - imguiSeparator(); -#endif + ImGui::Separator(); } void Sample_SoloMesh::handleTools() { -#if 0 const SampleToolType type = !tool ? SampleToolType::NONE : tool->type(); - if (imguiCheck("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } - if (imguiCheck("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } - if (imguiCheck("Create Off-Mesh Connections", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } - if (imguiCheck("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } - if (imguiCheck("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); } + if (ImGui::RadioButton("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } + if (ImGui::RadioButton("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } + if (ImGui::RadioButton("Create Off-Mesh Connections", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } + if (ImGui::RadioButton("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } + if (ImGui::RadioButton("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); } - imguiSeparatorLine(); - - imguiIndent(); + ImGui::Separator(); + ImGui::Indent(); if (tool) { tool->handleMenu(); } - - imguiUnindent(); -#endif + ImGui::Unindent(); } void Sample_SoloMesh::UI_DrawModeOption(const char* name, const DrawMode drawMode, const bool enabled) { -#if 0 - if (imguiCheck(name, currentDrawMode == drawMode, enabled)) - { - currentDrawMode = drawMode; - } -#endif + ImGui::BeginDisabled(!enabled); + bool checked = currentDrawMode == drawMode; + if (ImGui::Checkbox(name, &checked)) + { + currentDrawMode = drawMode; + } + ImGui::EndDisabled(); } void Sample_SoloMesh::handleDebugMode() { -#if 0 - imguiLabel("Draw"); + ImGui::Text("Draw Mode"); UI_DrawModeOption("Input Mesh", DrawMode::MESH, true); UI_DrawModeOption("Navmesh", DrawMode::NAVMESH, navMesh != nullptr); UI_DrawModeOption("Navmesh Invis", DrawMode::NAVMESH_INVIS, navMesh != nullptr); @@ -151,7 +144,6 @@ void Sample_SoloMesh::handleDebugMode() UI_DrawModeOption("Contours", DrawMode::CONTOURS, contourSet != nullptr); UI_DrawModeOption("Poly Mesh", DrawMode::POLYMESH, polyMesh != nullptr); UI_DrawModeOption("Poly Mesh Detail", DrawMode::POLYMESH_DETAIL, detailMesh != nullptr); -#endif } void Sample_SoloMesh::handleRender() @@ -349,7 +341,7 @@ bool Sample_SoloMesh::handleBuild() config.maxSimplificationError = edgeMaxError; config.minRegionArea = static_cast(rcSqr(regionMinSize)); // Note: area = size*size config.mergeRegionArea = static_cast(rcSqr(regionMergeSize)); // Note: area = size*size - config.maxVertsPerPoly = static_cast(vertsPerPoly); + config.maxVertsPerPoly = vertsPerPoly; config.detailSampleDist = detailSampleDist < 0.9f ? 0 : cellSize * detailSampleDist; config.detailSampleMaxError = cellHeight * detailSampleMaxError; diff --git a/RecastDemo/Source/Sample_TempObstacles.cpp b/RecastDemo/Source/Sample_TempObstacles.cpp index 36412780..0a224c79 100644 --- a/RecastDemo/Source/Sample_TempObstacles.cpp +++ b/RecastDemo/Source/Sample_TempObstacles.cpp @@ -28,25 +28,25 @@ #else # include #endif -#include "imgui.h" -#include "InputGeom.h" -#include "Sample.h" -#include "Sample_TempObstacles.h" -#include "Recast.h" -#include "RecastDebugDraw.h" -#include "DetourAssert.h" -#include "DetourNavMesh.h" -#include "DetourNavMeshBuilder.h" -#include "DetourDebugDraw.h" -#include "DetourCommon.h" -#include "DetourTileCache.h" -#include "NavMeshTesterTool.h" -#include "OffMeshConnectionTool.h" #include "ConvexVolumeTool.h" #include "CrowdTool.h" +#include "DetourAssert.h" +#include "DetourCommon.h" +#include "DetourDebugDraw.h" +#include "DetourNavMesh.h" +#include "DetourNavMeshBuilder.h" +#include "DetourTileCache.h" +#include "InputGeom.h" +#include "NavMeshTesterTool.h" +#include "OffMeshConnectionTool.h" +#include "Recast.h" #include "RecastAlloc.h" #include "RecastAssert.h" +#include "RecastDebugDraw.h" +#include "Sample.h" +#include "Sample_TempObstacles.h" #include "fastlz.h" +#include "imguiHelpers.h" #ifdef WIN32 # define snprintf _snprintf @@ -568,9 +568,7 @@ void drawDetailOverlay(const dtTileCache* tileCache, const int tileX, const int const int ntiles = tileCache->getTilesAt(tileX, tileY, tiles, MAX_LAYERS); if (!ntiles) { return; } - const int rawSize = calcLayerBufferSize(tileCache->getParams()->width, tileCache->getParams()->height); - - char text[128]; + //const int rawSize = calcLayerBufferSize(tileCache->getParams()->width, tileCache->getParams()->height); for (int i = 0; i < ntiles; ++i) { @@ -585,6 +583,7 @@ void drawDetailOverlay(const dtTileCache* tileCache, const int tileX, const int if (gluProject(static_cast(pos[0]), static_cast(pos[1]), static_cast(pos[2]), model, proj, view, &x, &y, &z)) { #if 0 + char text[128]; snprintf(text, 128, "(%d,%d)/%d", tile->header->tx, tile->header->ty, tile->header->tlayer); imguiDrawText(static_cast(x), static_cast(y) - 25, IMGUI_ALIGN_CENTER, text, imguiRGBA(0, 0, 0, 220)); snprintf(text, 128, "Compressed: %.1f kB", tile->dataSize / 1024.0f); diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index 5934db42..3d0e0e60 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -41,7 +41,8 @@ #include "Recast.h" #include "RecastDebugDraw.h" #include "Sample.h" -#include "imgui.h" + +#include #ifdef WIN32 # define snprintf _snprintf diff --git a/RecastDemo/Source/TestCase.cpp b/RecastDemo/Source/TestCase.cpp index d702c3a2..79fb7f7d 100644 --- a/RecastDemo/Source/TestCase.cpp +++ b/RecastDemo/Source/TestCase.cpp @@ -33,7 +33,8 @@ # include #endif #include "PerfTimer.h" -#include "imgui.h" + +#include #ifdef WIN32 # define snprintf _snprintf diff --git a/RecastDemo/Source/ValueHistory.cpp b/RecastDemo/Source/ValueHistory.cpp index 27b8be9d..4ee4395f 100644 --- a/RecastDemo/Source/ValueHistory.cpp +++ b/RecastDemo/Source/ValueHistory.cpp @@ -1,6 +1,6 @@ #include "ValueHistory.h" -#include "imgui.h" +#include #include #include diff --git a/RecastDemo/Source/main.cpp b/RecastDemo/Source/main.cpp index da94c604..3a6830f7 100644 --- a/RecastDemo/Source/main.cpp +++ b/RecastDemo/Source/main.cpp @@ -37,6 +37,7 @@ #include "Sample_TempObstacles.h" #include "Sample_TileMesh.h" #include "TestCase.h" +#include "imguiHelpers.h" #include #include @@ -245,109 +246,19 @@ int main(int /*argc*/, char** /*argv*/) style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.5f, 0.5f, 0.5f, 196.0f / 255.0f); //style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 196.0f / 255.0f, 0, 96.0f / 255.0f); - /* - /// 0 = FLAT APPEARENCE - /// 1 = MORE "3D" LOOK - int is3D = 1; - style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.73f, 0.73f, 0.73f, 0.35f); - style.Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.75f); - style.Colors[ImGuiCol_WindowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.75f); - style.Colors[ImGuiCol_PopupBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.75f); - style.Colors[ImGuiCol_Border] = ImVec4(0.12f, 0.12f, 0.12f, 0.71f); - style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); - style.Colors[ImGuiCol_FrameBg] = ImVec4(0.42f, 0.42f, 0.42f, 0.54f); - style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.42f, 0.42f, 0.42f, 0.40f); - style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.67f); - - style.Colors[ImGuiCol_TitleBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); - style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.17f, 0.17f, 0.17f, 0.90f); - - style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.335f, 0.335f, 0.335f, 1.000f); - - style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.24f, 0.24f, 0.24f, 0.53f); - style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.76f, 0.76f, 0.76f, 1.00f); - - style.Colors[ImGuiCol_CheckMark] = ImVec4(0.65f, 0.65f, 0.65f, 1.00f); - - style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.64f, 0.64f, 0.64f, 1.00f); - - style.Colors[ImGuiCol_Button] = ImVec4(0.54f, 0.54f, 0.54f, 0.35f); - style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.52f, 0.52f, 0.52f, 0.59f); - style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.76f, 0.76f, 0.76f, 1.00f); - - style.Colors[ImGuiCol_Header] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); - style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.47f, 0.47f, 0.47f, 1.00f); - style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.76f, 0.76f, 0.76f, 0.77f); - - style.Colors[ImGuiCol_Separator] = ImVec4(0.000f, 0.000f, 0.000f, 0.137f); - style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.700f, 0.671f, 0.600f, 0.290f); - style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.702f, 0.671f, 0.600f, 0.674f); - - style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); - style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); - style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); - - style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); - style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); - style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); - - style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); - style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); - style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); - style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); - style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); - - style.PopupRounding = 3; - style.WindowPadding = ImVec2(4, 4); - style.FramePadding = ImVec2(6, 4); - style.ItemSpacing = ImVec2(6, 2); - style.ScrollbarSize = 18; - style.WindowBorderSize = 1; - style.ChildBorderSize = 1; - style.PopupBorderSize = 1; - style.FrameBorderSize = is3D; - style.WindowRounding = 3; - style.ChildRounding = 3; - style.FrameRounding = 3; - style.ScrollbarRounding = 2; - style.GrabRounding = 3; - - #ifdef IMGUI_HAS_DOCK - style.TabBorderSize = is3D; - style.TabRounding = 3; - - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); - colors[ImGuiCol_DockingPreview] = ImVec4(0.85f, 0.85f, 0.85f, 0.28f); - - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - style.WindowRounding = 0.0f; - style.Colors[ImGuiCol_WindowBg].w = 1.0f; - } - #endif - */ // Setup Platform/Renderer backends ImGui_ImplSDL2_InitForOpenGL(app.window, app.glContext); ImGui_ImplOpenGL2_Init(); - ImGuiWindowFlags staticWindowFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse; + ImGuiWindowFlags staticWindowFlags = ImGuiWindowFlags_NoMove + //| ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoSavedSettings + | ImGuiWindowFlags_NoCollapse; app.prevFrameTime = SDL_GetTicks(); @@ -575,8 +486,8 @@ int main(int /*argc*/, char** /*argv*/) } // Update sample simulation. - const float SIM_RATE = 20; - const float DELTA_TIME = 1.0f / SIM_RATE; + constexpr float SIM_RATE = 20; + constexpr float DELTA_TIME = 1.0f / SIM_RATE; app.timeAcc = rcClamp(app.timeAcc + dt, -1.0f, 1.0f); int simIter = 0; while (app.timeAcc > DELTA_TIME) @@ -590,10 +501,10 @@ int main(int /*argc*/, char** /*argv*/) } // Clamp the framerate so that we do not hog all the CPU. - const float MIN_FRAME_TIME = 1.0f / 40.0f; + constexpr float MIN_FRAME_TIME = 1.0f / 40.0f; if (dt < MIN_FRAME_TIME) { - int ms = (int)((MIN_FRAME_TIME - dt) * 1000.0f); + int ms = static_cast((MIN_FRAME_TIME - dt) * 1000.0f); if (ms > 10) { ms = 10; @@ -691,8 +602,8 @@ int main(int /*argc*/, char** /*argv*/) app.cameraPos[1] += (app.moveUp - app.moveDown) * keybSpeed * dt; + // Draw the mesh glEnable(GL_FOG); - if (app.sample) { app.sample->handleRender(); @@ -701,10 +612,9 @@ int main(int /*argc*/, char** /*argv*/) { app.testCase->handleRender(); } - glDisable(GL_FOG); - // Render GUI + // Draw UI glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -712,8 +622,6 @@ int main(int /*argc*/, char** /*argv*/) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - app.mouseOverMenu = false; - ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); @@ -721,21 +629,17 @@ int main(int /*argc*/, char** /*argv*/) if (app.sample) { - app.sample->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport); + app.sample->handleRenderOverlay(projectionMatrix, modelviewMatrix, viewport); } if (app.testCase) { - if (app.testCase->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport)) - { - app.mouseOverMenu = true; - } + app.testCase->handleRenderOverlay(projectionMatrix, modelviewMatrix, viewport); } // Help text. if (app.showMenu) { - ImDrawList* draw_list = ImGui::GetForegroundDrawList(); - draw_list->AddText({280.0f, 20.0f}, IM_COL32(255, 255, 255, 128), "W/A/S/D: Move RMB: Rotate"); + DrawScreenspaceText(280.0f, 20.0f, IM_COL32(255, 255, 255, 128), "W/A/S/D: Move RMB: Rotate"); } bool newMeshSelected = false; @@ -743,8 +647,8 @@ int main(int /*argc*/, char** /*argv*/) if (app.showMenu) { - ImGui::SetNextWindowPos(ImVec2(app.width - 250 - 10, 10), ImGuiCond_Always); // Position in screen space - ImGui::SetNextWindowSize(ImVec2(250, app.height - 20), ImGuiCond_Always); // Size of the window + ImGui::SetNextWindowPos(ImVec2(static_cast(app.width - 250 - 10), 10), ImGuiCond_Always); // Position in screen space + ImGui::SetNextWindowSize(ImVec2(350, static_cast(app.height - 20)), ImGuiCond_Always); // Size of the window ImGui::Begin("Properties", nullptr, staticWindowFlags); ImGui::Checkbox("Show Log", &app.showLog); @@ -1012,11 +916,10 @@ int main(int /*argc*/, char** /*argv*/) #endif // Log - static bool auto_scroll = true; if (app.showLog && app.showMenu) { - ImGui::SetNextWindowPos(ImVec2(250 + 20, app.height - 200 - 10), ImGuiCond_Always); // Position in screen space - ImGui::SetNextWindowSize(ImVec2(app.width - 250 - 250 - 20 - 20, 200), ImGuiCond_Always); // Size of the window + ImGui::SetNextWindowPos(ImVec2(250 + 20, static_cast(app.height - 200 - 10)), ImGuiCond_Always); // Position in screen space + ImGui::SetNextWindowSize(ImVec2(static_cast(app.width - 250 - 350 - 20 - 20), 200), ImGuiCond_Always); // Size of the window ImGui::Begin("Log", nullptr, staticWindowFlags); for (int i = 0; i < app.buildContext.getLogCount(); ++i) @@ -1031,7 +934,7 @@ int main(int /*argc*/, char** /*argv*/) if (!app.showTestCases && app.showTools && app.showMenu) { ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_Always); // Position in screen space - ImGui::SetNextWindowSize(ImVec2(250, app.height - 20), ImGuiCond_Always); // Size of the window + ImGui::SetNextWindowSize(ImVec2(250, static_cast(app.height - 20)), ImGuiCond_Always); // Size of the window ImGui::Begin("Tools", nullptr, staticWindowFlags); if (app.sample) @@ -1042,8 +945,8 @@ int main(int /*argc*/, char** /*argv*/) ImGui::End(); } - // Marker - if (app.markerPositionSet && gluProject((GLdouble)app.markerPosition[0], (GLdouble)app.markerPosition[1], (GLdouble)app.markerPosition[2], modelviewMatrix, projectionMatrix, viewport, &x, &y, &z)) + // Draw Marker + if (app.markerPositionSet && gluProject(app.markerPosition[0], app.markerPosition[1], app.markerPosition[2], modelviewMatrix, projectionMatrix, viewport, &x, &y, &z)) { // Draw marker circle glLineWidth(5.0f); @@ -1052,9 +955,9 @@ int main(int /*argc*/, char** /*argv*/) const float r = 25.0f; for (int i = 0; i < 20; ++i) { - const float a = (float)i / 20.0f * RC_PI * 2; - const float fx = (float)x + cosf(a) * r; - const float fy = (float)y + sinf(a) * r; + const float a = static_cast(i) / 20.0f * RC_PI * 2; + const float fx = static_cast(x) + cosf(a) * r; + const float fy = static_cast(y) + sinf(a) * r; glVertex2f(fx, fy); } glEnd();