Skip to content

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

Closed
Whisperlyric wants to merge 1 commit into
maDU59:mainfrom
Whisperlyric:263-camera-relative-rendering
Closed

Whisperlyric wants to merge 1 commit into
maDU59:mainfrom
Whisperlyric:263-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 marked this pull request as ready for review September 22, 2026 10:03
@Whisperlyric

Copy link
Copy Markdown
Author

Tips:this problem also exists in lower versions as 2612

@maDU59

maDU59 commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Why did you make a PR and close it?
Also it's fully vibecoded isn't it?

@Whisperlyric

Copy link
Copy Markdown
Author

Sorry for the confusion — I accidentally opened the same PR twice and closed the duplicate; the other one is still open.
I did use AI help while tracking the cause down, but I reviewed the diff myself and tested it in-game on both 26.1.2 and 26.3 at ~30M — the line and impact boxes render correctly now. If anything looks off to you I'm glad to adjust.

@maDU59

maDU59 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Ok I'll take a look at it then, my fault for not having a CONTRIBUTING.md but I'd rather not have AI-driven PR in the future.

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.

2 participants