From ac9095b58dfa7536eedc0cb4aed6dc2b292c3918 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 1 Oct 2024 09:35:41 +0700 Subject: [PATCH] "Fix" chart rendering winding when rendering straight lines --- .../mc/otm/client/render/GraphRendering.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GraphRendering.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GraphRendering.kt index d8ef7fe50..c20392fce 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GraphRendering.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GraphRendering.kt @@ -63,16 +63,23 @@ fun renderGraph( val xDiff = x1 - x0 val yDiff = y1 - y0 - val length = (xDiff.pow(2f) + yDiff.pow(2f)).pow(0.5f) - val angle = acos(xDiff / length) * yDiff.sign - PI / 2f // rotate 90 deg + if (yDiff.sign == 0f) { + builder.vertex(pose, x0, y0 + LINE_WIDTH / 2f, 0f) + builder.vertex(pose, x0, y0 - LINE_WIDTH / 2f, 0f) + builder.vertex(pose, x1, y1 - LINE_WIDTH / 2f, 0f) + builder.vertex(pose, x1, y1 + LINE_WIDTH / 2f, 0f) + } else { + val length = (xDiff.pow(2f) + yDiff.pow(2f)).pow(0.5f) + val angle = acos(xDiff / length) * yDiff.sign - PI / 2f // rotate 90 deg - val xDisp = cos(angle).toFloat() * LINE_WIDTH / 2f - val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f + val xDisp = cos(angle).toFloat() * LINE_WIDTH / 2f + val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f - builder.vertex(pose, x1 - xDisp, y1 + yDisp, 0f) - builder.vertex(pose, x1 + xDisp, y1 - yDisp, 0f) - builder.vertex(pose, x0 + xDisp, y0 - yDisp, 0f) - builder.vertex(pose, x0 - xDisp, y0 + yDisp, 0f) + builder.vertex(pose, x0 + xDisp, y0 + yDisp, 0f) + builder.vertex(pose, x0 - xDisp, y0 - yDisp, 0f) + builder.vertex(pose, x1 - xDisp, y1 - yDisp, 0f) + builder.vertex(pose, x1 + xDisp, y1 + yDisp, 0f) + } //graphics.renderRect(x0, y0, LINE_WIDTH, LINE_WIDTH)