Fixed funky rotations when swimming.

This commit is contained in:
Sollace 2019-07-05 11:00:41 +02:00
parent f1d1a2857d
commit f80166dd99
2 changed files with 12 additions and 4 deletions

View file

@ -2,7 +2,7 @@ package com.minelittlepony.client.transform;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import com.minelittlepony.util.math.MathUtil; import com.minelittlepony.model.IModel;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
public class PostureSwimming extends PostureFlight { public class PostureSwimming extends PostureFlight {
@ -17,10 +17,12 @@ public class PostureSwimming extends PostureFlight {
@Override @Override
protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) { protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) {
double motionLerp = MathUtil.clampLimit(Math.sqrt(motionX * motionX + motionZ * motionZ) * 30, 1) / 2; return 90; // mojang handles this
}
@Override
public void transform(IModel model, PlayerEntity player, double motionX, double motionY, double motionZ, float yaw, float ticks) {
GlStateManager.translated(0, 0.9, -1); GlStateManager.translated(0, 0.9, -1);
super.transform(model, player, motionX, motionY, motionZ, yaw, ticks);
return 90 + super.calculateIncline(player, motionX, motionY, motionZ) * motionLerp;
} }
} }

View file

@ -12,6 +12,9 @@ import com.minelittlepony.util.math.MathUtil;
*/ */
public abstract class MotionCompositor { public abstract class MotionCompositor {
/**
* Gets the angle of horizontal roll in degrees based on the player's vertical and horizontal motion.
*/
protected double calculateRoll(PlayerEntity player, double motionX, double motionY, double motionZ) { protected double calculateRoll(PlayerEntity player, double motionX, double motionY, double motionZ) {
// since model roll should probably be calculated from model rotation rather than entity rotation... // since model roll should probably be calculated from model rotation rather than entity rotation...
@ -36,6 +39,9 @@ public abstract class MotionCompositor {
return MathHelper.clamp(roll, -54, 54); return MathHelper.clamp(roll, -54, 54);
} }
/**
* Gets the angle of inclination in degrees based on the player's vertical and horizontal motion.
*/
protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) { protected double calculateIncline(PlayerEntity player, double motionX, double motionY, double motionZ) {
double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); double dist = Math.sqrt(motionX * motionX + motionZ * motionZ);
double angle = Math.atan2(motionY, dist); double angle = Math.atan2(motionY, dist);