Skip to content

Commit

Permalink
Fix rotation interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyydotp committed Jun 6, 2024
1 parent 8fd958d commit 1f05b84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "me.lucyydotp"
version = "0.1.1"
version = "0.1.2-SNAPSHOT"

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/lucyydotp/papers/CameraPerspectiveMode.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.lucyydotp.papers;

import com.mojang.blaze3d.vertex.PoseStack;
import me.lucyydotp.papers.util.RotationInterpolator;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaternionf;
Expand Down Expand Up @@ -69,12 +69,12 @@ public void transform(PoseStack cameraPoseStack, float tickProgress, long time)

cameraPoseStack.rotateAround(
new Quaternionf()
.rotateAxis((float) Math.toRadians(Mth.lerp(tickProgress, lastPose.getZ(), pose.getZ())), player.getForward().toVector3f())
.rotateAxis((float) Math.toRadians(Mth.lerp(tickProgress, lastPose.getY(), pose.getY())), player.getUpVector(1).toVector3f())
.rotateAxis((float) Math.toRadians(Mth.lerp(tickProgress, -lastPose.getX(), -pose.getX())), player.getForward().toVector3f().rotateY((float) (Math.PI / 2f))),
.rotateAxis((float) Math.toRadians(RotationInterpolator.lerpDegrees(tickProgress, lastPose.getZ(), pose.getZ())), player.getForward().toVector3f())
.rotateAxis((float) Math.toRadians(RotationInterpolator.lerpDegrees(tickProgress, lastPose.getY(), pose.getY())), player.getUpVector(1).toVector3f())
.rotateAxis((float) Math.toRadians(RotationInterpolator.lerpDegrees(tickProgress, -lastPose.getX(), -pose.getX())), player.getForward().toVector3f().rotateY((float) (Math.PI / 2f))),
0,
// fixme: this might be a little low?
(float) (-player.getBbHeight() - player.getMyRidingOffset()),
(float) -1,
0
);
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/me/lucyydotp/papers/util/RotationInterpolator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.lucyydotp.papers.util;


import net.minecraft.util.Mth;

public class RotationInterpolator {

public static float lerpDegrees(float f, float start, float end) {
if (f <= 0.0) return start;
if (f >= 1.0) return end;
if (Math.abs(end - start) > 180) {
return Mth.lerp(f, start, end + 360);
}
return Mth.lerp(f, start, end);
}
}

0 comments on commit 1f05b84

Please sign in to comment.