Skip to content

Commit

Permalink
More correct yaw calculations for skin tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 15, 2016
1 parent f64d4e5 commit b240b99
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/main/java/net/citizensnpcs/npc/skin/SkinUpdateTracker.java
Expand Up @@ -92,10 +92,18 @@ private boolean canSee(Player player, SkinnableEntity skinnable, boolean checkFo
double angle = Math.atan2(deltaX, deltaZ);
float skinYaw = NMS.clampYaw(-(float) Math.toDegrees(angle));
float playerYaw = NMS.clampYaw(playerLoc.getYaw());
float upperBound = playerYaw + FIELD_OF_VIEW;
float lowerBound = playerYaw - FIELD_OF_VIEW;

return skinYaw >= lowerBound && skinYaw <= upperBound;
float upperBound = NMS.clampYaw(playerYaw + FIELD_OF_VIEW);
float lowerBound = NMS.clampYaw(playerYaw - FIELD_OF_VIEW);
if (upperBound == -180.0 && playerYaw > 0) {
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;
Expand Down Expand Up @@ -382,6 +390,7 @@ private class PlayerTracker {
final Location location = new Location(null, 0, 0, 0);
float lowerBound;
int rotationCount;
float startYaw;
float upperBound;

PlayerTracker(Player player) {
Expand All @@ -392,6 +401,7 @@ private class PlayerTracker {
void hardReset(Player player) {
this.hasMoved = false;
this.rotationCount = 0;
this.lowerBound = this.upperBound = this.startYaw = 0;
this.fovVisibleSkins.clear();
reset(player);
}
Expand All @@ -402,8 +412,12 @@ void reset(Player player) {
if (rotationCount < 3) {
float rotationDegrees = Settings.Setting.NPC_SKIN_ROTATION_UPDATE_DEGREES.asFloat();
float yaw = NMS.clampYaw(this.location.getYaw());
this.upperBound = yaw + rotationDegrees;
this.lowerBound = yaw - rotationDegrees;
this.startYaw = yaw;
this.upperBound = NMS.clampYaw(yaw + rotationDegrees);
this.lowerBound = NMS.clampYaw(yaw - rotationDegrees);
if (upperBound == -180.0 && startYaw > 0) {
upperBound = 0;
}
}
}

Expand All @@ -417,7 +431,12 @@ boolean shouldUpdate(Player player) {

if (rotationCount < 3) {
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
// after the player logs/teleports.
Expand Down

0 comments on commit b240b99

Please sign in to comment.