fix: remove X mirror, fix rotation float tolerance

UB mirrors both cell positions and player position within layer space,
so relative offset is direct (mirrors cancel out). Removed X negation.
Added float tolerance for rotation quaternion W component comparison
(was using strict equality which fails on floating point values).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-08 15:48:07 +02:00
parent b067a148f3
commit 8d2e74397b

View file

@ -3858,8 +3858,10 @@ function updateRadarWindow(msg) {
const hasTiles = dungeonTileCanvases && Object.keys(dungeonTileCanvases).length > 0;
// Normalize rotation value to radians (same as UB's DungeonCell.cs)
// Raw value is quaternion W component: 1→180°, ~0.707→-90°, ~-0.707→90°, 0→0°
function cellRotation(rot) {
if (rot === 1) return Math.PI;
if (Math.abs(rot - 1) < 0.01) return Math.PI;
if (Math.abs(rot + 1) < 0.01) return Math.PI;
if (rot < -0.70 && rot > -0.8) return Math.PI / 2;
if (rot > 0.70 && rot < 0.8) return -Math.PI / 2;
return 0;
@ -3877,8 +3879,9 @@ function updateRadarWindow(msg) {
ctx.globalAlpha = isCurrentFloor ? 0.85 : 0.12;
(level.cells || []).forEach(cell => {
// UB mirrors X, Y flipped for north-up (AC Y+ = north, canvas Y+ = down)
const dx = -(cell.x - playerX) * scale;
// Direct relative position (UB mirrors both cell and player, cancels out)
// Y negated for north-up (AC Y+ = north, canvas Y+ = down)
const dx = (cell.x - playerX) * scale;
const dy = -(cell.y - playerY) * scale;
const tileCanvas = hasTiles ? dungeonTileCanvases[String(cell.env_id)] : null;
@ -3976,7 +3979,7 @@ function updateRadarWindow(msg) {
// Use raw physics coords in dungeons (X mirrored), EW/NS on surface
let dX, dY;
if (isDungeon && obj.raw_x !== undefined) {
dX = -(obj.raw_x - playerX); // X mirrored
dX = (obj.raw_x - playerX);
dY = -(obj.raw_y - playerY); // Y flipped for north-up
} else {
dX = obj.ew - playerEW;
@ -4039,7 +4042,7 @@ function updateRadarWindow(msg) {
const withDist = objects.map(obj => {
let distMeters, dX, dY;
if (isDungeon && obj.raw_x !== undefined) {
dX = -(obj.raw_x - playerX);
dX = (obj.raw_x - playerX);
dY = -(obj.raw_y - playerY);
distMeters = Math.sqrt(dX * dX + dY * dY); // raw coords are ~meters
} else {