[R] movie3d function in the rgl package
Dani
danicyber at gmail.com
Fri Oct 24 19:55:46 CEST 2008
Dear list,
I'm using the function "movie3d" in the package "rgl" to create a .gif
animation of a 3d graphic. The program "ImageMagik" is working
properly, R packages are working, basic examples available in the
manual also working fine.
Problem Solved: when I tried to create more complex movies, i.e.
combining different views and zooming, the R-console crashed or
returned error playing the function returned by par3dinterp, using
heterogeneous parameters. When not crashing, "Error:
length(userMatrix) == 16 * length(times) is not TRUE."
Counterexample:
#rotating
v=seq(from=1,to=61,by=2.5)
for (i in 1:length(v)){
rgl.viewpoint(270+v[i],80-(v[i]/1)) #This is a counterexample
M <- par3d()
lista[[k]]=M;
k=k+1;
}
#zooming
v=seq(from=1,to=0.12,by=-0.02)
for (i in 1:length(v)){
par3d(zoom=v[i])
M <- par3d()
lista[[k]]=M; k=k+1;
}
#-------------- Ending view
rgl.viewpoint(326,40)
par3d(zoom=1)
M <- par3d()
lista[[k]]=M; k=k+1;
p = par3dinterp(lista)
play3d(p) # or movie3d (p,12)
----------------------------------------------------------------------
Light: after 2 weeks fighting with the function + a bag of coffee, I
found this function really helpful and I WANTED TO SHARE since I
didn't find anything like that in the web.
Step 1: set the zooming parameters to each view you want in a separate
vector (list_zooming) while accumulating the views in the
list_userMatrix
#rotating
v=seq(from=1,to=61,by=30)#2.5)
for (i in 1:length(v))
{
rgl.viewpoint(270+v[i],80-(v[i]/1))
M <- par3d("userMatrix") #This is an example who runs perfectly
list_userMatrix[[k]]=M;
k=k+1;
}
list_z=rep(1,length(v)); list_zooming=c(list_zooming,list_z)
#zooming
v=c(1,0.12)#seq(from=1,to=0.12,by=-0.2)
for (i in 1:length(v))
{
list_zooming=c(list_zooming,v[i])
M <- par3d("userMatrix")
list_userMatrix[[k]]=M; k=k+1;
}
#--------------
rgl.viewpoint(345,30)
par3d(zoom=0.1)
M <- par3d("userMatrix")
list_userMatrix[[k]]=M; k=k+1;
p = par3dinterp( userMatrix=list_userMatrix,zoom=list_zooming)
movie3d (p,duration=12)#as.integer(length(list_userMatrix)))
#play3d(p)
Hope it was helpful! Good lucky!
--
-------------------------------------
Daniela
More information about the R-help
mailing list