Skip to content

Commit

Permalink
Improve visualization of object collision triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli2 committed Jul 14, 2017
1 parent df00f94 commit 970fa41
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
76 changes: 68 additions & 8 deletions src/graphics/DrawDebug.cpp
Expand Up @@ -366,28 +366,88 @@ static void drawDebugFogs() {
}
}

// TODO remove too similar colors
static const Color distinctDebugColors[] = {
Color(230, 25, 75), // Red
Color( 60, 180, 75), // Green
Color(255, 225, 25), // Yellow
Color( 0, 130, 200), // Blue
Color(245, 130, 48), // Orange
Color(145, 30, 180), // Purple
Color( 70, 240, 240), // Cyan
Color(240, 50, 230), // Magenta
Color(250, 190, 190), // Pink
Color( 0, 128, 128), // Teal
Color(230, 190, 255), // Lavender
Color(170, 110, 40), // Brown
Color(255, 250, 200), // Beige
Color(128, 0, 0), // Maroon
Color(170, 255, 195), // Mint
Color(128, 128, 0), // Olive
Color(255, 215, 180), // Coral
Color( 0, 0, 128) // Navy
};

#include <boost/lexical_cast.hpp>

static void drawColorChart() {
Vec2f p = Vec2f(50, 50);
for(size_t i = 0; i < ARRAY_SIZE(distinctDebugColors); i++) {
drawLine(p, p + Vec2f(40, 0), 1.f, distinctDebugColors[i]);

drawTextCentered(hFontDebug, p + Vec2f(-5, 0), boost::lexical_cast<std::string>(i), Color::white);

p += Vec2i(0, 12);
}
}


//! Debug function to show the physical box of an object
static void drawDebugCollisionShape(EERIE_3DOBJ * obj) {

if(!obj || !obj->pbox) {
return;
}

Sphere sphere;
sphere.origin = obj->pbox->vert[0].pos;
sphere.radius = obj->pbox->radius;
drawLineSphere(sphere, Color::white);
drawColorChart();

Color shapeColor = Color::yellow;

if(obj->pbox->active == 2) {
shapeColor = Color::green;
}

for(size_t k = 0; k + 1 < obj->pbox->vert.size(); k++) {
drawLine(obj->pbox->vert[k].pos, obj->pbox->vert[k+1].pos, shapeColor);
}

Sphere sphere;
sphere.origin = obj->pbox->vert[0].pos;
sphere.radius = obj->pbox->radius;
drawLineSphere(sphere, shapeColor);

boost::array<PHYSVERT, 15> v = obj->pbox->vert;
const Color * c = distinctDebugColors;

// Vert indices copied from
// IsObjectVertexCollidingTriangle

//TOP
drawLineTriangle(v[1].pos, v[2].pos, v[3].pos, c[0]);
//BOTTOM
drawLineTriangle(v[10].pos, v[9].pos, v[11].pos, c[1]);
//UP/FRONT
drawLineTriangle(v[1].pos, v[4].pos, v[5].pos, c[2]);
//DOWN/FRONT
drawLineTriangle(v[5].pos, v[8].pos, v[9].pos, c[3]);
//UP/BACK
drawLineTriangle(v[3].pos, v[2].pos, v[7].pos, c[4]);
//DOWN/BACK
drawLineTriangle(v[7].pos, v[6].pos, v[11].pos, c[5]);
//UP/LEFT
drawLineTriangle(v[6].pos, v[2].pos, v[1].pos, c[6]);
//DOWN/LEFT
drawLineTriangle(v[10].pos, v[6].pos, v[5].pos, c[7]);
//UP/RIGHT
drawLineTriangle(v[4].pos, v[3].pos, v[7].pos, c[8]);
//DOWN/RIGHT
drawLineTriangle(v[8].pos, v[7].pos, v[11].pos, c[9]);
}

static void drawDebugEntityPhysicsCylinder(Entity * io) {
Expand Down
6 changes: 6 additions & 0 deletions src/graphics/DrawLine.cpp
Expand Up @@ -179,3 +179,9 @@ void drawLineCross(Vec3f v, Color c, float size) {
drawLine(v - Vec3f(0, size, 0), v + Vec3f(0, size, 0), c);
drawLine(v - Vec3f(0, 0, size), v + Vec3f(0, 0, size), c);
}

void drawLineTriangle(Vec3f v0, Vec3f v1, Vec3f v2, Color color) {
drawLine(v0, v1, color);
drawLine(v1, v2, color);
drawLine(v2, v0, color);
}
1 change: 1 addition & 0 deletions src/graphics/DrawLine.h
Expand Up @@ -35,5 +35,6 @@ void drawLineSphere(const Sphere & sphere, Color color);
void drawLineCylinder(const Cylinder & cyl, Color col);
void drawLineCross(Vec2f v, float z, Color color, float size);
void drawLineCross(Vec3f v, Color c, float size = 1.f);
void drawLineTriangle(Vec3f v0, Vec3f v1, Vec3f v2, Color color);

#endif // ARX_GRAPHICS_DRAWLINE_H

0 comments on commit 970fa41

Please sign in to comment.