Skip to content

Commit

Permalink
[VirtualInput] Switched to absolute camera angle coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Feb 12, 2024
1 parent 7506fe1 commit 672ade9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
Expand All @@ -29,12 +30,11 @@ public class MixinEntityRenderer implements SubtickDuck {
private Minecraft mc;


@ModifyArgs(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;turn(FF)V"))
public void playback_redirectCamera(Args args) {
TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(args.get(0), args.get(1));

args.set(0, TASmodClient.virtual.CAMERA_ANGLE.getCurrentPitch());
args.set(1, TASmodClient.virtual.CAMERA_ANGLE.getCurrentYaw());
@Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;turn(FF)V", shift = Shift.AFTER))
public void playback_injectAfterTurn(CallbackInfo ci) {
TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(mc.player.rotationPitch, mc.player.rotationYaw);
mc.player.rotationPitch = TASmodClient.virtual.CAMERA_ANGLE.getCurrentPitch();
mc.player.rotationYaw = TASmodClient.virtual.CAMERA_ANGLE.getCurrentYaw();
}

@Override
Expand All @@ -59,7 +59,7 @@ public float redirect_orientCameraYaw(float yaw, @Share("pitch") LocalFloatRef s
}

private float redirectCam(float yaw, float pitch) {
Triple<Float, Float, Float> interpolated = TASmodClient.virtual.CAMERA_ANGLE.getInterpolatedState(pitch, pitch, yaw, TASmodClient.controller.isPlayingback());
Triple<Float, Float, Float> interpolated = TASmodClient.virtual.CAMERA_ANGLE.getInterpolatedState(Minecraft.getMinecraft().timer.renderPartialTicks, pitch, yaw, TASmodClient.controller.isPlayingback());
GlStateManager.rotate(interpolated.getLeft(), 1.0f, 0.0f, 0.0f);
GlStateManager.rotate(interpolated.getRight(), 0.0f, 0.0f, 1.0f);
return interpolated.getMiddle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public VirtualCameraAngle(float pitch, float yaw, List<VirtualCameraAngle> subti
this.yaw = yaw;
}

public void update(float pitchDelta, float yawDelta) {
public void update(float pitch, float yaw) {
if(isParent() && !ignoreFirstUpdate()) {
addSubtick(clone());
}
this.pitch += pitchDelta;
this.yaw += yawDelta;
this.pitch = pitch;
this.yaw = yaw;
}

public void getStates(List<VirtualCameraAngle> reference) {
Expand All @@ -43,24 +43,12 @@ public void getStates(List<VirtualCameraAngle> reference) {
}
}

public VirtualCameraAngleEvent getCollected(VirtualCameraAngle nextCameraAngle) {
float pitchDelta = pitch;
float yawDelta = yaw;
for(VirtualCameraAngle subtick : nextCameraAngle.getAll()) {
pitchDelta+=subtick.pitch;
yawDelta+=subtick.yaw;
}
return new VirtualCameraAngleEvent(pitchDelta, yawDelta);
}

public void copyFrom(VirtualCameraAngle camera) {
this.pitch = camera.pitch;
this.yaw = camera.yaw;
this.subtickList.clear();
this.subtickList.addAll(camera.subtickList);
camera.subtickList.clear();
camera.pitch = 0f;
camera.yaw = 0f;
camera.resetFirstUpdate();
}

Expand Down
21 changes: 4 additions & 17 deletions src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,45 +476,32 @@ public class VirtualCameraAngleInput {
private final VirtualCameraAngle currentCameraAngle;
private final VirtualCameraAngle nextCameraAngle = new VirtualCameraAngle();
private final List<VirtualCameraAngle> cameraAngleInterpolationStates = new ArrayList<>();
private float currentPitchDelta = 0f;
private float currentYawDelta = 0f;

public VirtualCameraAngleInput(VirtualCameraAngle preloadedCamera) {
currentCameraAngle = preloadedCamera;
}

public void updateNextCameraAngle(float pitch, float yaw) {
LOGGER.debug("Pitch: {}, Yaw: {}", pitch, yaw);
// LOGGER.debug("Pitch: {}, Yaw: {}", pitch, yaw);
nextCameraAngle.update(pitch, yaw);
}

public void nextCameraTick() {
nextCameraAngle.getStates(cameraAngleInterpolationStates);
VirtualCameraAngleEvent event = currentCameraAngle.getCollected(nextCameraAngle);
currentPitchDelta = event.getDeltaPitch();
currentYawDelta = event.getDeltaYaw();
currentCameraAngle.copyFrom(nextCameraAngle);
}

public float getCurrentPitch() {
float out = currentPitchDelta;
if(currentPitchDelta != 0f) {
currentPitchDelta = 0f;
}
return out;
return currentCameraAngle.getPitch();
}

public float getCurrentYaw() {
float out = currentYawDelta;
if(currentYawDelta != 0f) {
currentYawDelta = 0f;
}
return out;
return currentCameraAngle.getYaw();
}

public Triple<Float, Float, Float> getInterpolatedState(float partialTick, float pitch, float yaw, boolean enable){
if(!enable) {
return Triple.of(pitch, yaw, 0f);
return Triple.of(nextCameraAngle.getPitch(), nextCameraAngle.getYaw()+180, 0f);
}

float interpolatedPitch = 0f;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/tasmod/virtual/VirtualInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.minecrafttas.tasmod.virtual.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.minecrafttas.tasmod.virtual.VirtualInput;
Expand Down

0 comments on commit 672ade9

Please sign in to comment.