From 180aad05decc7eefa87e4e45d6747c48f40e5361 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 17 Apr 2023 12:12:01 -0400 Subject: save --- .../net/tylermurphy/Minecraft/Scene/Camera.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 src/main/java/net/tylermurphy/Minecraft/Scene/Camera.java (limited to 'src/main/java/net/tylermurphy/Minecraft/Scene/Camera.java') diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Camera.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Camera.java new file mode 100755 index 0000000..9752998 --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Camera.java @@ -0,0 +1,74 @@ +package net.tylermurphy.Minecraft.Scene; + +import java.io.Serializable; + +import org.joml.Vector3f; + +import net.tylermurphy.Minecraft.Input.Input; +import net.tylermurphy.Minecraft.Render.Data.Display; + +public class Camera implements Serializable { + + private static final long serialVersionUID = -2612670500762524881L; + + protected Vector3f position = new Vector3f(0, 0, 0); + protected float pitch = 0; + protected float yaw = 0; + protected float roll = 0; + + public void move(){ + if(!World.player.isPaused) { + calculatePitch(); + calculateYaw(); + } + calculateCameraPosition(); + + yaw%=360; + } + + public void invertPitch(){ + this.pitch = -pitch; + } + + public Vector3f getPosition() { + return position; + } + + public float getPitch() { + return pitch; + } + + public float getYaw() { + return yaw; + } + + public float getRoll() { + return roll; + } + + public void calculateCameraPosition(){ + position.x = World.player.getTransform().getPosition().x; + position.z = World.player.getTransform().getPosition().z; + position.y = World.player.getTransform().getPosition().y + 10; + } + + protected void calculatePitch(){ + if(Display.closed()) { + float pitchChange = (float) (Input.getMouseDY() * 0.3f); + pitch -= pitchChange; + if(pitch < -90){ + pitch = -90; + }else if(pitch > 90){ + pitch = 90; + } + } + } + + protected void calculateYaw(){ + if(Display.closed()) { + float angleChange = (float) (Input.getMouseDX() * 0.4f); + yaw += angleChange; + } + } + +} -- cgit v1.2.3-freya