mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
optimize EntityRotation::front, tests
This commit is contained in:
parent
c4aa76d6d1
commit
1f2ea0ea90
@ -24,11 +24,17 @@ data class EntityRotation(
|
|||||||
val pitch: Float,
|
val pitch: Float,
|
||||||
) {
|
) {
|
||||||
val front: Vec3
|
val front: Vec3
|
||||||
get() = Vec3(
|
get() {
|
||||||
(-yaw).rad.sin * pitch.rad.cos,
|
val pitchRad = pitch.rad
|
||||||
(-pitch).rad.sin,
|
val pitchCos = pitchRad.cos
|
||||||
(-yaw).rad.cos * pitch.rad.cos
|
val yawRad = -yaw.rad
|
||||||
).normalize()
|
|
||||||
|
return Vec3(
|
||||||
|
yawRad.sin * pitchCos,
|
||||||
|
-pitchRad.sin,
|
||||||
|
yawRad.cos * pitchCos
|
||||||
|
).normalize()
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "(yaw=$yaw, pitch=$pitch)"
|
return "(yaw=$yaw, pitch=$pitch)"
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.entities
|
package de.bixilon.minosoft.data.entities
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.minosoft.data.entities.EntityRotation.Companion.interpolateYaw
|
import de.bixilon.minosoft.data.entities.EntityRotation.Companion.interpolateYaw
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@ -53,4 +54,22 @@ class EntityRotationTest {
|
|||||||
fun interpolation7() {
|
fun interpolation7() {
|
||||||
assertEquals(150.0f, interpolateYaw(0.5f, 110.0f, -170.0f))
|
assertEquals(150.0f, interpolateYaw(0.5f, 110.0f, -170.0f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun front1() {
|
||||||
|
val front = EntityRotation(10.0f, 20.0f).front
|
||||||
|
assertEquals(front, Vec3(-0.16317593, -0.34202015, 0.92541665))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun front2() {
|
||||||
|
val front = EntityRotation(-10.0f, -20.0f).front
|
||||||
|
assertEquals(front, Vec3(0.16317593, 0.34202015, 0.92541665))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun front3() {
|
||||||
|
val front = EntityRotation(-80.0f, 80.0f).front
|
||||||
|
assertEquals(front, Vec3(0.1710101, -0.9848077, 0.030153705))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user