rotate cube (y)

This commit is contained in:
Bixilon 2023-03-28 14:36:16 +02:00
parent 453d0e1a08
commit 8b558b37fb
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -38,39 +38,23 @@ data class SingleBlockStateApply(
val y: Int = 0, val y: Int = 0,
) : BlockStateApply { ) : BlockStateApply {
/*
private fun FloatArray.rotateUp(count: Int): FloatArray { private fun FloatArray.rotateY(count: Int) {
if (count == 0) return this if (count == 0) return
val a = this.map { it - 0.5f }.toFloatArray()
val b = when (count) { fun FloatArray.rotateOffsetY(offset: Int) {
1 -> floatArrayOf(a[2], a[1], -a[0], a[5], a[4], -a[3], a[8], a[7], -a[6], a[11], a[10], -a[9]) val x = this[offset + 0]
else -> this val z = this[offset + 2]
this[offset + 0] = -z + 1.0f // translates to origin and back; same as -(z-0.5f) + 0.5f
this[offset + 2] = x
} }
val c = b.pushRight(3, -count)
val d = c.map { it + 0.5f }.toFloatArray()
return d
}
*/
private fun FloatArray.rotateOffset(offset: Int) {
val x = this[offset + 0]
val y = this[offset + 2]
this[offset + 0] = -y + 1.0f // translates to origin and back; same as (y-0.5f) + 0.5f
this[offset + 2] = x
}
private fun FloatArray.rotateY(count: Int, negative: Boolean): FloatArray {
if (count == 0) return this
for (c in 0 until count) { for (c in 0 until count) {
for (i in 0 until 4) { for (i in 0 until 4) {
rotateOffset(i * 3) rotateOffsetY(i * 3)
} }
} }
return this.pushRight(3, if (negative) -count else count)
} }
@ -89,9 +73,16 @@ data class SingleBlockStateApply(
} }
var positions = positions(rotatedDirection, element.from, element.to) var positions = positions(direction, element.from, element.to)
positions.rotateY(y)
if (direction.axis == Axes.Y) { if (direction.axis == Axes.Y) {
positions = positions.rotateY(y, direction.negative) positions = positions.pushRight(3, if (direction.negative) -y else y)
} else {
if ((direction.axis == Axes.Z && (y == 2 || y == 3))) {
positions = positions.pushRight(3, if (direction.negative) -1 else 1)
} else if (direction.axis == Axes.X && (y == 1 || y == 2)) {
positions = positions.pushRight(3, if (direction.negative) 1 else -1)
}
} }
var uv = face.uv.toArray(rotatedDirection, face.rotation) var uv = face.uv.toArray(rotatedDirection, face.rotation)