satura/src/main/java/dev/loki/satura/interaction/movement/LookController.java
loki5512344 b26dfbbade
Satura: каркас мода, ядро, селекция, план, рендер, стратегии постановки и движок
Фазы 0-5: сборка Gradle/Loom, core (события, команды, конфиг), selection/plan/scan,
рендер (перенесён из Atheryx, см. NOTICE.md), стратегии ColumnDrop/BandStack,
HotbarRefill/ClickScheduler, BuildEngine и команды .build.
2026-10-16 10:21:20 +02:00

41 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dev.loki.satura.interaction.movement;
import dev.loki.satura.interaction.movement.io.PlayerPose;
/** Управление взглядом: плавный доворот с клампом °/тик и мгновенный взгляд вниз. */
public final class LookController {
public static final float MAX_YAW_STEP = 25f;
public static final float MAX_PITCH_STEP = 20f;
public static final float SNAP_EPSILON = 0.4f;
public static final float DOWN_PITCH = 90f;
private final PlayerPose pose;
public LookController(PlayerPose pose) {
this.pose = pose;
}
/** Доворот к точке за один тик; true, когда взгляд уже на цели. */
public boolean lookAtSmooth(double x, double y, double z) {
double dx = x - pose.x();
double dz = z - pose.z();
float targetYaw = Angles.yawTo(dx, dz);
float targetPitch = Angles.pitchTo(y - pose.eyeY(), Math.hypot(dx, dz));
float dYaw = Angles.wrap(targetYaw - pose.yaw());
float dPitch = targetPitch - pose.pitch();
if (Math.abs(dYaw) < SNAP_EPSILON && Math.abs(dPitch) < SNAP_EPSILON) {
pose.setYaw(targetYaw);
pose.setPitch(targetPitch);
return true;
}
pose.setYaw(Angles.approachYaw(pose.yaw(), targetYaw, MAX_YAW_STEP));
pose.setPitch(Angles.approachPitch(pose.pitch(), targetPitch, MAX_PITCH_STEP));
return false;
}
/** Мгновенно смотреть строго вниз (для стратегий столбика/пола). */
public void lookDown() {
pose.setPitch(DOWN_PITCH);
}
}