Commit eeec9218 by Jonathan Thomas

Fix camera pitch when close to entity or looking up in both 1st and 3rd person views.

parent 8982b58c
Pipeline #11649 passed with stage
in 20 seconds
...@@ -149,18 +149,18 @@ public class ClientInit implements ClientModInitializer { ...@@ -149,18 +149,18 @@ public class ClientInit implements ClientModInitializer {
// Get camera position // Get camera position
Vec3d interpolatedCameraPos; Vec3d interpolatedCameraPos;
double cameraHeight = 0D;
if (MinecraftClient.getInstance().options.getPerspective().isFirstPerson()) { if (MinecraftClient.getInstance().options.getPerspective().isFirstPerson()) {
// 1st person, Use the cameraEntity (interpolate for smooth motion) // 1st person, Use the cameraEntity (interpolate for smooth motion)
cameraHeight = cameraEntity.getHeight();
interpolatedCameraPos = new Vec3d( interpolatedCameraPos = new Vec3d(
MathHelper.lerp(partialTicks, cameraEntity.prevX, cameraEntity.getPos().x), MathHelper.lerp(partialTicks, cameraEntity.prevX, cameraEntity.getPos().x),
MathHelper.lerp(partialTicks, cameraEntity.prevY, cameraEntity.getPos().y) + cameraEntity.getHeight(), MathHelper.lerp(partialTicks, cameraEntity.prevY, cameraEntity.getPos().y),
MathHelper.lerp(partialTicks, cameraEntity.prevZ, cameraEntity.getPos().z) MathHelper.lerp(partialTicks, cameraEntity.prevZ, cameraEntity.getPos().z)
); );
} else { } else {
// Use the camera (3rd person) // Use the camera (3rd person)
interpolatedCameraPos = new Vec3d(camera.getPos().x, interpolatedCameraPos = new Vec3d(camera.getPos().x, camera.getPos().y, camera.getPos().z);
camera.getPos().y,
camera.getPos().z);
} }
// Get all entities // Get all entities
...@@ -199,8 +199,8 @@ public class ClientInit implements ClientModInitializer { ...@@ -199,8 +199,8 @@ public class ClientInit implements ClientModInitializer {
// Translate to the entity's position // Translate to the entity's position
matrices.translate(interpolatedEntityPos.x - interpolatedCameraPos.x, matrices.translate(interpolatedEntityPos.x - interpolatedCameraPos.x,
interpolatedEntityPos.y - interpolatedCameraPos.y + entity.getHeight() + paddingAboveEntity, (interpolatedEntityPos.y + entity.getHeight()) - (interpolatedCameraPos.y + cameraHeight) + paddingAboveEntity,
interpolatedEntityPos.z - interpolatedCameraPos.z); interpolatedEntityPos.z - interpolatedCameraPos.z);
// Calculate the difference vector (from entity to camera) // Calculate the difference vector (from entity to camera)
Vec3d difference = interpolatedCameraPos.subtract(interpolatedEntityPos); Vec3d difference = interpolatedCameraPos.subtract(interpolatedEntityPos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment