Builds a 4x4 transform whose rows are the world-space basis (right, up, forward). Use with transform_mesh() (rotation) and translate_mesh() (position).

lookat_transform(pos = c(0, 0, 0), look = c(0, 0, 1), up = c(0, 1, 0))

Arguments

pos

Default c(0,0,0). World-space origin of the local frame.

look

Default c(0,0,1). World-space point to look at.

up

Default c(0,1,0). World-space up direction (need not be unit length).

Value

4x4 numeric matrix. The upper-left 3x3 is the rotation used by transform_mesh(). The last column contains pos for convenience, but translation should be applied via translate_mesh().

Examples

if(run_documentation()) {
  m = sphere_mesh(radius = 0.5)
  pos  = c(-1,0,0)   # place Moon on the left
  look = c(0,0,0)    # look toward the origin (e.g., Earth/camera)
  up   = c(0,1,0)

  M = lookat_transform(pos = pos, look = look, up = up)

  m |>
    transform_mesh(M) |>
    translate_mesh(pos) |>
    rasterize_scene(lookfrom = c(0,0,0), lookat = pos,
      light_info = directional_light(direction = c(1,0,0)))
}