More correct yaw calculations for skin tracking

This commit is contained in:
fullwall 2016-01-15 15:29:12 +08:00
parent 2f247b13d4
commit ce561150b6

View File

@ -92,10 +92,18 @@ public class SkinUpdateTracker {
double angle = Math.atan2(deltaX, deltaZ); double angle = Math.atan2(deltaX, deltaZ);
float skinYaw = NMS.clampYaw(-(float) Math.toDegrees(angle)); float skinYaw = NMS.clampYaw(-(float) Math.toDegrees(angle));
float playerYaw = NMS.clampYaw(playerLoc.getYaw()); float playerYaw = NMS.clampYaw(playerLoc.getYaw());
float upperBound = playerYaw + FIELD_OF_VIEW; float upperBound = NMS.clampYaw(playerYaw + FIELD_OF_VIEW);
float lowerBound = playerYaw - FIELD_OF_VIEW; float lowerBound = NMS.clampYaw(playerYaw - FIELD_OF_VIEW);
if (upperBound == -180.0 && playerYaw > 0) {
return skinYaw >= lowerBound && skinYaw <= upperBound; upperBound = 0;
}
boolean hasMoved;
if (playerYaw - 90 < -180 || playerYaw + 90 > 180) {
hasMoved = skinYaw > lowerBound && skinYaw < upperBound;
} else {
hasMoved = skinYaw < lowerBound || skinYaw > upperBound;
}
return hasMoved;
} }
return true; return true;
@ -382,6 +390,7 @@ public class SkinUpdateTracker {
final Location location = new Location(null, 0, 0, 0); final Location location = new Location(null, 0, 0, 0);
float lowerBound; float lowerBound;
int rotationCount; int rotationCount;
float startYaw;
float upperBound; float upperBound;
PlayerTracker(Player player) { PlayerTracker(Player player) {
@ -392,6 +401,7 @@ public class SkinUpdateTracker {
void hardReset(Player player) { void hardReset(Player player) {
this.hasMoved = false; this.hasMoved = false;
this.rotationCount = 0; this.rotationCount = 0;
this.lowerBound = this.upperBound = this.startYaw = 0;
this.fovVisibleSkins.clear(); this.fovVisibleSkins.clear();
reset(player); reset(player);
} }
@ -402,8 +412,12 @@ public class SkinUpdateTracker {
if (rotationCount < 3) { if (rotationCount < 3) {
float rotationDegrees = Settings.Setting.NPC_SKIN_ROTATION_UPDATE_DEGREES.asFloat(); float rotationDegrees = Settings.Setting.NPC_SKIN_ROTATION_UPDATE_DEGREES.asFloat();
float yaw = NMS.clampYaw(this.location.getYaw()); float yaw = NMS.clampYaw(this.location.getYaw());
this.upperBound = yaw + rotationDegrees; this.startYaw = yaw;
this.lowerBound = yaw - rotationDegrees; this.upperBound = NMS.clampYaw(yaw + rotationDegrees);
this.lowerBound = NMS.clampYaw(yaw - rotationDegrees);
if (upperBound == -180.0 && startYaw > 0) {
upperBound = 0;
}
} }
} }
@ -417,7 +431,12 @@ public class SkinUpdateTracker {
if (rotationCount < 3) { if (rotationCount < 3) {
float yaw = NMS.clampYaw(currentLoc.getYaw()); float yaw = NMS.clampYaw(currentLoc.getYaw());
boolean hasRotated = yaw < lowerBound || yaw > upperBound; boolean hasRotated;
if (startYaw - 90 < -180 || startYaw + 90 > 180) {
hasRotated = yaw > lowerBound && yaw < upperBound;
} else {
hasRotated = yaw < lowerBound || yaw > upperBound;
}
// update the first 3 times the player rotates. helps load skins around player // update the first 3 times the player rotates. helps load skins around player
// after the player logs/teleports. // after the player logs/teleports.