mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
rendering: outsource zoom keybinding
This commit is contained in:
parent
f512188c3c
commit
b80d8a0379
@ -12,7 +12,6 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
|||||||
import glm_.glm
|
import glm_.glm
|
||||||
import glm_.mat4x4.Mat4
|
import glm_.mat4x4.Mat4
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
import org.lwjgl.glfw.GLFW.*
|
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
@ -44,6 +43,7 @@ class Camera(private val connection: Connection, private var fov: Float, private
|
|||||||
private var keyFlyUp = false
|
private var keyFlyUp = false
|
||||||
private var keyFlyDown = false
|
private var keyFlyDown = false
|
||||||
private var keySprintDown = false
|
private var keySprintDown = false
|
||||||
|
private var keyZoomDown = false
|
||||||
|
|
||||||
fun mouseCallback(xPos: Double, yPos: Double) {
|
fun mouseCallback(xPos: Double, yPos: Double) {
|
||||||
var xOffset = xPos - this.lastMouseX
|
var xOffset = xPos - this.lastMouseX
|
||||||
@ -92,6 +92,9 @@ class Camera(private val connection: Connection, private var fov: Float, private
|
|||||||
renderWindow.registerKeyCallback(ModIdentifier("minosoft:sprint")) { keyCodes: KeyCodes, keyAction: KeyBinding.KeyAction ->
|
renderWindow.registerKeyCallback(ModIdentifier("minosoft:sprint")) { keyCodes: KeyCodes, keyAction: KeyBinding.KeyAction ->
|
||||||
keySprintDown = keyAction == KeyBinding.KeyAction.PRESS
|
keySprintDown = keyAction == KeyBinding.KeyAction.PRESS
|
||||||
}
|
}
|
||||||
|
renderWindow.registerKeyCallback(ModIdentifier("minosoft:zoom")) { keyCodes: KeyCodes, keyAction: KeyBinding.KeyAction ->
|
||||||
|
keyZoomDown = keyAction == KeyBinding.KeyAction.PRESS
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleInput(deltaTime: Double) {
|
fun handleInput(deltaTime: Double) {
|
||||||
@ -127,7 +130,7 @@ class Camera(private val connection: Connection, private var fov: Float, private
|
|||||||
}
|
}
|
||||||
|
|
||||||
val lastZoom = zoom
|
val lastZoom = zoom
|
||||||
zoom = if (glfwGetKey(windowId, GLFW_KEY_C) == GLFW_PRESS) {
|
zoom = if (keyZoomDown) {
|
||||||
2f
|
2f
|
||||||
} else {
|
} else {
|
||||||
0f
|
0f
|
||||||
@ -155,7 +158,7 @@ class Camera(private val connection: Connection, private var fov: Float, private
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateProjectionMatrix(screenWidth: Int, screenHeight: Int): Mat4 {
|
private fun calculateProjectionMatrix(screenWidth: Int, screenHeight: Int): Mat4 {
|
||||||
return glm.perspective(glm.radians(fov / (zoom + 1.0f)), screenWidth.toFloat() / screenHeight.toFloat(), 0.1f, 1000f)
|
return glm.perspective(glm.radians(fov / (zoom + 1.0f)), screenWidth.toFloat() / screenHeight.toFloat(), 0.2f, 1000f)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recalculateViewMatrix() {
|
private fun recalculateViewMatrix() {
|
||||||
|
@ -21,7 +21,8 @@ import de.bixilon.minosoft.protocol.protocol.Packets
|
|||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
|
||||||
class PacketClientSettings(val locale: String = "en_US", val renderDistance: Int = 10, val mainHand: Hands = Hands.MAIN_HAND, val disableTextFiltering: Boolean = true) : ServerboundPacket {
|
class PacketClientSettings(private val locale: String = "en_US", private val renderDistance: Int = 10, private val mainHand: Hands = Hands.MAIN_HAND, private val disableTextFiltering: Boolean = true) : ServerboundPacket {
|
||||||
|
|
||||||
override fun write(connection: Connection): OutPacketBuffer {
|
override fun write(connection: Connection): OutPacketBuffer {
|
||||||
val buffer = OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLIENT_SETTINGS)
|
val buffer = OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLIENT_SETTINGS)
|
||||||
buffer.writeString(locale) // locale
|
buffer.writeString(locale) // locale
|
||||||
|
@ -77,6 +77,16 @@
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"minosoft:zoom": {
|
||||||
|
"change": [
|
||||||
|
"C"
|
||||||
|
],
|
||||||
|
"when": [
|
||||||
|
[
|
||||||
|
"minosoft:in_game"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
"minosoft:debug_screen": {
|
"minosoft:debug_screen": {
|
||||||
"release": [
|
"release": [
|
||||||
"F3"
|
"F3"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user