mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
human: outsource head position
This commit is contained in:
parent
8fe94cfcaf
commit
9e6a5f9188
@ -13,29 +13,16 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.entities.model.biped
|
||||
|
||||
import de.bixilon.kotlinglm.func.rad
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.minosoft.gui.rendering.entities.feature.SkeletalFeature
|
||||
import de.bixilon.minosoft.gui.rendering.entities.model.biped.animator.HeadPosition
|
||||
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
|
||||
import de.bixilon.minosoft.gui.rendering.util.mat.mat4.Mat4Util.rotateRadAssign
|
||||
|
||||
abstract class HumanModel<R : EntityRenderer<*>>(renderer: R, model: BakedSkeletalModel) : SkeletalFeature(renderer, model) {
|
||||
val head = instance.transform.children["head"]!!
|
||||
|
||||
val head = instance.transform.children["head"]?.let { HeadPosition(this, it) }
|
||||
|
||||
override fun updatePosition() {
|
||||
super.updatePosition()
|
||||
updateHeadPosition()
|
||||
}
|
||||
|
||||
private fun updateHeadPosition() {
|
||||
val info = renderer.info
|
||||
|
||||
val pitch = info.rotation.pitch
|
||||
head.value
|
||||
.translateAssign(head.pivot)
|
||||
.rotateRadAssign(Vec3(-pitch.rad, 0.0f, 0.0f))
|
||||
.translateAssign(head.nPivot)
|
||||
head?.update()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.entities.model.biped.animator
|
||||
|
||||
import de.bixilon.kotlinglm.func.rad
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.minosoft.gui.rendering.entities.model.biped.HumanModel
|
||||
import de.bixilon.minosoft.gui.rendering.skeletal.instance.TransformInstance
|
||||
import de.bixilon.minosoft.gui.rendering.util.mat.mat4.Mat4Util.rotateRadAssign
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
||||
|
||||
class HeadPosition(
|
||||
val model: HumanModel<*>,
|
||||
val transform: TransformInstance,
|
||||
) {
|
||||
private var rotation = Vec3.EMPTY
|
||||
|
||||
fun update() {
|
||||
val info = model.renderer.info
|
||||
|
||||
val pitch = info.rotation.pitch
|
||||
this.rotation.x = -pitch.rad
|
||||
transform.value
|
||||
.translateAssign(transform.pivot)
|
||||
.rotateRadAssign(this.rotation)
|
||||
.translateAssign(transform.nPivot)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user