mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
Merge remote-tracking branch 'origin/rendering' into rendering
# Conflicts: # src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/renderable/ElementRenderer.kt
This commit is contained in:
commit
41199767b6
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
* Copyright (C) 2020 Moritz Zwerger, Lukas Eisenhauer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
@ -113,17 +113,18 @@ class Camera(private val connection: Connection, private var fov: Float) {
|
||||
|
||||
fun handleInput(deltaTime: Double) {
|
||||
var cameraSpeed = movementSpeed * deltaTime
|
||||
|
||||
val movementFront = Vec3(cameraFront)
|
||||
movementFront.y = 0f
|
||||
movementFront.normalizeAssign() // when moving forwards, do not move down
|
||||
if (keySprintDown) {
|
||||
cameraSpeed *= 5
|
||||
}
|
||||
val lastPosition = cameraPosition
|
||||
val currentY = cameraPosition.y
|
||||
if (keyForwardDown) {
|
||||
cameraPosition = cameraPosition + cameraFront * cameraSpeed
|
||||
cameraPosition = cameraPosition + movementFront * cameraSpeed
|
||||
}
|
||||
if (keyBackDown) {
|
||||
cameraPosition = cameraPosition - cameraFront * cameraSpeed
|
||||
cameraPosition = cameraPosition - movementFront * cameraSpeed
|
||||
}
|
||||
if (keyLeftDown) {
|
||||
cameraPosition = cameraPosition - cameraRight * cameraSpeed
|
||||
@ -131,7 +132,6 @@ class Camera(private val connection: Connection, private var fov: Float) {
|
||||
if (keyRightDown) {
|
||||
cameraPosition = cameraPosition + cameraRight * cameraSpeed
|
||||
}
|
||||
this.cameraPosition.y = currentY // stay on xz line when moving (aka. no clip): ToDo: make movement not slower when you look up
|
||||
if (keyFlyDown) {
|
||||
cameraPosition = cameraPosition - CAMERA_UP_VEC3 * cameraSpeed
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.Axes
|
||||
import de.bixilon.minosoft.data.Directions
|
||||
import glm_.glm
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
open class BlockModelElement(data: JsonObject) {
|
||||
@ -96,22 +97,23 @@ open class BlockModelElement(data: JsonObject) {
|
||||
Directions.NORTH to setOf(POSITION_3, POSITION_4, POSITION_7, POSITION_8),
|
||||
)
|
||||
|
||||
fun getRotatedValues(x: Float, y: Float, sin: Double, cos: Double): Vec2 {
|
||||
return Vec2((x * cos - y * sin).toFloat(), (x * sin + y * cos).toFloat())
|
||||
}
|
||||
|
||||
fun rotateVector(original: Vec3, angle: Double, axis: Axes): Vec3 {
|
||||
fun getRotatedValues(x: Float, y: Float, sin: Double, cos: Double): Pair<Float, Float> {
|
||||
return Pair((x * cos - y * sin).toFloat(), (x * sin + y * cos).toFloat())
|
||||
}
|
||||
return when (axis) {
|
||||
Axes.X -> {
|
||||
val rotatedValues = getRotatedValues(original.y, original.z, glm.sin(angle), glm.cos(angle))
|
||||
Vec3(original.x, rotatedValues.first, rotatedValues.second)
|
||||
Vec3(original.x, rotatedValues)
|
||||
}
|
||||
Axes.Y -> {
|
||||
val rotatedValues = getRotatedValues(original.x, original.z, glm.sin(angle), glm.cos(angle))
|
||||
Vec3(rotatedValues.first, original.y, rotatedValues.second)
|
||||
Vec3(rotatedValues.x, original.y, rotatedValues.y)
|
||||
}
|
||||
Axes.Z -> {
|
||||
val rotatedValues = getRotatedValues(original.x, original.y, glm.sin(angle), glm.cos(angle))
|
||||
Vec3(rotatedValues.first, rotatedValues.second, original.z)
|
||||
Vec3(rotatedValues.x, rotatedValues.y, original.z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.models.loading
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.Directions
|
||||
import glm_.Java.Companion.glm
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3
|
||||
import java.util.*
|
||||
@ -53,10 +54,10 @@ class BlockModelFace(data: JsonObject, from: Vec3, to: Vec3, direction: Directio
|
||||
}
|
||||
}
|
||||
positions = mutableListOf(
|
||||
Vec2(uvToFloat(textureStart.x), uvToFloat(textureStart.y)),
|
||||
Vec2(uvToFloat(textureStart.x), uvToFloat(textureEnd.y)),
|
||||
Vec2(uvToFloat(textureEnd.x), uvToFloat(textureEnd.y)),
|
||||
Vec2(uvToFloat(textureEnd.x), uvToFloat(textureStart.y)),
|
||||
uvToFloat(Vec2(textureStart.x, textureStart.y)),
|
||||
uvToFloat(Vec2(textureStart.x, textureEnd.y)),
|
||||
uvToFloat(Vec2(textureEnd.x, textureEnd.y)),
|
||||
uvToFloat(Vec2(textureEnd.x, textureStart.y)),
|
||||
)
|
||||
val rotation = data["rotation"]?.asInt?.div(90) ?: 0
|
||||
Collections.rotate(positions, rotation)
|
||||
@ -71,6 +72,17 @@ class BlockModelFace(data: JsonObject, from: Vec3, to: Vec3, direction: Directio
|
||||
return result
|
||||
}
|
||||
|
||||
fun rotate(angle: Double) {
|
||||
if (angle == 0.0) {
|
||||
return
|
||||
}
|
||||
val sin = glm.sin(angle)
|
||||
val cos = glm.cos(angle)
|
||||
for (i in positions.indices) {
|
||||
val offset = positions[i] - Vec2(0.5f, 0.5f)
|
||||
positions[i] = BlockModelElement.getRotatedValues(offset.x, offset.y, sin, cos) + Vec2(0.5f, 0.5f)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun uvToFloat(uv: Float): Float {
|
||||
|
@ -30,7 +30,7 @@ import glm_.vec4.Vec4
|
||||
|
||||
class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvlock: Boolean, rescale: Boolean) {
|
||||
private val fullFaceDirections: MutableSet<Directions> = mutableSetOf()
|
||||
private val faces: MutableMap<Directions, BlockModelFace> = element.faces
|
||||
private val faces: MutableMap<Directions, BlockModelFace> = HashMap(element.faces)
|
||||
private var positions: Array<Vec3> = element.positions.clone()
|
||||
private val directionMapping: MutableMap<Directions, Directions> = mutableMapOf()
|
||||
|
||||
@ -42,6 +42,9 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvlock: Boolea
|
||||
fullFaceDirections.add(direction)
|
||||
}
|
||||
directionMapping[direction] = getRotatedDirection(rotation, direction)
|
||||
for (face in faces.values) {
|
||||
face.rotate(rotation.y.toDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +113,7 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvlock: Boolea
|
||||
val parentElements = parent.elements
|
||||
val result: MutableList<ElementRenderer> = mutableListOf()
|
||||
for (parentElement in parentElements) {
|
||||
result.add(ElementRenderer(parentElement, rotation, uvlock, rescale))
|
||||
result.add(ElementRenderer(parentElement, rotation, true, rescale)) // uvlock is not yet implemented in the data generator
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user