From 756e7d102d1043cdc94764c7219ebe65a9d5d344 Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Sat, 27 Jun 2020 18:21:46 +0200 Subject: [PATCH] Improve rotation algorithm. --- fabric/build.gradle | 2 +- .../client/LambdaControlsClient.java | 2 +- .../lambdacontrols/client/LambdaInput.java | 42 +++++++++--------- .../lambdacontrols/textures/gui/cursor.png | Bin 0 -> 1087 bytes 4 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 fabric/src/main/resources/assets/lambdacontrols/textures/gui/cursor.png diff --git a/fabric/build.gradle b/fabric/build.gradle index 1242bd7..a4b46ab 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.6-SNAPSHOT' + id 'fabric-loom' version '0.4-SNAPSHOT' id 'java-library' id 'maven-publish' } diff --git a/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaControlsClient.java b/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaControlsClient.java index 0310531..03216f0 100644 --- a/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaControlsClient.java +++ b/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaControlsClient.java @@ -131,7 +131,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni public void onRender(MinecraftClient client) { - this.input.onRender(client); + this.input.onRender(client.getTickDelta(), client); } /** diff --git a/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaInput.java b/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaInput.java index 407ed21..0e6c6cd 100644 --- a/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaInput.java +++ b/fabric/src/main/java/me/lambdaurora/lambdacontrols/client/LambdaInput.java @@ -41,6 +41,7 @@ import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; import net.minecraft.client.gui.widget.SliderWidget; import net.minecraft.container.Slot; import net.minecraft.container.SlotActionType; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.util.hit.BlockHitResult; @@ -80,8 +81,6 @@ public class LambdaInput private int actionGuiCooldown = 0; private int ignoreNextA = 0; // Sneak state. - private double prevTargetYaw = 0.0; - private double prevTargetPitch = 0.0; private double targetYaw = 0.0; private double targetPitch = 0.0; private float prevXAxis = 0.F; @@ -103,8 +102,8 @@ public class LambdaInput */ public void onTick(@NotNull MinecraftClient client) { - this.prevTargetYaw = this.targetYaw; - this.prevTargetPitch = this.targetPitch; + this.targetYaw = 0.F; + this.targetPitch = 0.F; // Handles the key bindings. if (LambdaControlsClient.BINDING_LOOK_UP.isPressed()) { @@ -189,20 +188,24 @@ public class LambdaInput * * @param client The client instance. */ - public void onRender(@NotNull MinecraftClient client) + public void onRender(float tickDelta, @NotNull MinecraftClient client) { - if ((client.currentScreen == null || client.currentScreen instanceof TouchscreenOverlay) && - (this.prevTargetYaw != this.targetYaw || this.prevTargetPitch != this.targetPitch)) { - float deltaYaw = (float) ((this.targetYaw - client.player.prevYaw) * client.getTickDelta()); - float deltaPitch = (float) ((this.targetPitch - client.player.prevPitch) * client.getTickDelta()); - float rotationYaw = client.player.prevYaw + deltaYaw; - float rotationPitch = client.player.prevPitch + deltaPitch; + if (!(client.currentScreen == null || client.currentScreen instanceof TouchscreenOverlay)) + return; + + PlayerEntity player = client.player; + if (player == null) + return; + + if (this.targetYaw != 0F || this.targetPitch != 0F) { + float rotationYaw = (float) (player.prevYaw + (this.targetYaw / 0.10) * tickDelta); + float rotationPitch = (float) (player.prevPitch + (this.targetPitch / 0.10) * tickDelta); client.player.yaw = rotationYaw; client.player.pitch = MathHelper.clamp(rotationPitch, -90.F, 90.F); if (client.player.isRiding()) { client.player.getVehicle().copyPositionAndRotation(client.player); } - client.getTutorialManager().onUpdateMouse(deltaPitch, deltaYaw); + client.getTutorialManager().onUpdateMouse(this.targetPitch, this.targetYaw); } } @@ -437,6 +440,7 @@ public class LambdaInput if (client.currentScreen == null) { // Handles the look direction. + absValue -= this.config.getDeadZone(); this.handleLook(client, axis, (float) (absValue / (1.0 - this.config.getDeadZone())), state); } else { boolean allowMouseControl = true; @@ -570,7 +574,7 @@ public class LambdaInput /** * Handles the look direction input. * - * @param client The client isntance. + * @param client The client instance. * @param axis The axis to change. * @param value The value of the look. * @param state The state. @@ -579,21 +583,19 @@ public class LambdaInput { // Handles the look direction. if (client.player != null) { - double powValue = Math.pow(value, 4.0); + double powValue = Math.pow(value, 2.0); if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) { if (state == 2) { - this.targetPitch = client.player.pitch - this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; - this.targetPitch = MathHelper.clamp(this.targetPitch, -90.0D, 90.0D); + this.targetPitch = -this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; } else if (state == 1) { - this.targetPitch = client.player.pitch + this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; - this.targetPitch = MathHelper.clamp(this.targetPitch, -90.0D, 90.0D); + this.targetPitch = this.config.getRightYAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; } } if (axis == GLFW_GAMEPAD_AXIS_RIGHT_X) { if (state == 2) { - this.targetYaw = client.player.yaw - this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; + this.targetYaw = -this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; } else if (state == 1) { - this.targetYaw = client.player.yaw + this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; + this.targetYaw = this.config.getRightXAxisSign() * (this.config.getRotationSpeed() * powValue) * 0.33D; } } } diff --git a/fabric/src/main/resources/assets/lambdacontrols/textures/gui/cursor.png b/fabric/src/main/resources/assets/lambdacontrols/textures/gui/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..3b7ae917a43da00e7a03160328398bc1b2b61ff7 GIT binary patch literal 1087 zcmV-F1i<@=P)#WSyTCXX^Z}*oZ}E!LE9GGEJOpVl8Xrg-3UW)!dx&kw6J5jJKKNw6d*uh{LTCRU zW!Q@V000SaNLh0L09-}@09-}^6qG|j0007ZNklFkSnW;l;hYsY!!4q;|@drHZJ z2}NGOa|%3VUKzc68QBl333ROa~fGu^*jIoU#H-+m4=pno)O^SkW6H=NOCLAhM;T zWU@$^7F8;_Q|sLxw@1@4{7g7J1z9K5@~!zIvIl7Cba%m8Hxv&=%9O{b9)P>Kw74Ro zCadAQc0y}QE-BQF0C&z(W700Ghi}Iw0l6WwZo*5qXz7>|u9yN0IG@k6hw#}VAviJI z<#JKIr{TJJpcIsuFh%41Xypq#jC zY2_C+TM6H_6S4};n^AOyywP|!BgAOhj+X<5dXwr^;0@u=Hd`~X84>^h002ovPDHLk FV1j)3=LrA+ literal 0 HcmV?d00001