Skip to content

Commit

Permalink
Add signal and collision drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Feb 4, 2024
1 parent ac86dd9 commit 6eda1d0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/modules/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#include "instance/Instances.h"
#include "instance/Enemy.h"

template <typename T>
static inline cdc::Vector3 GetVertice(unsigned int vertice, Mesh* mesh, cdc::Vector* offset)
{
auto vertex = &((T*)mesh->m_vertices)[vertice];
auto position = cdc::Vector3{ static_cast<float>(vertex->x), static_cast<float>(vertex->y), static_cast<float>(vertex->z) };

position += offset;

return position;
}

void Draw::OnMenu()
{
if (ImGui::BeginMenu("Draw"))
Expand Down Expand Up @@ -195,10 +206,40 @@ void Draw::DrawMarkUp()

void Draw::DrawCollision(Level* level)
{
auto terrain = level->terrain;

// Draw the collision mesh for all terrain groups
for (int i = 0; i < terrain->numTerrainGroups; i++)
{
auto terrainGroup = &terrain->terrainGroups[i];

if (terrainGroup->mesh)
{
DrawCollision(terrainGroup);
}
}
}

void Draw::DrawCollision(TerrainGroup* terrainGroup)
{
auto mesh = terrainGroup->mesh;

// Draw all mesh faces
for (int i = 0; i < mesh->m_numFaces; i++)
{
auto face = &mesh->m_faces[i];

// Get the position of every vertice in world coordinates
auto x = GetVertice<MeshVertex>(face->i0, mesh, &mesh->m_position);
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));
}
}

void Draw::DrawPortals(Level* level)
Expand Down Expand Up @@ -231,6 +272,30 @@ void Draw::DrawPortals(Level* level)

void Draw::DrawSignals(Level* level)
{
auto terrain = level->terrain;
auto terrainGroup = terrain->signalTerrainGroup;

// Make sure there is a signal mesh
if (!terrainGroup || !terrainGroup->mesh)
{
return;
}

auto mesh = terrainGroup->mesh;

// Draw all mesh faces
for (int i = 0; i < mesh->m_numFaces; i++)
{
auto face = (SignalFace*)&mesh->m_faces[i];

// Get the position of every vertice in world coordinates
auto x = GetVertice<MeshVertex32>(face->i0, mesh, &mesh->m_position);
auto y = GetVertice<MeshVertex32>(face->i1, mesh, &mesh->m_position);
auto z = GetVertice<MeshVertex32>(face->i2, mesh, &mesh->m_position);

// Draw the face
DrawTriangle(&x, &y, &z, RGBA(255, 0, 0, 10));
}
}

#endif
15 changes: 15 additions & 0 deletions src/render/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ void DRAW_DrawTriangles(int flags, int tpage, DRAWVERTEX* verts, int numtris)
Hooking::Call(addr, flags, tpage, verts, numtris);
}

void DrawTriangle(cdc::Vector3* v0, cdc::Vector3* v1, cdc::Vector3* v2, int color)
{
DRAWVERTEX verts[3];

TRANS_TransToDrawVertexV4f(verts, v0);
TRANS_TransToDrawVertexV4f(&verts[1], v1);
TRANS_TransToDrawVertexV4f(&verts[2], v2);

verts[0].color = color;
verts[1].color = color;
verts[2].color = color;

DRAW_DrawTriangles(2, 0, verts, 1);
}

void DrawPlane(cdc::Vector3* v0, cdc::Vector3* v1, int color)
{
DRAWVERTEX verts[6];
Expand Down
1 change: 1 addition & 0 deletions src/render/Draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ void TRANS_RotTransPersVectorf(cdc::Vector3* srcvector, cdc::Vector3* dstvector)
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);

0 comments on commit 6eda1d0

Please sign in to comment.