Skip to contents

Functions to retrieve, save, restore, list and remove rgl viewpoints; see Details for additional information.

Usage

add.viewpoint(name, view = getview3d())

set.viewpoint(name)

ls.viewpoints(...)

rm.viewpoints(...)

get.viewpoints()

getview3d()

setview3d(view)

Arguments

name

character string giving the name under which a viewpoint is stored (add.viewpoint()) or looked up (set.viewpoint()).

view

a list with the viewpoint parameters, typically the value returned by getview3d().

...

additional arguments to be passed to ls() or rm().

Value

add.viewpoint() is called for its side effect of storing view under name; it invisibly returns view.

set.viewpoint() is called for its side effect of restoring a stored viewpoint; it invisibly returns the corresponding view.

ls.viewpoints() returns a character vector with the names of the stored viewpoints.

rm.viewpoints() is called for its side effect of removing one or more stored viewpoints.

get.viewpoints() returns a named list with all the stored viewpoints.

getview3d() returns a list with the components zoom, userMatrix and userProjection (see rgl::par3d()).

setview3d() is called mainly for its side effect of setting the viewpoint of the active rgl device (see rgl::par3d()); it returns the value returned by par3d().

Details

add.viewpoint() stores view under name, silently overwriting any viewpoint previously stored under the same name. By default view is the current viewpoint, as returned by getview3d().

set.viewpoint() looks up the viewpoint stored under name and applies it to the active rgl device via setview3d().

ls.viewpoints() returns the names of all the viewpoints currently stored.

rm.viewpoints() removes one or more stored viewpoints by name; called with no arguments, it removes all of them.

get.viewpoints() returns a named list with all the viewpoints currently stored, one entry per name.

getview3d() retrieves the parameters that define the current viewpoint of the active rgl device (zoom, user matrix and user projection), so that they can be saved and restored later with setview3d().

setview3d() applies to the active rgl device a viewpoint previously obtained with getview3d() (this is also what set.viewpoint() uses internally to restore a stored viewpoint).

See also

Examples

library(rgl)
new3d()
shade3d(volcanom, col = "lightgreen")



# Save the current viewpoint under the name "default"
add.viewpoint("default")

# ... rotate, zoom or pan the scene interactively ...

# Restore the saved viewpoint
set.viewpoint("default")

# Names of the stored viewpoints
ls.viewpoints()
#> [1] "default"

# All stored viewpoints, as a named list
get.viewpoints()
#> $default
#> $default$zoom
#> [1] 1
#> 
#> $default$userMatrix
#>      [,1]       [,2]      [,3] [,4]
#> [1,]    1  0.0000000 0.0000000    0
#> [2,]    0  0.3420201 0.9396926    0
#> [3,]    0 -0.9396926 0.3420201    0
#> [4,]    0  0.0000000 0.0000000    1
#> 
#> $default$userProjection
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    0    1    0    0
#> [3,]    0    0    1    0
#> [4,]    0    0    0    1
#> 
#> 

# Remove all stored viewpoints
rm.viewpoints()
ls.viewpoints()
#> character(0)