Learn R Programming

rayvertex (version 0.15.0)

lookat_transform: Look-At Transform (row-vector convention)

Description

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

Usage

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

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().

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).

Examples

Run this code
if (FALSE) { # interactive() || isTRUE(as.logical(Sys.getenv("IN_PKGDOWN")))
  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)))
}

Run the code above in your browser using DataLab