Skip to main content

camera_relative_view

Function camera_relative_view 

Source
pub fn camera_relative_view(
    view: [[f32; 4]; 4],
    cam_pos: [f32; 3],
    origin: [f32; 3],
) -> [[f32; 4]; 4]
Expand description

Rebase a column-major view matrix onto a render origin for camera-relative rendering.

The returned matrix keeps view’s orientation but places the camera at cam_pos - origin, so geometry expressed relative to origin transforms identically to the absolute scene – camera_relative_view(view, ..) * model_relative equals view * model_absolute – while being computed entirely from small coordinates, avoiding the catastrophic cancellation a large-magnitude view * model product suffers.

Only the rotation (the upper-left 3x3) of view is used; the translation column is rebuilt as rotation * (origin - cam_pos). That subtraction is exact in f32 when the camera sits within a chunk of the origin (two nearby like-signed values subtract without rounding), so no precision is lost rebasing.