Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public void onPlayback(long tick, InputContainer inputContainer) {
}
}

@Override
public void onRecord(long tick, InputContainer inputContainer) {
// TODO Auto-generated method stub
super.onRecord(tick, inputContainer);
}

@Override
public void onClear() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public abstract class SerialiserFlavorBase implements Registerable {
*/
protected boolean processExtensions = true;

/**
* Rotation counter for clamping the yaw
*/
protected int yawRotations = 0;

/*==============================================
_____ _ _ _
/ ____| (_) | (_)
Expand Down Expand Up @@ -488,7 +493,7 @@ protected List<String> serialiseCameraAngle(VirtualCameraAngle cameraAngle) {
* @return The serialised camera angle subtick
*/
protected String serialiseCameraAngleSubtick(VirtualCameraAngle cameraAngleSubtick) {
return String.format("%s;%s", cameraAngleSubtick.getYaw(), cameraAngleSubtick.getPitch());
return String.format("%s;%s", clampYaw(cameraAngleSubtick.getYaw()), cameraAngleSubtick.getPitch());
}

/**
Expand Down Expand Up @@ -1402,6 +1407,8 @@ protected VirtualCameraAngle deserialiseCameraAngle(List<String> cameraAngleStri
if (!"null".equals(cameraPitchString))
cameraPitch = deserialiseRelativeFloat("camera pitch", cameraPitchString, previousPitch);

cameraYaw = unclampYaw(cameraYaw, previousYaw);

out.updateFromState(cameraPitch, cameraYaw);

previousYaw = cameraYaw;
Expand Down Expand Up @@ -1749,6 +1756,44 @@ protected String charListToString(List<Character> charList) {
return charString;
}

/**
* <p>Clamps the yaw to a value between -180 and 180
* @param yaw The yaw to clamp
* @return The clamped yaw
*/
protected Float clampYaw(Float yaw) {
if (yaw == null)
return yaw;

while (yaw >= 180)
yaw -= 360;
while (yaw < -180)
yaw += 360;
return yaw;
}

/**
* <p>Unclamping the yaw from a clamped value
* <p>Makes it so 170 and a previous value of -170 will return -190,<br>
* removing the -180 180 clamp. Uses {@link #yawRotations}
* @param yaw The yaw to unclamp
* @param previous The previous yaw to compare against.
* @return The unclamped yaw
*/
protected Float unclampYaw(Float yaw, Float previous) {
if (previous == null || yaw == null)
return yaw;

float clampedPrevious = clampYaw(previous);
if (clampedPrevious >= 0 && (clampedPrevious - yaw) > 180) {
yawRotations++;
}
if (clampedPrevious < 0 && (clampedPrevious - yaw) < -180) {
yawRotations--;
}
return yaw + (360 * yawRotations);
}

@Override
public String toString() {
return getExtensionName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,20 @@ void testJoinNotEmpty() {
assertEquals(expected, actual);
}

/**
* Testing {@link #clampYaw(Float)} to force the yaw between -180 and 180
*/
@Test
void testYawClamping() {
assertEquals(-170f, clampYaw(190f));
assertEquals(160f, clampYaw(-200f));
}

@Test
void testYawUnclamping() {
assertEquals(-190f, unclampYaw(170f, -170f));
}

private <T extends Serializable> void assertBigArrayList(BigArrayList<T> expected, BigArrayList<T> actual) {
assertIterableEquals(convertBigArrayListToArrayList(expected), convertBigArrayListToArrayList(actual));
}
Expand All @@ -1078,5 +1092,4 @@ private <T extends Serializable> ArrayList<T> convertBigArrayListToArrayList(Big
public SerialiserFlavorBase clone() {
return new SerialiserFlavorBaseTest();
}

}