@@ -105,6 +105,11 @@ public abstract class SerialiserFlavorBase implements Registerable {
105
105
*/
106
106
protected boolean processExtensions = true ;
107
107
108
+ /**
109
+ * Rotation counter for clamping the yaw
110
+ */
111
+ protected int yawRotations = 0 ;
112
+
108
113
/*==============================================
109
114
_____ _ _ _
110
115
/ ____| (_) | (_)
@@ -488,7 +493,7 @@ protected List<String> serialiseCameraAngle(VirtualCameraAngle cameraAngle) {
488
493
* @return The serialised camera angle subtick
489
494
*/
490
495
protected String serialiseCameraAngleSubtick (VirtualCameraAngle cameraAngleSubtick ) {
491
- return String .format ("%s;%s" , cameraAngleSubtick .getYaw (), cameraAngleSubtick .getPitch ());
496
+ return String .format ("%s;%s" , clampYaw ( cameraAngleSubtick .getYaw () ), cameraAngleSubtick .getPitch ());
492
497
}
493
498
494
499
/**
@@ -1402,6 +1407,8 @@ protected VirtualCameraAngle deserialiseCameraAngle(List<String> cameraAngleStri
1402
1407
if (!"null" .equals (cameraPitchString ))
1403
1408
cameraPitch = deserialiseRelativeFloat ("camera pitch" , cameraPitchString , previousPitch );
1404
1409
1410
+ cameraYaw = unclampYaw (cameraYaw , previousYaw );
1411
+
1405
1412
out .updateFromState (cameraPitch , cameraYaw );
1406
1413
1407
1414
previousYaw = cameraYaw ;
@@ -1749,6 +1756,44 @@ protected String charListToString(List<Character> charList) {
1749
1756
return charString ;
1750
1757
}
1751
1758
1759
+ /**
1760
+ * <p>Clamps the yaw to a value between -180 and 180
1761
+ * @param yaw The yaw to clamp
1762
+ * @return The clamped yaw
1763
+ */
1764
+ protected Float clampYaw (Float yaw ) {
1765
+ if (yaw == null )
1766
+ return yaw ;
1767
+
1768
+ while (yaw >= 180 )
1769
+ yaw -= 360 ;
1770
+ while (yaw < -180 )
1771
+ yaw += 360 ;
1772
+ return yaw ;
1773
+ }
1774
+
1775
+ /**
1776
+ * <p>Unclamping the yaw from a clamped value
1777
+ * <p>Makes it so 170 and a previous value of -170 will return -190,<br>
1778
+ * removing the -180 180 clamp. Uses {@link #yawRotations}
1779
+ * @param yaw The yaw to unclamp
1780
+ * @param previous The previous yaw to compare against.
1781
+ * @return The unclamped yaw
1782
+ */
1783
+ protected Float unclampYaw (Float yaw , Float previous ) {
1784
+ if (previous == null || yaw == null )
1785
+ return yaw ;
1786
+
1787
+ float clampedPrevious = clampYaw (previous );
1788
+ if (clampedPrevious >= 0 && (clampedPrevious - yaw ) > 180 ) {
1789
+ yawRotations ++;
1790
+ }
1791
+ if (clampedPrevious < 0 && (clampedPrevious - yaw ) < -180 ) {
1792
+ yawRotations --;
1793
+ }
1794
+ return yaw + (360 * yawRotations );
1795
+ }
1796
+
1752
1797
@ Override
1753
1798
public String toString () {
1754
1799
return getExtensionName ();
0 commit comments