send position to server

This commit is contained in:
Bixilon 2021-02-07 21:20:57 +01:00
parent e692620220
commit f93750dac5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 19 additions and 8 deletions

View File

@ -14,6 +14,8 @@ package de.bixilon.minosoft.data.entities
data class EntityRotation(val yaw: Float, val pitch: Float, val headYaw: Float) {
constructor(yaw: Double, pitch: Double) : this(yaw.toFloat(), pitch.toFloat(), yaw.toFloat())
override fun toString(): String {
return "(yaw=$yaw, pitch=$pitch, headYaw=$headYaw)"
}

View File

@ -13,10 +13,13 @@
package de.bixilon.minosoft.data.entities
import de.bixilon.minosoft.data.world.BlockPosition
import glm_.vec3.Vec3
data class Location(val x: Double, val y: Double, val z: Double) {
constructor(position: Vec3) : this(position.x.toDouble(), position.y.toDouble(), position.z.toDouble())
override fun toString(): String {
return "($x $y $z)"
}

View File

@ -12,11 +12,11 @@ class Camera(private var fov: Float, private val windowId: Long) {
private var mouseSensitivity = 0.1
private var movementSpeed = 7
private var cameraFront = Vec3(0.0f, 0.0f, -1.0f)
private var cameraPosition = Vec3(0.0f, 0.0f, 3.0f)
var cameraPosition = Vec3(0.0f, 0.0f, 0.0f)
private var lastMouseX = 0.0
private var lastMouseY = 0.0
private var yaw = 0.0
private var pitch = 0.0
var yaw = 0.0
var pitch = 0.0
fun mouseCallback(xPos: Double, yPos: Double) {
var xOffset = xPos - this.lastMouseX
@ -85,10 +85,6 @@ class Camera(private var fov: Float, private val windowId: Long) {
this.fov = fov
}
fun setPosition(position: Vec3) {
cameraPosition = position
}
fun setRotation(yaw: Double, pitch: Double) {
cameraFront = Vec3((cos(glm.radians(yaw)) * cos(glm.radians(pitch))).toFloat(), sin(glm.radians(pitch)).toFloat(), (sin(glm.radians(yaw)) * cos(glm.radians(pitch))).toFloat()).normalize()
}

View File

@ -1,9 +1,12 @@
package de.bixilon.minosoft.gui.rendering
import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.Location
import de.bixilon.minosoft.data.world.ChunkLocation
import de.bixilon.minosoft.gui.rendering.shader.Shader
import de.bixilon.minosoft.gui.rendering.textures.TextureArray
import de.bixilon.minosoft.protocol.network.Connection
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending
import de.bixilon.minosoft.util.CountUpAndDownLatch
import org.lwjgl.*
import org.lwjgl.glfw.Callbacks
@ -135,6 +138,8 @@ class RenderWindow(private val connection: Connection) {
var lastCalcTime = glfwGetTime()
var frameTimeLastCalc = 0.0
var lastPositionChangeTime = 0.0
while (!glfwWindowShouldClose(windowId)) {
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) // clear the framebuffer
@ -171,6 +176,11 @@ class RenderWindow(private val connection: Connection) {
}
framesLastSecond++
if (glfwGetTime() - lastPositionChangeTime > 0.05) {
// ToDo: Replace this with proper movement and only send it, when out position changed
connection.sendPacket(PacketPlayerPositionAndRotationSending(Location(camera.cameraPosition), EntityRotation(camera.yaw, camera.pitch), false))
}
for (renderQueueElement in renderQueue) {
renderQueueElement.run()

View File

@ -64,7 +64,7 @@ class Renderer(private val connection: Connection) {
fun teleport(position: Location) {
renderWindow.renderQueue.add {
renderWindow.camera.setPosition(Vec3(position.x, position.y, position.z))
renderWindow.camera.cameraPosition = Vec3(position.x, position.y, position.z)
}
}