code cleanup

This commit is contained in:
Lukas 2020-09-23 22:17:47 +02:00
parent aa6ec55792
commit 4feb25621c
28 changed files with 100 additions and 145 deletions

View File

@ -30,7 +30,7 @@ public class GameWindow {
private static Connection connection; private static Connection connection;
private static PlayerController playerController; private static PlayerController playerController;
static boolean running = false; private static boolean running = false;
public static boolean paused = false; public static boolean paused = false;
public static void prepare() { public static void prepare() {

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *
@ -28,7 +28,7 @@ import static org.lwjgl.system.MemoryUtil.NULL;
public class OpenGLWindow { public class OpenGLWindow {
private final boolean fullscreen; private final boolean fullscreen;
long window; private long window;
private int width, height; private int width, height;
private double mouseX; private double mouseX;
private double mouseY; private double mouseY;

View File

@ -32,7 +32,7 @@ public class WorldRenderer {
private BlockModelLoader modelLoader; private BlockModelLoader modelLoader;
private LinkedBlockingQueue<Pair<ChunkLocation, Chunk>> queuedChunks; private LinkedBlockingQueue<Pair<ChunkLocation, Chunk>> queuedChunks;
Thread chunkLoadThread; private Thread chunkLoadThread;
public WorldRenderer() { public WorldRenderer() {
faces = new HashMap<>(); faces = new HashMap<>();

View File

@ -23,9 +23,8 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
public class BlockConfiguration { public class BlockConfiguration {
BlockRotations rotation; private BlockRotations rotation;
HashSet<BlockProperties> blockProperties; private HashSet<BlockProperties> blockProperties;
public BlockConfiguration(JsonObject json) { public BlockConfiguration(JsonObject json) {
if (json.has("facing")) { if (json.has("facing")) {

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *

View File

@ -33,7 +33,7 @@ import static de.bixilon.minosoft.util.Util.readJsonAsset;
public class BlockModelLoader { public class BlockModelLoader {
private final HashMap<String, HashMap<String, BlockModelInterface>> blockDescriptionMap; private final HashMap<String, HashMap<String, BlockModelInterface>> blockDescriptionMap;
TextureLoader textureLoader; private TextureLoader textureLoader;
public BlockModelLoader() { public BlockModelLoader() {
blockDescriptionMap = new HashMap<>(); blockDescriptionMap = new HashMap<>();

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *
@ -18,9 +18,9 @@ import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
import de.bixilon.minosoft.render.texture.InFaceUV; import de.bixilon.minosoft.render.texture.InFaceUV;
public class Face { public class Face {
final SubBlockPosition[] positions; private final SubBlockPosition[] positions;
int rotation; private int rotation;
InFaceUV uv; private InFaceUV uv;
public Face(float texture, InFaceUV uv, SubBlockPosition[] facePositions) { public Face(float texture, InFaceUV uv, SubBlockPosition[] facePositions) {
this(texture, uv, facePositions, 0); this(texture, uv, facePositions, 0);

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Lukas Eisenhauer * Copyright (C) 2020 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 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.
* *
@ -13,12 +13,9 @@
package de.bixilon.minosoft.render.blockModels.specialModels; package de.bixilon.minosoft.render.blockModels.specialModels;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockRotations;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.render.blockModels.BlockConfiguration; import de.bixilon.minosoft.render.blockModels.BlockConfiguration;
import de.bixilon.minosoft.render.blockModels.BlockConfigurationTrue; import de.bixilon.minosoft.render.blockModels.BlockConfigurationTrue;
@ -28,16 +25,13 @@ import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock; import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
import de.bixilon.minosoft.render.texture.TextureLoader; import de.bixilon.minosoft.render.texture.TextureLoader;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import static de.bixilon.minosoft.util.Util.readJsonFromFile;
public class BlockModel implements BlockModelInterface { public class BlockModel implements BlockModelInterface {
HashMap<BlockConfiguration, HashSet<SubBlock>> blockConfigurationStates; private final HashMap<BlockConfiguration, HashSet<SubBlock>> blockConfigurationStates;
boolean isFull; private final boolean isFull;
public BlockModel(JsonObject block, String mod) { public BlockModel(JsonObject block, String mod) {
blockConfigurationStates = new HashMap<>(); blockConfigurationStates = new HashMap<>();
@ -57,10 +51,6 @@ public class BlockModel implements BlockModelInterface {
isFull = true; isFull = true;
} }
public BlockModel() {
}
public static HashSet<Face> prepareBlockState(HashSet<SubBlock> subBlocks, public static HashSet<Face> prepareBlockState(HashSet<SubBlock> subBlocks,
HashMap<FaceOrientation, Boolean> adjacentBlocks, Block block) { HashMap<FaceOrientation, Boolean> adjacentBlocks, Block block) {
HashSet<Face> result = new HashSet<>(); HashSet<Face> result = new HashSet<>();

View File

@ -29,7 +29,7 @@ import java.util.HashSet;
import static de.bixilon.minosoft.render.blockModels.specialModels.BlockModel.*; import static de.bixilon.minosoft.render.blockModels.specialModels.BlockModel.*;
public class CropModel implements BlockModelInterface { public class CropModel implements BlockModelInterface {
HashMap<String, HashSet<SubBlock>> modelMap; private final HashMap<String, HashSet<SubBlock>> modelMap;
public CropModel(JsonObject block, String mod) { public CropModel(JsonObject block, String mod) {
int stages = block.get("stages").getAsInt(); int stages = block.get("stages").getAsInt();

View File

@ -30,11 +30,11 @@ import java.util.HashSet;
import static de.bixilon.minosoft.render.blockModels.specialModels.BlockModel.*; import static de.bixilon.minosoft.render.blockModels.specialModels.BlockModel.*;
public class DoorModel implements BlockModelInterface { public class DoorModel implements BlockModelInterface {
HashSet<SubBlock> bottom; private final HashSet<SubBlock> bottom;
HashSet<SubBlock> bottom_hinge; private final HashSet<SubBlock> bottom_hinge;
HashSet<SubBlock> top; private final HashSet<SubBlock> top;
HashSet<SubBlock> top_hinge; private final HashSet<SubBlock> top_hinge;
public DoorModel(JsonObject block, String mod) { public DoorModel(JsonObject block, String mod) {
bottom = BlockModelInterface.load(mod, block.get("bottom").getAsString()); bottom = BlockModelInterface.load(mod, block.get("bottom").getAsString());

View File

@ -27,10 +27,9 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
public class FireModel implements BlockModelInterface { public class FireModel implements BlockModelInterface {
HashSet<SubBlock> floor; private final HashSet<SubBlock> floor;
HashSet<SubBlock> side; private final HashSet<SubBlock> side;
HashSet<SubBlock> up; private final HashSet<SubBlock> up;
public FireModel(JsonObject block, String mod) { public FireModel(JsonObject block, String mod) {
floor = BlockModelInterface.load(mod, block.get("floor").getAsString()); floor = BlockModelInterface.load(mod, block.get("floor").getAsString());

View File

@ -27,9 +27,9 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
public class StairsModel implements BlockModelInterface { public class StairsModel implements BlockModelInterface {
HashSet<SubBlock> straight; private final HashSet<SubBlock> straight;
HashSet<SubBlock> inner; private final HashSet<SubBlock> inner;
HashSet<SubBlock> outer; private final HashSet<SubBlock> outer;
public StairsModel(JsonObject block, String mod) { public StairsModel(JsonObject block, String mod) {
straight = BlockModelInterface.load(mod, block.get("straight").getAsString()); straight = BlockModelInterface.load(mod, block.get("straight").getAsString());

View File

@ -32,7 +32,7 @@ public class Cuboid {
FaceOrientation.NORTH, new int[]{5, 4, 0, 1} FaceOrientation.NORTH, new int[]{5, 4, 0, 1}
); );
HashMap<FaceOrientation, SubBlockPosition[]> facePositionMap; private final HashMap<FaceOrientation, SubBlockPosition[]> facePositionMap;
public Cuboid(SubBlockPosition from, SubBlockPosition to, SubBlockRotation rotation) { public Cuboid(SubBlockPosition from, SubBlockPosition to, SubBlockRotation rotation) {
SubBlockPosition[] positions = new SubBlockPosition[8]; SubBlockPosition[] positions = new SubBlockPosition[8];

View File

@ -25,16 +25,16 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
public class SubBlock { public class SubBlock {
SubBlockRotation rotation; private SubBlockRotation rotation;
HashMap<FaceOrientation, Float> textureCoordinates; private final HashMap<FaceOrientation, Float> textureCoordinates;
HashMap<FaceOrientation, String> textures; private final HashMap<FaceOrientation, String> textures;
HashMap<FaceOrientation, Integer> textureRotations; private final HashMap<FaceOrientation, Integer> textureRotations;
HashMap<FaceOrientation, Boolean> cullFaceTextures; private final HashMap<FaceOrientation, Boolean> cullFaceTextures;
HashMap<FaceOrientation, InFaceUV> uv; private final HashMap<FaceOrientation, InFaceUV> uv;
Cuboid cuboid; private final Cuboid cuboid;
private final boolean isFull; private final boolean isFull;

View File

@ -22,20 +22,22 @@ import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.blockR
import static org.lwjgl.opengl.GL11.glVertex3f; import static org.lwjgl.opengl.GL11.glVertex3f;
public class SubBlockPosition { public class SubBlockPosition {
float x, y, z; public float x;
public float y;
public float z;
public static final SubBlockPosition middlePos = new SubBlockPosition(8, 8, 8); private static final SubBlockPosition middlePos = new SubBlockPosition(8, 8, 8);
public static final SubBlockRotation westRotator = new SubBlockRotation(middlePos, Axis.Y, 90); private static final SubBlockRotation westRotator = new SubBlockRotation(middlePos, Axis.Y, 90);
public static final SubBlockRotation eastRotator = new SubBlockRotation(middlePos, Axis.Y, 270); private static final SubBlockRotation eastRotator = new SubBlockRotation(middlePos, Axis.Y, 270);
public static final SubBlockRotation southRotator = new SubBlockRotation(middlePos, Axis.Y, 180); private static final SubBlockRotation southRotator = new SubBlockRotation(middlePos, Axis.Y, 180);
public static final SubBlockRotation xAxisRotator = new SubBlockRotation(middlePos, Axis.Z, 90); private static final SubBlockRotation xAxisRotator = new SubBlockRotation(middlePos, Axis.Z, 90);
public static final SubBlockRotation zAxisRotator = new SubBlockRotation(middlePos, Axis.X, 90); private static final SubBlockRotation zAxisRotator = new SubBlockRotation(middlePos, Axis.X, 90);
public static final SubBlockRotation downRotator = new SubBlockRotation(middlePos, Axis.X, 90); private static final SubBlockRotation downRotator = new SubBlockRotation(middlePos, Axis.X, 90);
public static final SubBlockRotation downAltRotator = new SubBlockRotation(middlePos, Axis.X, 180); private static final SubBlockRotation downAltRotator = new SubBlockRotation(middlePos, Axis.X, 180);
public static final SubBlockRotation upRotator = new SubBlockRotation(middlePos, Axis.X, -90); private static final SubBlockRotation upRotator = new SubBlockRotation(middlePos, Axis.X, -90);
public SubBlockPosition(JsonArray json) { public SubBlockPosition(JsonArray json) {

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *
@ -21,9 +21,9 @@ import static java.lang.StrictMath.cos;
import static java.lang.StrictMath.sin; import static java.lang.StrictMath.sin;
public class SubBlockRotation { public class SubBlockRotation {
SubBlockPosition origin; private final SubBlockPosition origin;
Axis direction; private Axis direction;
float angle; private final float angle;
public SubBlockRotation(SubBlockPosition origin, Axis direction, float angle) { public SubBlockRotation(SubBlockPosition origin, Axis direction, float angle) {
this.origin = origin; this.origin = origin;
@ -35,15 +35,9 @@ public class SubBlockRotation {
origin = new SubBlockPosition(rotation.get("origin").getAsJsonArray()); origin = new SubBlockPosition(rotation.get("origin").getAsJsonArray());
String axis = rotation.get("axis").getAsString(); String axis = rotation.get("axis").getAsString();
switch (axis) { switch (axis) {
case "x": case "x" -> direction = Axis.X;
direction = Axis.X; case "y" -> direction = Axis.Y;
break; case "z" -> direction = Axis.Z;
case "y":
direction = Axis.Y;
break;
case "z":
direction = Axis.Z;
break;
} }
angle = rotation.get("angle").getAsFloat(); angle = rotation.get("angle").getAsFloat();
} }
@ -63,21 +57,21 @@ public class SubBlockRotation {
SubBlockPosition transformed = SubBlockPosition.subtract(position, origin); SubBlockPosition transformed = SubBlockPosition.subtract(position, origin);
Pair<Float, Float> rotated; Pair<Float, Float> rotated;
switch (direction) { switch (direction) {
case X: case X -> {
rotated = rotate(transformed.y, transformed.z, angle); rotated = rotate(transformed.y, transformed.z, angle);
transformed.y = rotated.getKey(); transformed.y = rotated.getKey();
transformed.z = rotated.getValue(); transformed.z = rotated.getValue();
break; }
case Y: case Y -> {
rotated = rotate(transformed.x, transformed.z, angle); rotated = rotate(transformed.x, transformed.z, angle);
transformed.x = rotated.getKey(); transformed.x = rotated.getKey();
transformed.z = rotated.getValue(); transformed.z = rotated.getValue();
break; }
case Z: case Z -> {
rotated = rotate(transformed.x, transformed.y, angle); rotated = rotate(transformed.x, transformed.y, angle);
transformed.x = rotated.getKey(); transformed.x = rotated.getKey();
transformed.y = rotated.getValue(); transformed.y = rotated.getValue();
break; }
} }
return SubBlockPosition.add(transformed, origin); return SubBlockPosition.add(transformed, origin);
} }

View File

@ -21,7 +21,8 @@ import static java.lang.StrictMath.*;
import static org.lwjgl.opengl.GL11.glRotatef; import static org.lwjgl.opengl.GL11.glRotatef;
public class CameraMovement { public class CameraMovement {
Vec3 cameraFront = new Vec3(0.0f, 0.0f, -1.0f); private static final float sensitivity = 0.1f;
private Vec3 cameraFront = new Vec3(0.0f, 0.0f, -1.0f);
private boolean firstMouse = false; private boolean firstMouse = false;
private float lastX; private float lastX;
@ -30,11 +31,11 @@ public class CameraMovement {
private float pitch; private float pitch;
public void mouseCallback(long l, double xPos, double yPos) { public void mouseCallback(long l, double xPos, double yPos) {
// variable l is unused but always given by openGL so it is needed in the method signature
if (GameWindow.paused) { if (GameWindow.paused) {
return; return;
} }
// variable l is unused but always given by openGL so we need it in the method signature
if (firstMouse) { if (firstMouse) {
lastX = (float) xPos; lastX = (float) xPos;
lastY = (float) yPos; lastY = (float) yPos;
@ -46,18 +47,18 @@ public class CameraMovement {
lastX = (float) xPos; lastX = (float) xPos;
lastY = (float) yPos; lastY = (float) yPos;
float sensitivity = 0.1f; // change this value to your liking
xoffset *= sensitivity; xoffset *= sensitivity;
yoffset *= sensitivity; yoffset *= sensitivity;
yaw += xoffset; yaw += xoffset;
pitch += yoffset; pitch += yoffset;
// make sure that pitch does not get out of bounds if (pitch > 89.0f) {
if (pitch > 89.0f)
pitch = 89.0f; pitch = 89.0f;
if (pitch < -89.0f) }
if (pitch < -89.0f) {
pitch = -89.0f; pitch = -89.0f;
}
Vec3 front = new Vec3(); Vec3 front = new Vec3();
front.x = (float) -(sin(toRadians(yaw)) * cos(toRadians(pitch))); front.x = (float) -(sin(toRadians(yaw)) * cos(toRadians(pitch)));

View File

@ -23,9 +23,9 @@ import static de.bixilon.minosoft.render.utility.AdditionalMath.betterRound;
import static de.bixilon.minosoft.render.utility.AdditionalMath.valuesBetween; import static de.bixilon.minosoft.render.utility.AdditionalMath.valuesBetween;
public class CollisionHandler { public class CollisionHandler {
World world; private final World world;
PlayerController controller; private final PlayerController controller;
BlockModelLoader modelLoader; private final BlockModelLoader modelLoader;
public CollisionHandler(PlayerController controller) { public CollisionHandler(PlayerController controller) {
world = GameWindow.getConnection().getPlayer().getWorld(); world = GameWindow.getConnection().getPlayer().getWorld();
@ -35,7 +35,7 @@ public class CollisionHandler {
public void handleCollisions() { public void handleCollisions() {
if (isPositionValid(controller.playerPos)) { if (isPositionValid(controller.playerPos)) {
// we aren't collided with anything so the player Position does not have to be adjusted // the player currently isn't colliding with with anything so the player Position does not have to be adjusted
return; return;
} }
xAxisCollision(); xAxisCollision();
@ -73,7 +73,7 @@ public class CollisionHandler {
controller.playerVelocity.y = 0; controller.playerVelocity.y = 0;
if (deltaY < 0) { if (deltaY < 0) {
controller.onGround = true; controller.setOnGround(true);
} }
} }

View File

@ -22,14 +22,15 @@ import static de.bixilon.minosoft.render.utility.Vec3.mul;
import static org.lwjgl.opengl.GL11.glTranslatef; import static org.lwjgl.opengl.GL11.glTranslatef;
public class PlayerController { public class PlayerController {
private final float playerHeight = 1.8f; private static final float playerHeight = 1.8f;
private final float playerWidth = 0.25f; private static final float playerWidth = 0.25f;
private static final float gravity = 13;
CameraMovement cameraMovement; CameraMovement cameraMovement;
PlayerMovement playerMovement; PlayerMovement playerMovement;
Vec3 playerPos = new Vec3(); // the feet position of the player Vec3 playerPos = new Vec3(); // the feet position of the player
Vec3 playerVelocity = new Vec3(); Vec3 playerVelocity = new Vec3();
float gravity = 9.81f; private boolean onGround;
boolean onGround;
private boolean enableGravity; private boolean enableGravity;
private CollisionHandler collisionHandler; private CollisionHandler collisionHandler;
public Vec3 oldPos; public Vec3 oldPos;
@ -121,4 +122,8 @@ public class PlayerController {
public float getPlayerHeight() { public float getPlayerHeight() {
return playerHeight; return playerHeight;
} }
public void setOnGround(boolean onGround) {
this.onGround = onGround;
}
} }

View File

@ -11,10 +11,6 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft. * This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/ */
/*
* A simple camera controller to fly around the scene
*/
package de.bixilon.minosoft.render.movement; package de.bixilon.minosoft.render.movement;
import de.bixilon.minosoft.render.GameWindow; import de.bixilon.minosoft.render.GameWindow;
@ -25,20 +21,19 @@ import static de.bixilon.minosoft.render.utility.Vec3.mul;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
public class PlayerMovement { public class PlayerMovement {
private static final float FLY_SPEED = 0.1f;
private static final Vec3 CAMERA_UP = new Vec3(0f, 1f, 0f);
private final long window; private final long window;
Vec3 cameraFront; private Vec3 cameraFront;
Vec3 cameraUp = new Vec3(0f, 1f, 0f); private Vec3 playerPos;
float flySpeed = 0.1f;
Vec3 playerPos;
public PlayerMovement(long window) { public PlayerMovement(long window) {
this.window = window; this.window = window;
} }
private void processInput(float deltaTime) { private void processInput(float deltaTime) {
float cameraSpeed = flySpeed / deltaTime; float cameraSpeed = FLY_SPEED / deltaTime;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
playerPos.add(mul(cameraFront, -cameraSpeed * deltaTime)); playerPos.add(mul(cameraFront, -cameraSpeed * deltaTime));
@ -47,10 +42,10 @@ public class PlayerMovement {
playerPos.add(mul(cameraFront, cameraSpeed * deltaTime)); playerPos.add(mul(cameraFront, cameraSpeed * deltaTime));
} }
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
playerPos.add(mul(cross(cameraUp, cameraFront), -cameraSpeed * deltaTime)); playerPos.add(mul(cross(CAMERA_UP, cameraFront), -cameraSpeed * deltaTime));
} }
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
playerPos.add(mul(cross(cameraUp, cameraFront), cameraSpeed * deltaTime)); playerPos.add(mul(cross(CAMERA_UP, cameraFront), cameraSpeed * deltaTime));
} }
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *
@ -20,7 +20,7 @@ import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.textur
import static org.lwjgl.opengl.GL11.glTexCoord2f; import static org.lwjgl.opengl.GL11.glTexCoord2f;
public class InFaceUV { public class InFaceUV {
public int u1, v1, u2, v2; public final int u1, v1, u2, v2;
public float realU1, realV1, realU2, realV2; public float realU1, realV1, realU2, realV2;

View File

@ -33,10 +33,10 @@ import static org.lwjgl.opengl.GL30.glGenerateMipmap;
public class TextureLoader { public class TextureLoader {
private final HashMap<String, HashMap<String, Integer>> textureCoordinates; private final HashMap<String, HashMap<String, Integer>> textureCoordinates;
int textureID; private int textureID;
float step; private float step;
int totalTextures = 0; private int totalTextures = 0;
HashMap<String, HashMap<String, BufferedImage>> images; private HashMap<String, HashMap<String, BufferedImage>> images;
public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, HashMap<String, float[]>> tints) { public TextureLoader(HashMap<String, HashSet<String>> textures, HashMap<String, HashMap<String, float[]>> tints) {
textureCoordinates = new HashMap<>(); textureCoordinates = new HashMap<>();

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *
@ -39,8 +39,4 @@ public class AdditionalMath {
} }
return (int) x - 1; return (int) x - 1;
} }
public static boolean isBetween(double x, double a, double b) {
return x <= a && x >= b || x >= a && x <= b;
}
} }

View File

@ -1,26 +0,0 @@
/*
* Codename Minosoft
* Copyright (C) 2020 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.render.utility;
public class Triplet<T, T1, T2> {
public T item1;
public T1 item2;
public T2 item3;
public Triplet(T item1, T1 item2, T2 item3) {
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Codename Minosoft * Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger * Copyright (C) 2020 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. * 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.
* *