diff --git a/src/debug/lines.cpp b/src/debug/lines.cpp index da4be93d..2021409e 100644 --- a/src/debug/lines.cpp +++ b/src/debug/lines.cpp @@ -18,56 +18,191 @@ namespace lol { //Resets draw infos -void Debug::ResetDrawSetup() +void Debug::DrawSetupReset() { g_scene->SetLineTime(); g_scene->SetLineMask(); } //Sets draw infos -void Debug::DrawSetup(float new_time) +void Debug::DrawSetupTime(float new_time) { g_scene->SetLineTime(new_time); } -void Debug::DrawSetup(int new_mask) + +//-- +void Debug::DrawSetupMask(int new_mask) { g_scene->SetLineMask(new_mask); } -void Debug::DrawSetup(float new_time, int new_mask) + +//-- +void Debug::DrawSetupSegment(float new_segment_size) { - g_scene->SetLineTime(new_time); - g_scene->SetLineMask(new_mask); + g_scene->SetLineSegmentSize(new_segment_size); } -void Debug::DrawLine(vec3 a, vec3 b, vec4 color) +//-- +void Debug::DrawSetupColor(vec4 color) { - g_scene->AddLine(a, b, color); + g_scene->SetLineColor(color); } +//-- +void Debug::DrawSetup(float new_time, int new_mask, float segment_size, vec4 color) +{ + Debug::DrawSetupTime(new_time); + Debug::DrawSetupMask(new_mask); + Debug::DrawSetupSegment(segment_size); + Debug::DrawSetupColor(color); +} + +//Draw stuff +void Debug::DrawLine(vec3 a, vec3 b) +{ + Debug::DrawLine(a, b, g_scene->GetLineColor()); +} +void Debug::DrawLine(vec3 a, vec3 b, vec4 color) +{ g_scene->AddLine(a, b, color); } + +//-- +void Debug::DrawBox(box3 a) +{ DrawBox(a.A, a.B, g_scene->GetLineColor()); } void Debug::DrawBox(box3 a, vec4 color) { DrawBox(a.A, a.B, color); } +//-- +void Debug::DrawBox(vec3 a, vec3 b) +{ Debug::DrawBox(a, b, g_scene->GetLineColor()); } void Debug::DrawBox(vec3 a, vec3 b, vec4 color) { - vec3 v[8]; + Debug::DrawBox(a, b, mat4::identity, color); +} + +//-- +void Debug::DrawBox(box3 a, mat4 transform) +{ DrawBox(a.A, a.B, transform, g_scene->GetLineColor()); } +void Debug::DrawBox(box3 a, mat4 transform, vec4 color) +{ + DrawBox(a.A, a.B, transform, color); +} + +//-- +void Debug::DrawBox(vec3 a, vec3 b, mat4 transform) +{ Debug::DrawBox(a, b, transform, g_scene->GetLineColor()); } +void Debug::DrawBox(vec3 a, vec3 b, mat4 transform, vec4 color) +{ + vec4 v[8]; for (int i = 0; i < 8; i++) { v[i].x = i & 1 ? a.x : b.x; v[i].y = i & 2 ? a.y : b.y; v[i].z = i & 4 ? a.z : b.z; + v[i].w = 1.f; } for (int i = 0; i < 4; i++) { int j = ((i & 1) << 1) | ((i >> 1) ^ 1); - Debug::DrawLine(v[i], v[i + 4], color); - Debug::DrawLine(v[i], v[j], color); - Debug::DrawLine(v[i + 4], v[j + 4], color); + Debug::DrawLine((transform * v[i]).xyz, (transform * v[i + 4]).xyz, color); + Debug::DrawLine((transform * v[i]).xyz, (transform * v[j]).xyz, color); + Debug::DrawLine((transform * v[i + 4]).xyz, (transform * v[j + 4]).xyz, color); + } +} + +//-- +void Debug::DrawCircle(vec3 a, vec3 n) +{ Debug::DrawCircle(a, n, g_scene->GetLineColor()); } +void Debug::DrawCircle(vec3 a, vec3 n, vec4 color) +{ + vec3 x = orthogonal(n); + vec3 y = cross(normalize(n), normalize(x)) * length(n); + DrawCircle(a, x, y, color); +} + +//-- +void Debug::DrawCircle(vec3 a, vec3 x, vec3 y) +{ Debug::DrawCircle(a, x, y, g_scene->GetLineColor()); } +void Debug::DrawCircle(vec3 a, vec3 x, vec3 y, vec4 color) +{ + float size = F_PI * 2.f * lol::max(length(x), length(y)); + int segment_nb = lol::max(1, (int)((size * .25f) / g_scene->GetLineSegmentSize())); + for (int i = 0; i < segment_nb; i++) + { + float a0 = (((float)i) / (float)segment_nb) * F_PI_2; + float a1 = (((float)i + 1) / (float)segment_nb) * F_PI_2; + vec2 p0 = vec2(lol::cos(a0), lol::sin(a0)); + vec2 p1 = vec2(lol::cos(a1), lol::sin(a1)); + + Debug::DrawLine(a + p0.x * x + p0.y * y, a + p1.x * x + p1.y * y, color); + Debug::DrawLine(a + p0.x * -x + p0.y * -y, a + p1.x * -x + p1.y * -y, color); + Debug::DrawLine(a + p0.x * x + p0.y * -y, a + p1.x * x + p1.y * -y, color); + Debug::DrawLine(a + p0.x * -x + p0.y * y, a + p1.x * -x + p1.y * y, color); + } +} + +//-- +void Debug::DrawSphere(vec3 a, float s) +{ Debug::DrawSphere(a, s, g_scene->GetLineColor()); } +void Debug::DrawSphere(vec3 a, float s, vec4 color) +{ + Debug::DrawSphere(a, vec3::axis_x * s, vec3::axis_y * s, vec3::axis_z * s, color); +} + +//-- +void Debug::DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z) +{ Debug::DrawSphere(a, x, y, z, g_scene->GetLineColor()); } +void Debug::DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z, vec4 color) +{ + Debug::DrawCircle(a, x, y, color); + Debug::DrawCircle(a, y, z, color); + Debug::DrawCircle(a, z, x, color); +} + +//-- +void Debug::DrawCapsule(vec3 a, float s, vec3 h) +{ Debug::DrawCapsule(a, s, h, g_scene->GetLineColor()); } +void Debug::DrawCapsule(vec3 a, float s, vec3 h, vec4 color) +{ + vec3 x = orthonormal(h) * s; + vec3 y = cross(normalize(h), normalize(x)) * s; + Debug::DrawCapsule(a, x, y, normalize(h) * s, h, color); +} + +//-- +void Debug::DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h) +{ Debug::DrawCapsule(a, x, y, z, h, g_scene->GetLineColor()); } +void Debug::DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h, vec4 color) +{ + float size = F_PI * 2.f * lol::max(length(x), length(y)); + int segment_nb = lol::max(1, (int)((size * .25f) / g_scene->GetLineSegmentSize())); + for (int i = -1; i < 2; i += 2) + { + vec3 b = a + h * .5f * (float)i; + vec3 c = a - h * .5f * (float)i; + Debug::DrawCircle(b, x, y, color); + Debug::DrawLine(b + x * (float)i, c + x * (float)i, color); + Debug::DrawLine(b + y * (float)i, c + y * (float)i, color); + for (int j = 0; j < segment_nb; j++) + { + float a0 = (((float)j) / (float)segment_nb) * F_PI_2; + float a1 = (((float)j + 1) / (float)segment_nb) * F_PI_2; + vec2 p0 = vec2(lol::cos(a0), lol::sin(a0)); + vec2 p1 = vec2(lol::cos(a1), lol::sin(a1)); + + Debug::DrawLine(b + p0.x * x + p0.y * z * (float)i, b + p1.x * x + p1.y * z * (float)i, color); + Debug::DrawLine(b + p0.x * -x + p0.y * z * (float)i, b + p1.x * -x + p1.y * z * (float)i, color); + Debug::DrawLine(b + p0.x * y + p0.y * z * (float)i, b + p1.x * y + p1.y * z * (float)i, color); + Debug::DrawLine(b + p0.x * -y + p0.y * z * (float)i, b + p1.x * -y + p1.y * z * (float)i, color); + } } } +//-- +void Debug::DrawViewProj(mat4 view, mat4 proj) +{ Debug::DrawViewProj(view, proj, g_scene->GetLineColor()); } void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) { mat4 const view_proj = proj * view; @@ -91,6 +226,9 @@ void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) Debug::DrawViewProj(view_proj, color); } +//-- +void Debug::DrawViewProj(mat4 view_proj) +{ Debug::DrawViewProj(view_proj, g_scene->GetLineColor()); } void Debug::DrawViewProj(mat4 view_proj, vec4 color) { //Near plane diff --git a/src/lol/debug/lines.h b/src/lol/debug/lines.h index b68915a2..4f381769 100644 --- a/src/lol/debug/lines.h +++ b/src/lol/debug/lines.h @@ -25,16 +25,40 @@ namespace Debug { //Resets draw infos -void ResetDrawSetup(); +void DrawSetupReset(); //Sets draw infos -void DrawSetup(float new_time); -void DrawSetup(int new_mask); -void DrawSetup(float new_time, int new_mask); +void DrawSetupTime(float new_time); +void DrawSetupMask(int new_mask); +void DrawSetupSegment(float segment_size); +void DrawSetupColor(vec4 color); +void DrawSetup(float new_time, int new_mask, float segment_size, vec4 color); +//Draw stuff in World +void DrawLine(vec3 a, vec3 b); void DrawLine(vec3 a, vec3 b, vec4 color); +void DrawBox(box3 a); void DrawBox(box3 a, vec4 color); +void DrawBox(vec3 a, vec3 b); void DrawBox(vec3 a, vec3 b, vec4 color); +void DrawBox(box3 a, mat4 transform); +void DrawBox(box3 a, mat4 transform, vec4 color); +void DrawBox(vec3 a, vec3 b, mat4 transform); +void DrawBox(vec3 a, vec3 b, mat4 transform, vec4 color); +void DrawCircle(vec3 a, vec3 n); +void DrawCircle(vec3 a, vec3 n, vec4 color); +void DrawCircle(vec3 a, vec3 x, vec3 y); +void DrawCircle(vec3 a, vec3 x, vec3 y, vec4 color); +void DrawSphere(vec3 a, float s); +void DrawSphere(vec3 a, float s, vec4 color); +void DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z); +void DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z, vec4 color); +void DrawCapsule(vec3 a, float s, vec3 h); +void DrawCapsule(vec3 a, float s, vec3 h, vec4 color); +void DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h); +void DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h, vec4 color); +void DrawViewProj(mat4 view_proj); void DrawViewProj(mat4 view_proj, vec4 color); +void DrawViewProj(mat4 view, mat4 proj); void DrawViewProj(mat4 view, mat4 proj, vec4 color); } /* namespace Debug */ diff --git a/src/scene.cpp b/src/scene.cpp index 832de7ef..5cea8080 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -62,6 +62,8 @@ private: /* Old API */ float m_new_line_time; int m_new_line_mask; + float m_new_line_segment_size; + vec4 m_new_line_color; Array m_lines; int m_debug_mask; Shader *m_line_shader; @@ -99,8 +101,11 @@ Scene::Scene(ivec2 size) data->m_line_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position, VertexUsage::Color)); data->m_debug_mask = 1; + SetLineTime(); SetLineMask(); + SetLineSegmentSize(); + SetLineColor(); } Scene::~Scene() @@ -180,14 +185,12 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) data->m_tiles.Push(t); } -void Scene::SetLineTime(float new_time) -{ - data->m_new_line_time = new_time; -} -void Scene::SetLineMask(int new_mask) -{ - data->m_new_line_mask = new_mask; -} +void Scene::SetLineTime(float new_time) { data->m_new_line_time = new_time; } +void Scene::SetLineMask(int new_mask) { data->m_new_line_mask = new_mask; } +void Scene::SetLineSegmentSize(float new_segment_size) { data->m_new_line_segment_size = new_segment_size; } +float Scene::GetLineSegmentSize() { return data->m_new_line_segment_size; } +void Scene::SetLineColor(vec4 new_color) { data->m_new_line_color = new_color; } +vec4 Scene::GetLineColor() { return data->m_new_line_color; } void Scene::AddLine(vec3 a, vec3 b, vec4 color) { diff --git a/src/scene.h b/src/scene.h index 5fb15e83..182385f6 100644 --- a/src/scene.h +++ b/src/scene.h @@ -55,6 +55,10 @@ public: void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale); void SetLineTime(float new_time=-1.f); void SetLineMask(int new_mask=0xFFFFFFFF); + void SetLineSegmentSize(float new_segment_size=100000.f); + float GetLineSegmentSize(); + void SetLineColor(vec4 new_color=vec4(1.f)); + vec4 GetLineColor(); void AddLine(vec3 a, vec3 b, vec4 color); void AddLight(Light *light);