Repository navigation
Add Mat44 perspective and orthographic projections - #67
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Mat44.perspective/4andMat44.ortho/6for 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 requires0 < fov_y < pi, positive aspect, and0 < near < far; invalid parameters raiseArithmeticError. 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 raiseArithmeticError.The docs and examples show that perspective projection requires
apply_left/2followed by division by the outputw;transform_point/2discards that coordinate. Orthographic projection preserveswand supportstransform_point/2directly. 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.