From 36eab5870507fad2188fad9165fa6034b422ffe5 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Tue, 5 May 2015 10:52:06 +0200 Subject: [PATCH] Added prerequisites for future Camera Tilt feature --- .../replaymod/events/GuiReplayOverlay.java | 4 ++-- .../replaymod/events/KeyInputHandler.java | 8 ++++++++ .../crushedpixel/replaymod/holders/Position.java | 15 +++++++++++++++ .../replaymod/interpolation/SplinePoint.java | 9 ++++++++- .../replaymod/registry/KeybindRegistry.java | 4 ++++ .../replaymod/replay/ReplayHandler.java | 16 ++++++++++++++++ .../resources/assets/replaymod/lang/en_US.lang | 4 +++- 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java index e46d36b5..5cbcbae6 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java @@ -657,7 +657,7 @@ public class GuiReplayOverlay extends Gui { private void addPlaceKeyframe() { Entity cam = mc.getRenderViewEntity(); if(cam == null) return; - ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw))); + ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw, ReplayHandler.getCameraTilt()))); } private void addTimeKeyframe() { @@ -677,7 +677,7 @@ public class GuiReplayOverlay extends Gui { private boolean isClick() { if(Mouse.isButtonDown(0)) { - boolean bef = new Boolean(mouseDwn); + boolean bef = mouseDwn; mouseDwn = true; return !bef; } else { diff --git a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java index 406ef6dc..a961367e 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java @@ -104,6 +104,14 @@ public class KeyInputHandler { public void handleCustomKeybindings(KeyBinding kb, boolean found, int keyCode) { //Custom registered handlers + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ROTATE_CLOCKWISE) && (kb.isKeyDown() || kb.getKeyCode() == keyCode) && !found) { + ReplayHandler.addCameraTilt(1); + } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ROTATE_COUNTERCLOCKWISE) && (kb.isKeyDown() || kb.getKeyCode() == keyCode) && !found) { + ReplayHandler.addCameraTilt(-1); + } + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !found) { TickAndRenderListener.requestScreenshot(); } diff --git a/src/main/java/eu/crushedpixel/replaymod/holders/Position.java b/src/main/java/eu/crushedpixel/replaymod/holders/Position.java index cdea5463..4f503f2a 100755 --- a/src/main/java/eu/crushedpixel/replaymod/holders/Position.java +++ b/src/main/java/eu/crushedpixel/replaymod/holders/Position.java @@ -7,6 +7,7 @@ public class Position { private double x, y, z; private float pitch, yaw; + private float rotation = 0; public Position(Entity e) { this.x = e.posX; @@ -16,6 +17,15 @@ public class Position { this.yaw = e.rotationYaw; } + public Position(double x, double y, double z, float pitch, float yaw, float rotation) { + this.x = x; + this.y = y; + this.z = z; + this.pitch = pitch; + this.yaw = yaw; + this.rotation = rotation; + } + public Position(double x, double y, double z, float pitch, float yaw) { this.x = x; this.y = y; @@ -64,6 +74,10 @@ public class Position { this.yaw = yaw; } + public float getRotation() { return rotation; } + + public void setRotation(float rotation) { this.rotation = rotation; } + @Override public String toString() { return "X=" + x + ", Y=" + y + ", Z=" + z + ", Yaw=" + yaw + ", Pitch=" + pitch; @@ -85,6 +99,7 @@ public class Position { .append(z) .append(pitch) .append(yaw) + .append(rotation) .toHashCode(); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/interpolation/SplinePoint.java b/src/main/java/eu/crushedpixel/replaymod/interpolation/SplinePoint.java index e16d5877..fb98f0f5 100755 --- a/src/main/java/eu/crushedpixel/replaymod/interpolation/SplinePoint.java +++ b/src/main/java/eu/crushedpixel/replaymod/interpolation/SplinePoint.java @@ -14,11 +14,13 @@ public class SplinePoint extends BasicSpline { private Vector zCubics; private Vector pitchCubics; private Vector yawCubics; + private Vector rotCubics; private Field vectorX; private Field vectorY; private Field vectorZ; private Field vectorPitch; private Field vectorYaw; + private Field vectorRot; public SplinePoint() { this.points = new Vector(); @@ -28,6 +30,7 @@ public class SplinePoint extends BasicSpline { this.zCubics = new Vector(); this.pitchCubics = new Vector(); this.yawCubics = new Vector(); + this.rotCubics = new Vector(); try { vectorX = Position.class.getDeclaredField("x"); @@ -35,11 +38,13 @@ public class SplinePoint extends BasicSpline { vectorZ = Position.class.getDeclaredField("z"); vectorPitch = Position.class.getDeclaredField("pitch"); vectorYaw = Position.class.getDeclaredField("yaw"); + vectorRot = Position.class.getDeclaredField("rotation"); vectorX.setAccessible(true); vectorY.setAccessible(true); vectorZ.setAccessible(true); vectorPitch.setAccessible(true); vectorYaw.setAccessible(true); + vectorRot.setAccessible(true); } catch(SecurityException e) { e.printStackTrace(); } catch(NoSuchFieldException e) { @@ -62,6 +67,7 @@ public class SplinePoint extends BasicSpline { calcNaturalCubic(points, vectorZ, zCubics); calcNaturalCubic(points, vectorPitch, pitchCubics); calcNaturalCubic(points, vectorYaw, yawCubics); + calcNaturalCubic(points, vectorRot, rotCubics); } catch(IllegalArgumentException e) { e.printStackTrace(); } catch(IllegalAccessException e) { @@ -80,7 +86,8 @@ public class SplinePoint extends BasicSpline { yCubics.get(cubicNum).eval(cubicPos), zCubics.get(cubicNum).eval(cubicPos), (float) pitchCubics.get(cubicNum).eval(cubicPos), - (float) yawCubics.get(cubicNum).eval(cubicPos)); + (float) yawCubics.get(cubicNum).eval(cubicPos), + (float) rotCubics.get(cubicNum).eval(cubicPos)); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java b/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java index 21e5c32a..7133317c 100755 --- a/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java +++ b/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java @@ -16,6 +16,8 @@ public class KeybindRegistry { public static final String KEY_CLEAR_KEYFRAMES = "replaymod.input.clearkeyframes"; public static final String KEY_SYNC_TIMELINE = "replaymod.input.synctimeline"; public static final String KEY_KEYFRAME_PRESETS = "replaymod.input.keyframerepository"; + public static final String KEY_ROTATE_CLOCKWISE = "replaymod.input.rotateclockwise"; + public static final String KEY_ROTATE_COUNTERCLOCKWISE = "replaymod.input.rotatecounterclockwise"; private static Minecraft mc = Minecraft.getMinecraft(); public static void initialize() { @@ -27,6 +29,8 @@ public class KeybindRegistry { bindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title")); bindings.add(new KeyBinding(KEY_CLEAR_KEYFRAMES, Keyboard.KEY_C, "replaymod.title")); bindings.add(new KeyBinding(KEY_KEYFRAME_PRESETS, Keyboard.KEY_X, "replaymod.title")); + bindings.add(new KeyBinding(KEY_ROTATE_CLOCKWISE, Keyboard.KEY_L, "replaymod.title")); + bindings.add(new KeyBinding(KEY_ROTATE_COUNTERCLOCKWISE, Keyboard.KEY_K, "replaymod.title")); mc.gameSettings.keyBindings = bindings.toArray(new KeyBinding[bindings.size()]); diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java index c7a83b7e..87f83fdb 100755 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java @@ -32,6 +32,8 @@ public class ReplayHandler { private static Entity currentEntity = null; private static Position lastPosition = null; + private static float cameraTilt = 0; + private static KeyframeSet[] keyframeRepository = new KeyframeSet[]{}; public static KeyframeSet[] getKeyframeRepository() { @@ -102,6 +104,18 @@ public class ReplayHandler { spectateCamera(); } + public static float getCameraTilt() { + return cameraTilt; + } + + public static void setCameraTilt(float tilt) { + cameraTilt = tilt; + } + + public static void addCameraTilt(float tilt) { + cameraTilt += tilt; + } + public static void sortKeyframes() { Collections.sort(keyframes, new KeyframeComparator()); } @@ -281,6 +295,8 @@ public class ReplayHandler { channel.close(); } + setCameraTilt(0); + networkManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); INetHandlerPlayClient pc = new NetHandlerPlayClient(mc, null, networkManager, new GameProfile(UUID.randomUUID(), "Player")); networkManager.setNetHandler(pc); diff --git a/src/main/resources/assets/replaymod/lang/en_US.lang b/src/main/resources/assets/replaymod/lang/en_US.lang index 94e685b2..04f0ee26 100644 --- a/src/main/resources/assets/replaymod/lang/en_US.lang +++ b/src/main/resources/assets/replaymod/lang/en_US.lang @@ -21,6 +21,7 @@ replaymod.api.unknownlang=This language has not been translated replaymod.api.zippingerror=An error occured while zipping the language files replaymod.api.usernameexists=This username is already taken replaymod.api.mailexists=This email address is already linked to an account +replaymod.api.invalidmail=Invalid e-Mail Address #All of the chat messages @@ -97,7 +98,6 @@ replaymod.gui.register.confirmpw=Confirm Password replaymod.gui.register.error.nomatch=Passwords don't match replaymod.gui.register.error.shortusername=Username has to be at least 5 characters long replaymod.gui.register.error.shortpw=Password has to be at least 5 characters long -replaymod.gui.register.error.invalidmail=Invalid e-Mail Address #Replay Viewer GUI @@ -187,6 +187,8 @@ replaymod.input.spectate=Spectate Players replaymod.input.clearkeyframes=Clear Keyframes replaymod.input.synctimeline=Synchronize Timeline replaymod.input.keyframerepository=Open Keyframe Presets +replaymod.input.rotateclockwise=Rotate Clockwise +replaymod.input.rotatecounterclockwise=Rotate Counterclockwise #Keyframe Presets GUI replaymod.gui.keyframerepository.title=Keyframe Repository