Implementing Zooming

This commit is contained in:
Sebastian 2023-08-24 15:04:35 +02:00
parent 7edcda998c
commit 7acf9fd703
2 changed files with 22 additions and 3 deletions

View File

@ -9,9 +9,7 @@ import core.engine.renderer.MasterRenderer;
import core.engine.terrain.Terrain; import core.engine.terrain.Terrain;
import core.engine.textures.ModelTexture; import core.engine.textures.ModelTexture;
import org.lwjgl.Version; import org.lwjgl.Version;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.*;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
import utils.vectors.Vector3f; import utils.vectors.Vector3f;
@ -113,6 +111,19 @@ public class Engine {
// Set the clear color // Set the clear color
glClearColor(1.0f, 0.0f, 0.0f, 0.0f); glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
Camera camera = new Camera(); Camera camera = new Camera();
GLFWScrollCallback glfwScrollCallback = new GLFWScrollCallback() {
@Override
public void invoke(long window, double xOffset, double yOffset) {
if(yOffset > 0) {
camera.zoomIn();
} else if(yOffset < 0) {
camera.zoomOut();
}
}
};
glfwSetScrollCallback(window, glfwScrollCallback);
glfwSetKeyCallback(window, glfwKeyCallback = new GLFWKeyCallback() { glfwSetKeyCallback(window, glfwKeyCallback = new GLFWKeyCallback() {
@Override @Override
public void invoke(long window, int key, int scancode, int action, int mods) { public void invoke(long window, int key, int scancode, int action, int mods) {

View File

@ -25,6 +25,14 @@ public class Camera {
position.x -= .5f; position.x -= .5f;
} }
public void zoomOut() {
position.y += 0.5f;
}
public void zoomIn() {
position.y -= 0.5f;
}
public Vector3f getPosition() { public Vector3f getPosition() {
return position; return position;
} }