Improve line renderer
This commit is contained in:
@@ -110,7 +110,7 @@ object AncestralSpadeSolver : SubscriptionOwner {
|
|||||||
}
|
}
|
||||||
if (particlePositions.size > 2 && lastDing.passedTime() < 10.seconds && nextGuess != null) {
|
if (particlePositions.size > 2 && lastDing.passedTime() < 10.seconds && nextGuess != null) {
|
||||||
color(0f, 1f, 0f, 0.7f)
|
color(0f, 1f, 0f, 0.7f)
|
||||||
line(*particlePositions.toTypedArray())
|
line(particlePositions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,12 +151,24 @@ class RenderInWorldContext private constructor(
|
|||||||
|
|
||||||
fun line(points: List<Vec3d>, lineWidth: Float = 10F) {
|
fun line(points: List<Vec3d>, lineWidth: Float = 10F) {
|
||||||
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
|
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram)
|
||||||
RenderSystem.lineWidth(lineWidth / pow(camera.pos.squaredDistanceTo(points.first()), 0.25).toFloat())
|
RenderSystem.lineWidth(lineWidth)
|
||||||
buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES)
|
buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES)
|
||||||
buffer.fixedColor(255, 255, 255, 255)
|
buffer.fixedColor(255, 255, 255, 255)
|
||||||
|
|
||||||
|
val matrix = matrixStack.peek()
|
||||||
|
var lastNormal: Vector3f? = null
|
||||||
points.zipWithNext().forEach { (a, b) ->
|
points.zipWithNext().forEach { (a, b) ->
|
||||||
doLine(matrixStack.peek(), buffer, a.x, a.y, a.z, b.x, b.y, b.z)
|
val normal = Vector3f(b.x.toFloat(), b.y.toFloat(), b.z.toFloat())
|
||||||
|
.sub(a.x.toFloat(), a.y.toFloat(), a.z.toFloat())
|
||||||
|
.normalize()
|
||||||
|
val lastNormal0 = lastNormal ?: normal
|
||||||
|
lastNormal = normal
|
||||||
|
buffer.vertex(matrix.positionMatrix, a.x.toFloat(), a.y.toFloat(), a.z.toFloat())
|
||||||
|
.normal(matrix, lastNormal0.x, lastNormal0.y, lastNormal0.z)
|
||||||
|
.next()
|
||||||
|
buffer.vertex(matrix.positionMatrix, b.x.toFloat(), b.y.toFloat(), b.z.toFloat())
|
||||||
|
.normal(matrix, normal.x, normal.y, normal.z)
|
||||||
|
.next()
|
||||||
}
|
}
|
||||||
buffer.unfixColor()
|
buffer.unfixColor()
|
||||||
|
|
||||||
@@ -167,20 +179,22 @@ class RenderInWorldContext private constructor(
|
|||||||
private fun doLine(
|
private fun doLine(
|
||||||
matrix: MatrixStack.Entry,
|
matrix: MatrixStack.Entry,
|
||||||
buf: BufferBuilder,
|
buf: BufferBuilder,
|
||||||
i: Number,
|
i: Float,
|
||||||
j: Number,
|
j: Float,
|
||||||
k: Number,
|
k: Float,
|
||||||
x: Number,
|
x: Float,
|
||||||
y: Number,
|
y: Float,
|
||||||
z: Number
|
z: Float
|
||||||
) {
|
) {
|
||||||
val normal = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
|
val normal = Vector3f(x, y, z)
|
||||||
.sub(i.toFloat(), j.toFloat(), k.toFloat())
|
.sub(i, j, k)
|
||||||
.normalize()
|
.normalize()
|
||||||
buf.vertex(matrix.positionMatrix, i.toFloat(), j.toFloat(), k.toFloat())
|
buf.vertex(matrix.positionMatrix, i, j, k)
|
||||||
.normal(matrix, normal.x, normal.y, normal.z).next()
|
.normal(matrix, normal.x, normal.y, normal.z)
|
||||||
buf.vertex(matrix.positionMatrix, x.toFloat(), y.toFloat(), z.toFloat())
|
.next()
|
||||||
.normal(matrix, normal.x, normal.y, normal.z).next()
|
buf.vertex(matrix.positionMatrix, x, y, z)
|
||||||
|
.normal(matrix, normal.x, normal.y, normal.z)
|
||||||
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,9 +204,11 @@ class RenderInWorldContext private constructor(
|
|||||||
|
|
||||||
for (i in 0..1) {
|
for (i in 0..1) {
|
||||||
for (j in 0..1) {
|
for (j in 0..1) {
|
||||||
doLine(matrix, buf, 0, i, j, 1, i, j)
|
val i = i.toFloat()
|
||||||
doLine(matrix, buf, i, 0, j, i, 1, j)
|
val j = j.toFloat()
|
||||||
doLine(matrix, buf, i, j, 0, i, j, 1)
|
doLine(matrix, buf, 0F, i, j, 1F, i, j)
|
||||||
|
doLine(matrix, buf, i, 0F, j, i, 1F, j)
|
||||||
|
doLine(matrix, buf, i, j, 0F, i, j, 1F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.unfixColor()
|
buf.unfixColor()
|
||||||
|
|||||||
Reference in New Issue
Block a user