Project world points through the last drawn frame's camera (#132)

render.project (API level 31) returns where a world point lands on the
screen, in GUI pixels, through the camera the last drawn frame used:
the player's own view or a mod's set-main-view camera, the bob and the
spin included, at most a frame behind. None for a point behind the
camera, and with no world or drawn frame yet; a point off the screen
still projects past its edges, for the caller to clip.

The game copies the frame's eye and view-projection into the mod
snapshot after a world frame is drawn, and clears it when another world
is entered, so a stale camera never projects into the new one. The
projection is camera-relative, as the world's geometry is drawn, with
the renderer's own f32 precision far from the origin.

For AirDef's world overlay: square markers over visible targets while
a key is held, on top of normal gameplay. The UI test guest calls the
new function so the sandbox checks the level-31 contract.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
2026-11-20 23:54:29 +03:00
parent a861c1ed24
commit 2bcce64236
9 changed files with 258 additions and 4 deletions
+1
View File
@@ -907,6 +907,7 @@ Where a capture is.
| --- | --- | --- |
| `set-hud` | `func(shapes: list<shape>)` | Replaces the mod's HUD shapes: up to 1024, drawn every frame in order over the HUD (after the hotbar, under chat and screens), hidden with the HUD (F1). An empty list removes them. |
| `gui-size` | `func() -> tuple<f32, f32>` | The screen's size in GUI pixels (width, height), as of this tick. |
| `project` | `func(x: f64, y: f64, z: f64) -> option<point>` | Where a world point lands on the screen, in GUI pixels from the top left, through the camera the last drawn frame used (AirDef fork, API level 31): the player's own view, or the `set-main-view` camera when one is up, at most a frame behind. None for a point behind the camera, and with no world or drawn frame yet. A point off the screen still projects, past its edges: the caller clips. For a mod's `set-hud` markers over the world as the player sees it. |
| `shake` | `func(strength: f32, seconds: f32)` | Shakes the camera: a jolt of `strength` (0 to 1, 1 the hardest) that fades out over `seconds` (at most 10). Jolts add up to 1. The view turns, the player doesn't, and the player's Distortion Effects option scales it (0 turns it off). |
| `set-corner` | `func(corner: corner, width: f32, height: f32, shapes: list<shape>)` | Replaces the mod's corner panel: shapes in GUI pixels from the top left of a `width` × `height` box that the game places in `corner`, stacked with the game's overlays and the other mods' panels (under the status effects at the top right), as `hud`'s panels are. |
| `clear-corner` | `func()` | Removes the mod's corner panel. |