implement camera/position quantization
This commit is contained in:
@@ -17,12 +17,22 @@ public class FpsCameraController {
|
||||
private float yaw = 0f;
|
||||
private float pitch = 0f;
|
||||
|
||||
private float eyeHeight = 1.8f;
|
||||
private final float eyeHeight = 1.8f;
|
||||
private final float jumpSpeed = 12f;
|
||||
private final float gravity = -50f;
|
||||
private float velocityY = 0f;
|
||||
private float gravity = -50f;
|
||||
private float jumpSpeed = 12f;
|
||||
private boolean grounded = false;
|
||||
|
||||
// --- approximation toggles
|
||||
private final boolean retroQuantization = true;
|
||||
|
||||
// how coarse the rotation is (0.25f = round to 0.25°)
|
||||
private final float yawStepDegrees = 0.2f;
|
||||
private final float pitchStepDegrees = 0.2f;
|
||||
|
||||
// how coarse the position is (16f = steps of 1/16 units)
|
||||
private final float positionQuantize = 64f;
|
||||
|
||||
private final Vector3 tmpForward = new Vector3();
|
||||
private final Vector3 tmpRight = new Vector3();
|
||||
|
||||
@@ -205,12 +215,29 @@ public class FpsCameraController {
|
||||
velocityY = jumpSpeed;
|
||||
grounded = false;
|
||||
}
|
||||
|
||||
// snap position to quantization steps
|
||||
if (retroQuantization) {
|
||||
float q = positionQuantize;
|
||||
camera.position.x = Math.round(camera.position.x * q) / q;
|
||||
camera.position.y = Math.round(camera.position.y * q) / q;
|
||||
camera.position.z = Math.round(camera.position.z * q) / q;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCameraDirection() {
|
||||
// build direction vector from yaw/pitch
|
||||
float yawRad = (float) Math.toRadians(yaw);
|
||||
float pitchRad = (float) Math.toRadians(pitch);
|
||||
float useYaw = yaw;
|
||||
float usePitch = pitch;
|
||||
|
||||
if (retroQuantization) {
|
||||
// snap yaw/pitch to fixed angular steps
|
||||
useYaw = Math.round(useYaw / yawStepDegrees) * yawStepDegrees;
|
||||
usePitch = Math.round(usePitch / pitchStepDegrees) * pitchStepDegrees;
|
||||
}
|
||||
|
||||
float yawRad = (float) Math.toRadians(useYaw);
|
||||
float pitchRad = (float) Math.toRadians(usePitch);
|
||||
|
||||
float x = (float) (Math.cos(pitchRad) * Math.sin(yawRad));
|
||||
float y = (float) Math.sin(pitchRad);
|
||||
|
||||
Reference in New Issue
Block a user