Skip to content

fix: use camera-relative coordinates to avoid float precision loss at large world coordinates - #38

Open
Whisperlyric wants to merge 1 commit into
maDU59:26.1.2from
Whisperlyric:fix/2612-camera-relative-rendering
Open

Whisperlyric wants to merge 1 commit into
maDU59:26.1.2from
Whisperlyric:fix/2612-camera-relative-rendering

Conversation

@Whisperlyric

Copy link
Copy Markdown

Problem

At large world coordinates (tens of millions, e.g. near the world border):

  • the trajectory line breaks up into discrete, disconnected segments, and
  • the impact block outline is distorted — it no longer forms a 1×1×1 cube
    (some edges stretched to several blocks), so the
    highlighted target can no longer be identified.

Cause: all render vertices were converted to float in absolute world
coordinates
(new Vector3f((float) pos.x, ...) for trajectory points,
float-cast box corners in RenderUtils). A float only has a 24-bit mantissa,
so at ~30,000,000 the spacing between representable values grows to 2–4 blocks:
adjacent line vertices snap onto the same coarse grid, which shatters the line,
and a box's min/max corners are rounded independently, so its edges no longer
span exactly one block.

Solution

Subtract the camera position on the CPU in double and convert the resulting
camera-relative offsets to float instead; relative coordinates are small, so no precision is lost. The now-redundant poseStack.translate(-cam) is removed. Applied to: - trajectory line segments and the impact cross (PtpClient.renderTrajectory) - highlight/outline boxes (RenderUtils.renderFilledBox / renderBox)

@Whisperlyric
Whisperlyric force-pushed the fix/2612-camera-relative-rendering branch from c860bb5 to faf07f1 Compare October 5, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant