Skip to content

Commit

Permalink
Improve collision drawing and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Feb 6, 2024
1 parent 6eda1d0 commit cee489f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
50 changes: 37 additions & 13 deletions src/modules/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -234,11 +255,14 @@ void Draw::DrawCollision(TerrainGroup* terrainGroup)
auto y = GetVertice<MeshVertex>(face->i1, mesh, &mesh->m_position);
auto z = GetVertice<MeshVertex>(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));
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/modules/Draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ 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;
bool m_drawAnimation = false;

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);
Expand Down
28 changes: 28 additions & 0 deletions src/render/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion src/render/Draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void DrawPlane(cdc::Vector3* v0, cdc::Vector3* v1, int color);
void DrawLine(cdc::Vector3* v0, cdc::Vector3* v1, int color);

0 comments on commit cee489f

Please sign in to comment.