Skip to content

Add Mat44 perspective and orthographic projections - #67

Merged
crertel merged 2 commits into
masterfrom
44-mat44-projection
Sep 16, 2026
Merged

crertel merged 2 commits into
masterfrom
44-mat44-projection

Conversation

@crertel

@crertel crertel commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Adds Mat44.perspective/4 and Mat44.ortho/6 for projecting right-handed camera coordinates looking down -Z. Both use row vectors and map the near and far planes to normalized device depths -1 and +1, matching the OpenGL projection convention.

perspective(fov_y, aspect, near, far) takes a vertical field of view in radians and width/height aspect ratio. It requires 0 < fov_y < pi, positive aspect, and 0 < near < far; invalid parameters raise ArithmeticError. Its depth coefficients avoid multiplying near and far together, preventing avoidable overflow or underflow.

ortho(x_min, x_max, y_min, y_max, near, far) supports asymmetric volumes, reversed bounds for axis flips, and zero or negative near/far distances. Each pair must have nonzero extent; equal endpoints raise ArithmeticError.

The docs and examples show that perspective projection requires apply_left/2 followed by division by the output w; transform_point/2 discards that coordinate. Orthographic projection preserves w and supports transform_point/2 directly. Float typespecs and explicit float clauses with numeric fallbacks are preserved.

Validation: 570 tests and 5 doctests pass with 100% line coverage. Tests cover all near/far corners, known matrices, foreshortening and depth, homogeneous coordinates, camera translation composition, inverse round trips, reversed and fractional bounds, integer/mixed inputs, large/small distances, and invalid parameters. Formatting, compilation with warnings as errors, and documentation generation pass.

Part of #44. This PR is based on master and is independent of the camera/billboard implementation in #66.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — 44-mat44-projection into master

@coveralls

coveralls commented Sep 16, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — 44-mat44-projection into master

@crertel crertel self-assigned this Sep 16, 2026
@crertel
crertel merged commit 4e915c2 into master Sep 16, 2026
4 checks passed
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