2021-02-19 04:12:43 +00:00
|
|
|
package net.shadowfacts.cacao.view
|
|
|
|
|
|
|
|
import net.minecraft.client.util.math.MatrixStack
|
|
|
|
import net.shadowfacts.cacao.geometry.BezierCurve
|
|
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
|
|
import net.shadowfacts.cacao.util.Color
|
|
|
|
import net.shadowfacts.cacao.util.RenderHelper
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class BezierCurveView(val curve: BezierCurve): View() {
|
|
|
|
|
|
|
|
private val points by lazy {
|
|
|
|
val step = 0.05
|
|
|
|
var t = 0.0
|
|
|
|
val points = mutableListOf<Point>()
|
|
|
|
while (t <= 1) {
|
|
|
|
points.add(curve.point(t))
|
|
|
|
t += step
|
|
|
|
}
|
|
|
|
points
|
|
|
|
}
|
|
|
|
|
|
|
|
var lineWidth = 3f
|
|
|
|
var lineColor = Color.BLACK
|
|
|
|
|
|
|
|
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
2021-12-22 23:59:51 +00:00
|
|
|
matrixStack.push()
|
|
|
|
matrixStack.scale(bounds.width.toFloat(), bounds.height.toFloat(), 1f)
|
2021-02-19 04:12:43 +00:00
|
|
|
for ((index, point) in points.withIndex()) {
|
|
|
|
val next = points.getOrNull(index + 1) ?: break
|
|
|
|
RenderHelper.drawLine(point, next, zIndex, lineWidth, lineColor)
|
|
|
|
}
|
2021-12-22 23:59:51 +00:00
|
|
|
matrixStack.pop()
|
2021-02-19 04:12:43 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 23:59:51 +00:00
|
|
|
}
|