diff options
| author | Lorenz <lo.scherf@gmail.com> | 2022-08-06 11:46:08 +0200 |
|---|---|---|
| committer | Lorenz <lo.scherf@gmail.com> | 2022-08-06 11:46:08 +0200 |
| commit | 7829de2d99c04858b5bfb156f66cdc17212561d4 (patch) | |
| tree | 949cf71ede55fbb7ee33bfec0fcf9ec32873b8d5 /src/main/java/at/hannibal2/skyhanni/utils | |
| parent | 1c2cfc5b3ed788739ca6da6899b2e662b5c21308 (diff) | |
| download | SkyHanni-7829de2d99c04858b5bfb156f66cdc17212561d4.tar.gz SkyHanni-7829de2d99c04858b5bfb156f66cdc17212561d4.tar.bz2 SkyHanni-7829de2d99c04858b5bfb156f66cdc17212561d4.zip | |
Merge branch 'master' of C:\Users\Lorenz\IdeaProjects\SkyHanni with conflicts.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index bfc5f7228..510b04fb8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -2,16 +2,22 @@ package at.hannibal2.skyhanni.utils import net.minecraft.entity.Entity import net.minecraft.util.BlockPos +import net.minecraft.util.Rotations import net.minecraft.util.Vec3 +import kotlin.math.cos import kotlin.math.pow +import kotlin.math.sin data class LorenzVec( val x: Double, val y: Double, - val z: Double + val z: Double, ) { + constructor(x: Int, y: Int, z: Int) : this(x.toDouble(), y.toDouble(), z.toDouble()) + constructor(x: Float, y: Float, z: Float) : this(x.toDouble(), y.toDouble(), z.toDouble()) + fun toBlocPos(): BlockPos = BlockPos(x, y, z) fun toVec3(): Vec3 = Vec3(x, y, z) @@ -47,6 +53,18 @@ data class LorenzVec( LorenzVec(x multiplyZeroSave d.toDouble(), y multiplyZeroSave d.toDouble(), z multiplyZeroSave d.toDouble()) fun add(other: LorenzVec) = LorenzVec(x + other.x, y + other.y, z + other.z) + + companion object { + fun getFromYawPitch(yaw: Double, pitch: Double): LorenzVec { + val yaw: Double = (yaw + 90) * Math.PI / 180 + val pitch: Double = (pitch + 90) * Math.PI / 180 + + val x = sin(pitch) * cos(yaw) + val y = sin(pitch) * sin(yaw) + val z = cos(pitch) + return LorenzVec(x, z, y) + } + } } private infix fun Double.multiplyZeroSave(other: Double): Double { @@ -58,4 +76,6 @@ fun BlockPos.toLorenzVec(): LorenzVec = LorenzVec(x, y, z) fun Entity.getLorenzVec(): LorenzVec = LorenzVec(posX, posY, posZ) -fun Vec3.toLorenzVec(): LorenzVec = LorenzVec(xCoord, yCoord, zCoord)
\ No newline at end of file +fun Vec3.toLorenzVec(): LorenzVec = LorenzVec(xCoord, yCoord, zCoord) + +fun Rotations.toLorenzVec(): LorenzVec = LorenzVec(x, y, z)
\ No newline at end of file |
