Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -93,6 +102,7 @@ public OrthoViewHandler() {
KeyBindingHelper.registerKeyBinding(keyMod);
KeyBindingHelper.registerKeyBinding(key360);
KeyBindingHelper.registerKeyBinding(keyBackground);
KeyBindingHelper.registerKeyBinding(keySaveCam);

reset();
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The 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)));
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;
Copy link
Owner

Choose a reason for hiding this comment

The 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):

if camSaved then
  stuff = stuffSaved
else 
  stuff = defaults
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Owner

@pascallj pascallj May 16, 2022

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/mineshotrevived/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down