A symmetric perspective projection from a vertical field of view in radians, the aspect ratio (width over height), and the near and far distances. Right-handed, camera looks along -z, clip depth -1..1 (0..1 with depth_range_01 = true). x_offset and y_offset shear the frustum for jittering or off-center views. The field of view must be in (0, pi) and z_near and z_far positive and different.
m := make_projection_matrix(PI / 2, 1.0, 1, 100);
p := m * xyzw(0, 0, -1, 1);
assert(abs(p.x) < 0.0001 && abs(p.w - 1) < 0.0001);
p = m * xyzw(1, 1, -1, 1); // a point at 45 degrees lands at the edge of clip space
assert(abs(p.x / p.w - 1) < 0.0001 && abs(p.y / p.w - 1) < 0.0001);make_projection_matrix :: (
fov_vertical: float,
aspect_ratio_horizontal_over_vertical: float,
z_near: float,
z_far: float,
x_offset := 0.0,
y_offset := 0.0,
depth_range_01 := false
) -> Matrix4
A perspective projection from a field of view.
Parameters
- fov_vertical: float
- the vertical field of view in radians.
- aspect_ratio_horizontal_over_vertical: float
- width divided by height.
- z_near: float
- distance to the near plane.
- z_far: float
- distance to the far plane.
- x_offset := 0.0
- shifts the view centre horizontally.
- y_offset := 0.0
- shifts the view centre vertically.
- depth_range_01 := false
- true maps depth to
0..1, false to-1..1.