rgl.setMouseCallbacks {rgl}R Documentation

User callbacks on mouse events

Description

This function sets user callbacks on mouse events.

Usage

rgl.setMouseCallbacks(button, begin = NULL, update = NULL, end = NULL)

Arguments

button Which button?
begin Called when mouse down event occurs
update Called when mouse moves
end Called when mouse is released

Details

This function sets an event handler on mouse events that occur within the current rgl window. The begin and update events should be functions taking two arguments; these will be the mouse coordinates when the event occurs. The end event handler takes no arguments.

Alternatively, the handlers may be set to NULL, the default value, in which case no action will occur.

Value

This function is called for the side effect of setting the mouse event handlers.

Author(s)

Duncan Murdoch

See Also

par3d to set built-in handlers

Examples


## Not quite right --- this doesn't play well with rescaling

 pan3d <- function(button) {
   start <- list()
   
   begin <- function(x, y) {
       start$userMatrix <<- par3d("userMatrix")
       start$viewport <<- par3d("viewport")
       start$scale <<- par3d("scale")
       start$projection <<- rgl.projection()
       start$pos <<- rgl.window2user( x/start$viewport[3], 1 - y/start$viewport[4], 0.5, 
                                      projection=start$projection)
   }
   
   update <- function(x, y) {
        xlat <- (rgl.window2user( x/start$viewport[3], 1 - y/start$viewport[4], 0.5,
                                 projection = start$projection) - start$pos)*start$scale
        mouseMatrix <- translationMatrix(xlat[1], xlat[2], xlat[3])
        par3d(userMatrix = start$userMatrix %*% t(mouseMatrix) )
   }
   rgl.setMouseCallbacks(button, begin, update)
   cat("Callbacks set on button", button, "of rgl device",rgl.cur(),"\n")
 }
 pan3d(3)

[Package rgl version 0.81 Index]