Skip to content
Prev 309727 / 398502 Next

rgl package and animation

On 12-11-02 7:47 PM, Robert Baer wrote:
Your code didn't include the mr variable, but I assume it's just 
max(dat$r).  With that assumption, I'd do the animation function as follows:

First, draw the new sphere at the first point and save the object id:

sphereid <- sphere3d(dat[1,c("X", "Y", "Z")], col="red", radius=1)

# Also save the spinner that you like:

spin <- spin3d( ) #maybe with different parms

# Now, the animation function:

f <- function(time) {
   par3d(skipRedraw = TRUE) # stops intermediate redraws
   on.exit(par3d(skipRedraw=FALSE)) # redraw at the end

   rgl.pop(id=sphereid) # delete the old sphere
   pt <- time %% 40 + 1 # compute which one to draw
   pnt <- dat[pt, c("X", "Y", "Z")] # maybe interpolate instead?
   sphereid <<- spheres3d(pnt, radius=1, col="red")
   spin(time)
}

Duncan Murdoch