import pyrtl, sys, math import wdino, fare def scalextransrotLeg(o,tx,ty,tz,rotx,rotz,sx,sy,sz): o.push() o.translate(tx,ty,tz) o.rotate(2,rotz) o.rotate(0,rotx) o.scale(sx,sy,sz) wdino.leg(o) o.pop() # x front leg =f back leg =b # z far leg=f near leg =n def pwalk(o,rotzbn, rotzbf, rotzfn, rotzff): scalextransrotLeg(o, -2, -1, 0.5, -10, rotzbn, 0.8, 1, 0.8) scalextransrotLeg(o, -2, -1, -0.5, 10, rotzbf, 0.8, 1, 0.8) scalextransrotLeg(o, 2, -1, 0.5, -10, rotzfn, 0.8, 1, 0.8) scalextransrotLeg(o, 2, -1, -0.5, 10, rotzff, 0.8, 1, 0.8) def walk(o,rotzbn, rotzbf, rotzfn, rotzff): o.begin() pwalk(o,rotzbn, rotzbf, rotzfn, rotzff) o.blend() def pre_wgrock(o,rotzbn, rotzbf, rotzfn, rotzff, ta, nr): o.begin() wdino.body(o) walk(o,rotzbn, rotzbf, rotzfn, rotzff) wdino.transneck(o, nr) wdino.tail(o,ta) o.blend() def wgrock(o,rotzbn, rotzbf, rotzfn, rotzff, ta, nr): o.push() o.translate(0, 4.1307, 0) pre_wgrock(o, rotzbn, rotzbf, rotzfn, rotzff, ta, nr) o.pop() def walkgrock(rotzbn, rotzbf, rotzfn, rotzff, ta, nr): o = wdino.pycsoft.CSoft() wgrock(o, rotzbn, rotzbf, rotzfn, rotzff, ta, nr) return o def mytry(rot): o = wdino.pycsoft.CSoft() o.push() # o.rotate(2, rot) o.scale(1, 5, 1) o.cylinder() o.pop() return o def rframe(cluster, n, rotzbn, rotzbf, rotzfn, rotzff, ta, nr, xpos, radius, theta, camx, camz): # create the scene scene = pyrtl.World() pyrtl.NewAlloc() #define some background objects scene.push() # checkers = pyrtl.Checkers(pyrtl.Material((0,0,0.5)), # pyrtl.Material((0,0.5,0))) # checkers.scale(30,1,30) # checkers.translate(0,0.02,0) scene.material(pyrtl.Material((1,1,1))) # scene.texture(checkers) turbg = pyrtl.Turbulence(pyrtl.Material((0.9,0.8,0.7)), pyrtl.Material((0.4,0.4,0.1)),5); scene.material(pyrtl.Material((1,1,1))) scene.texture(turbg) scene.scale(50,1,50) scene.floor() scene.pop() #sky scene.push() turb = pyrtl.Turbulence(pyrtl.Material((0.2,0.2,0.8)), pyrtl.Material((0.8,0.8,0.8)),5); scene.material(pyrtl.Material((1,1,1))) scene.texture(turb) scene.scale(100,100,100) scene.sphere() scene.pop() # scene.viewing( (4.400,-33.200), 0, (-2.450,-4.100) ) # scene.lookat( ( camx, 7, camz), (0.761914, 4, -1.256192) ) scene.lookat( ( 15, 9, 35), (0,2,0)) scene.image((320,240)) scene.push() scene.rotate(1, -theta*180/math.pi) scene.translate(0, 0, radius) scene.soft(walkgrock(rotzbn, rotzbf, rotzfn, rotzff, ta, nr)) scene.pop() # scene.soft(mytry(rotzbn)) scene.progress(1) scene.light((2, 20, 12), (0.9, 0.9, 0.9), 30) scene.light((16, 5, 20), (0.6, 0.6, 0.6), 35) if (cluster>0): scene.prender() else: scene.render() #file name format for mpeg converter scene.save('prod/dino.%06d.ppm' %(n)) pyrtl.KillAlloc() # end of rframe cluster=0 #if sys.argv[1:]: # cluster=0 # print 'Using local processor only, no cluster' #else: # cluster=1 # print 'Using the cluster' #number of frames is nlast * wc n=0 #last frame in a single cycle nlast=24 p2=2*math.pi #dt=(2.0*math.pi/(nlast-1)) dt=4.0/(nlast) dt2 = dt/2 print ' dt ',dt dtor=math.pi/180.0 #range of leg swing in degrees e.g. +/- 20 degrees range=20.0; # wc gives the number of walk cycles def walkcycle(n, theta, xpos, zpos, radius, dtheta): print 'Starting Frame ', n, ' position ',xpos, zpos camx=18.5 camz=13.5 t=0 while t<4: #legs rotzbn = range*fare.bell4(t++2) rotzbf = range*fare.bell4(t) rotzfn = range*fare.bell4(t) rotzff = range*fare.bell4(t+2) #tail rotation range is 15 to 22 degrees ta=fare.range(t,15,22) #neck rotation range is 11 to 17 degrees nr=fare.range(t,11,17) # xpos=radius*math.sin(theta) # zpos=radius*math.cos(theta) print n, '%10f ' %(xpos), '%10f ' %(zpos), '%10f ' %(theta) rframe(cluster, n, rotzbn, rotzbf, rotzfn, rotzff, ta, nr, radius, zpos, theta, camx, camz) t=t+dt theta=theta+dtheta n=n+1 return n, theta #end walkcycle k=12 radius=16 xpos=0 zpos=radius inf=[0,0] theta=0 dtheta=(2*math.pi)/((1+nlast)*k) print ' dtheta ', dtheta t=0 while (k>0): inf=walkcycle(inf[0], inf[1], xpos, zpos, radius, dtheta) k=k-1 print 'Finished ', inf[0]-1 , ' Frames ', ' position ',inf[1]