diff --git a/README.md b/README.md index 18f2810..bf6ffdf 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ The controls are slightly different compared to the original Mineshot: * Multiply: Turn clipping off * Divide: Render full 360 degrees around player * Demical dot: Change the background color between sky, red and white +* Numpad 0: Save the current rotation and zoom level to restore them the next time the ortho view is enabled +* MOD-key (Left Alt) + Numpad 0: Delete the saved rotation and zoom level The key-bindings can be changed in the Minecraft Controls menu. diff --git a/src/main/java/nl/pascalroeleven/minecraft/mineshotrevived/client/OrthoViewHandler.java b/src/main/java/nl/pascalroeleven/minecraft/mineshotrevived/client/OrthoViewHandler.java index 89eb428..49d9350 100644 --- a/src/main/java/nl/pascalroeleven/minecraft/mineshotrevived/client/OrthoViewHandler.java +++ b/src/main/java/nl/pascalroeleven/minecraft/mineshotrevived/client/OrthoViewHandler.java @@ -1,5 +1,6 @@ package nl.pascalroeleven.minecraft.mineshotrevived.client; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_KP_0; import static org.lwjgl.glfw.GLFW.GLFW_KEY_KP_1; import static org.lwjgl.glfw.GLFW.GLFW_KEY_KP_2; import static org.lwjgl.glfw.GLFW.GLFW_KEY_KP_3; @@ -20,6 +21,7 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.render.Camera; import net.minecraft.util.math.Matrix4f; import nl.pascalroeleven.minecraft.mineshotrevived.Mineshot; import nl.pascalroeleven.minecraft.mineshotrevived.client.config.PropertiesHandler; @@ -62,8 +64,12 @@ public class OrthoViewHandler { GLFW_KEY_KP_DIVIDE, KEY_CATEGORY); private final KeyBinding keyBackground = new KeyBinding("key.mineshotrevived.ortho.background", GLFW_KEY_KP_DECIMAL, KEY_CATEGORY); + private final KeyBinding keySaveCam = new KeyBinding("key.mineshotrevived.ortho.save_cam", + GLFW_KEY_KP_0, KEY_CATEGORY); private boolean enabled; + private boolean camSaved; + private boolean render360; private boolean frustumUpdate; private boolean freeCam; @@ -73,6 +79,9 @@ public class OrthoViewHandler { private float zoom; private float xRot; private float yRot; + private float zoomSaved; + private float xRotSaved; + private float yRotSaved; private int tick; private int tickPrevious; @@ -93,6 +102,7 @@ public OrthoViewHandler() { KeyBindingHelper.registerKeyBinding(keyMod); KeyBindingHelper.registerKeyBinding(key360); KeyBindingHelper.registerKeyBinding(keyBackground); + KeyBindingHelper.registerKeyBinding(keySaveCam); reset(); } @@ -102,9 +112,12 @@ public boolean onCameraUpdate() { if (!enabled) { return false; } - + Camera cam = MC.gameRenderer.getCamera(); if (!freeCam) { - ((CameraInvoker) MC.gameRenderer.getCamera()).InvokeSetRotation(yRot + 180, xRot); + ((CameraInvoker) cam).InvokeSetRotation(yRot + 180, xRot); + } else { + yRot = cam.getYaw() - 180; + xRot = cam.getPitch(); } return true; @@ -131,7 +144,7 @@ public Matrix4f onWorldRenderer(float tickDelta) { double partial = tickDelta; double elapsed = ticksElapsed + (partial - partialPrevious); elapsed *= SECONDS_PER_TICK * ROTATE_SPEED; - updateZoomAndRotation(elapsed); + updateZoomAndRotation(elapsed, false); tickPrevious = tick; partialPrevious = partial; @@ -192,39 +205,51 @@ public void onKeyEvent() { } else if (keyClip.isPressed()) { clip = !clip; } else if (keyRotateT.isPressed()) { + setZoom(zoomSaved); xRot = mod ? -90 : 90; yRot = 0; } else if (keyRotateF.isPressed()) { + setZoom(zoomSaved); xRot = 0; yRot = mod ? -90 : 90; } else if (keyRotateS.isPressed()) { + setZoom(zoomSaved); xRot = 0; yRot = mod ? 180 : 0; } else if (key360.isPressed()) { render360 = !render360; frustumUpdate = true; + } else if (keySaveCam.isPressed()) { + if (mod) { + camSaved = false; + } else { + zoomSaved = zoom; + xRotSaved = xRot; + yRotSaved = yRot; + camSaved = true; + } } // Update stepped rotation/zoom controls // Note: the smooth controls are handled in onWorldRenderer, since they need to be // executed on every frame if (mod) { - updateZoomAndRotation(1); - // Snap values to step units - xRot = Math.round(xRot / ROTATE_STEP) * ROTATE_STEP; - yRot = Math.round(yRot / ROTATE_STEP) * ROTATE_STEP; - zoom = (float) Math.pow(ZOOM_STEP, Math.round(Math.log10(zoom) / Math.log10(ZOOM_STEP))); + updateZoomAndRotation(1, true); } } private void reset() { + if (!camSaved) { + zoomSaved = (float) Math.pow(ZOOM_STEP, 3); + xRotSaved = Integer.parseInt(properties.get("xRotation")); + yRotSaved = Integer.parseInt(properties.get("yRotation")); + } + zoom = zoomSaved; + xRot = xRotSaved; + yRot = yRotSaved; freeCam = false; clip = false; render360 = false; - - zoom = (float) Math.pow(ZOOM_STEP, 3); - xRot = Integer.parseInt(properties.get("xRotation")); - yRot = Integer.parseInt(properties.get("yRotation")); tick = 0; tickPrevious = 0; partialPrevious = 0; @@ -270,26 +295,40 @@ private boolean modifierKeyPressed() { return keyMod.isPressed(); } - private void updateZoomAndRotation(double multi) { + private void updateZoomAndRotation(double multi, boolean mod) { if (keyZoomIn.isPressed()) { setZoom((float) Math.max(1E-7, (zoom / (1 + ((ZOOM_STEP - 1) * multi))))); + if (mod) + // zoom = 2^(ceil(log2(zoom))) + zoom = (float) Math.pow(ZOOM_STEP, Math.ceil(Math.log10(zoom) / Math.log10(ZOOM_STEP))); } if (keyZoomOut.isPressed()) { setZoom((float) (zoom * (1 + ((ZOOM_STEP - 1) * multi)))); + if (mod) + // zoom = 2^(floor(log2(zoom))) + zoom = (float) Math.pow(ZOOM_STEP, Math.floor(Math.log10(zoom) / Math.log10(ZOOM_STEP))); } if (keyRotateL.isPressed()) { yRot += ROTATE_STEP * multi; + if (mod) + yRot = (float) (Math.floor(yRot / ROTATE_STEP) * ROTATE_STEP); } if (keyRotateR.isPressed()) { yRot -= ROTATE_STEP * multi; + if (mod) + yRot = (float) (Math.ceil(yRot / ROTATE_STEP) * ROTATE_STEP); } if (keyRotateU.isPressed()) { xRot += ROTATE_STEP * multi; + if (mod) + xRot = (float) (Math.floor(xRot / ROTATE_STEP) * ROTATE_STEP); } if (keyRotateD.isPressed()) { xRot -= ROTATE_STEP * multi; + if (mod) + xRot = (float) (Math.ceil(xRot / ROTATE_STEP) * ROTATE_STEP); } } } diff --git a/src/main/resources/assets/mineshotrevived/lang/en_us.json b/src/main/resources/assets/mineshotrevived/lang/en_us.json index 35ee89d..df49c6f 100644 --- a/src/main/resources/assets/mineshotrevived/lang/en_us.json +++ b/src/main/resources/assets/mineshotrevived/lang/en_us.json @@ -15,6 +15,7 @@ "key.mineshotrevived.ortho.zoom_out": "Zoom out", "key.mineshotrevived.ortho.render360": "Render full 360 degrees", "key.mineshotrevived.ortho.background": "Change background", + "key.mineshotrevived.ortho.save_cam": "Save the camera settings", "mineshotrevived.config.height": "Capture Height (px)", "mineshotrevived.config.notify_dev": "Notify on dev-versions", "mineshotrevived.config.notify_incompatible": "Notify on incompatible versions",