-
Notifications
You must be signed in to change notification settings - Fork 1
Add camera saving feature #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do all the setZoom calls accomplish here? To me this has an additional downside that the zoomlevel is reset every time you want to switch between these standard views. |
||
| 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))); | ||
pascallj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, it is more intuitive to add the structure like this (and also saves an assignment):
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, when camSaved is false, both stuff and stuffSaved need to be changed, which is the function of Alt+0
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is no camera saved, why do have to initialize the stuffSaved variables to the defaults then? Because the next time you want to save a camera, these are overwritten anyway. And reset() is called every time the othogonal view is enabled. The only other time these variables are used, is in the setZoom calls, but these seem redundant to me. |
||
| 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); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.