A view matrix for a camera at viewpoint looking at look_at, with reference_up_vector fixing the roll. It maps world positions into camera space, where the camera sits at the origin. look_at must not equal viewpoint, and the up vector must not be parallel to the view direction (the result is NaN or garbage).
x_is_forward (default true) picks the camera axes. With it the camera looks along +x, with +z up and -y to the right. With x_is_forward = false it looks along -z, with +y up and +x to the right: the usual OpenGL view space, which is what make_projection_matrix and make_frustum_matrix expect.
view := make_look_at_matrix(xyz(0, 0, 5), xyz(0, 0, 0), xyz(0, 1, 0), x_is_forward = false);
p := transform_point(view, xyz(0, 0, 0));
assert(abs(p.x) < 0.0001 && abs(p.y) < 0.0001 && abs(p.z + 5) < 0.0001); // 5 units in front (-z)make_look_at_matrix :: (
viewpoint: Vector3,
look_at: Vector3,
reference_up_vector: Vector3,
$x_is_forward := true
) -> Matrix4
A view matrix for a camera at viewpoint looking at look_at.
Parameters
- viewpoint: Vector3
- where the camera is.
- look_at: Vector3
- the point it looks at.
- reference_up_vector: Vector3
- roughly which way is up. Must not be parallel to the view direction.
- $x_is_forward := true
- true makes the camera look down the x axis, false down the negative z axis.