From cee489f35b0b5aa86581b2062b49cdbc7c3bddf2 Mon Sep 17 00:00:00 2001 From: Indra Date: Tue, 6 Feb 2024 02:13:47 +0100 Subject: [PATCH] Improve collision drawing and filtering --- src/modules/Draw.cpp | 50 ++++++++++++++++++++++++++++++++------------ src/modules/Draw.h | 7 +++++++ src/render/Draw.cpp | 28 +++++++++++++++++++++++++ src/render/Draw.h | 3 ++- 4 files changed, 74 insertions(+), 14 deletions(-) diff --git a/src/modules/Draw.cpp b/src/modules/Draw.cpp index 745aa71..0ee8056 100644 --- a/src/modules/Draw.cpp +++ b/src/modules/Draw.cpp @@ -72,18 +72,29 @@ void Draw::OnFrame() void Draw::OnDraw() { - if (m_drawInstances) + if (m_drawInstances || m_drawCollision) { ImGui::Begin("Draw options"); - // Filter - ImGui::InputText("Filter", m_filter, sizeof(m_filter)); + if (ImGui::CollapsingHeader("Instance")) + { + // Filter + ImGui::InputText("Filter", m_filter, sizeof(m_filter)); + + // Options + ImGui::Checkbox("Draw intro", &m_drawIntro); + ImGui::Checkbox("Draw family", &m_drawFamily); + ImGui::Checkbox("Draw animations", &m_drawAnimation); + ImGui::Checkbox("Draw health", &m_drawHealth); + } + + if (ImGui::CollapsingHeader("Collision")) + { + ImGui::Checkbox("Player collision", &m_drawPlayerCollision); + ImGui::Checkbox("Enemy collision", &m_drawEnemyCollision); - // Options - ImGui::Checkbox("Draw intro", &m_drawIntro); - ImGui::Checkbox("Draw family", &m_drawFamily); - ImGui::Checkbox("Draw animations", &m_drawAnimation); - ImGui::Checkbox("Draw health", &m_drawHealth); + ImGui::InputInt("Terrain group", &m_terrainGroup); + } ImGui::End(); } @@ -213,7 +224,17 @@ void Draw::DrawCollision(Level* level) { auto terrainGroup = &terrain->terrainGroups[i]; - if (terrainGroup->mesh) + // Filter on terrain group + if (m_terrainGroup >= 0 && m_terrainGroup != i) + { + continue; + } + + // Filter on player/enemy collision + auto flag = terrainGroup->flags & 0x4000; + auto filter = (m_drawPlayerCollision && flag == 0) || (m_drawEnemyCollision && flag != 0); + + if (terrainGroup->mesh && filter) { DrawCollision(terrainGroup); } @@ -234,11 +255,14 @@ void Draw::DrawCollision(TerrainGroup* terrainGroup) auto y = GetVertice(face->i1, mesh, &mesh->m_position); auto z = GetVertice(face->i2, mesh, &mesh->m_position); - // TODO collision face lines - // TODO collision type/mask colors - // Draw the face - DrawTriangle(&x, &y, &z, RGBA(0, 255, 0, 10)); + auto color = terrainGroup->flags & 0x4000 ? RGBA(255, 0, 255, 10) : RGBA(0, 255, 0, 10); + DrawTriangle(&x, &y, &z, color); + + // Draw the face outlines + DrawLine(&x, &y, RGB(255, 0, 0)); + DrawLine(&y, &z, RGB(255, 0, 0)); + DrawLine(&z, &x, RGB(255, 0, 0)); } } diff --git a/src/modules/Draw.h b/src/modules/Draw.h index c6b5b8b..ba40ba8 100644 --- a/src/modules/Draw.h +++ b/src/modules/Draw.h @@ -17,6 +17,7 @@ class Draw : public Module bool m_drawPortals = false; bool m_drawSignals = false; + // Instance options bool m_drawIntro = false; bool m_drawFamily = false; bool m_drawHealth = false; @@ -24,6 +25,12 @@ class Draw : public Module char m_filter[100] = ""; + // Collision options + bool m_drawPlayerCollision = true; + bool m_drawEnemyCollision = true; + + int m_terrainGroup = -1; + void DrawInstances(); void DrawInstance(Instance* instance); void DrawEnemyRoute(Instance* instance); diff --git a/src/render/Draw.cpp b/src/render/Draw.cpp index aa0e619..3a0446e 100644 --- a/src/render/Draw.cpp +++ b/src/render/Draw.cpp @@ -65,5 +65,33 @@ void DrawPlane(cdc::Vector3* v0, cdc::Vector3* v1, int color) verts[4].color = color; verts[5].color = color; + DRAW_DrawTriangles(2, 0, verts, 2); +} + +// Scuffed ass line, TODO fix +void DrawLine(cdc::Vector3* v0, cdc::Vector3* v1, int color) +{ + DRAWVERTEX verts[6]; + + auto v2 = *v1; + auto v3 = *v0; + + v2.z += 50.f; + v3.x += 50.f; + + TRANS_TransToDrawVertexV4f(verts, v0); + TRANS_TransToDrawVertexV4f(&verts[1], &v2); + TRANS_TransToDrawVertexV4f(&verts[2], v1); + TRANS_TransToDrawVertexV4f(&verts[3], &v3); + TRANS_TransToDrawVertexV4f(&verts[4], v1); + TRANS_TransToDrawVertexV4f(&verts[5], v0); + + verts[0].color = color; + verts[1].color = color; + verts[2].color = color; + verts[3].color = color; + verts[4].color = color; + verts[5].color = color; + DRAW_DrawTriangles(2, 0, verts, 2); } \ No newline at end of file diff --git a/src/render/Draw.h b/src/render/Draw.h index 0b2a192..ab289b9 100644 --- a/src/render/Draw.h +++ b/src/render/Draw.h @@ -28,4 +28,5 @@ void DRAW_DrawQuads(int flags, int tpage, DRAWVERTEX* verts, int numquads); void DRAW_DrawTriangles(int flags, int tpage, DRAWVERTEX* verts, int numtris); void DrawTriangle(cdc::Vector3* v0, cdc::Vector3* v1, cdc::Vector3* v2, int color); -void DrawPlane(cdc::Vector3* v0, cdc::Vector3* v1, int color); \ No newline at end of file +void DrawPlane(cdc::Vector3* v0, cdc::Vector3* v1, int color); +void DrawLine(cdc::Vector3* v0, cdc::Vector3* v1, int color); \ No newline at end of file