# bounce.py from vpython demos put into syzygy # distributed scenegraph format, prototype 1 # 19apr05 Ben Schaeffer and George Francis from PySZG import * import time import sys ff= arDistSceneGraphFramework(); if not ff.init(sys.argv): print("initfailed") sys.exit(0) dgLight("light0","root",0,arVector4(0,0,1,0),arVector3(1,1,1) ) dgTransform("basetransform","root", ar_translationMatrix(0,2,-5) ) #an object needs all of this tid = dgTransform("balltransform", "basetransform", \ ar_translationMatrix(0,4,-0) ) mm=ar_scaleMatrix(0.3,0.3,0.3) #mm= arMatrix4(1,0,0,0,2,0, etc) dgTransform("scaleball","balltransform", mm ) #these names need to be unique, for a bunch of balls, #dgMaterial("ballcolor"+str(ballid),"scaleball", arVector3(1,0,0)) dgMaterial("ballcolor","scaleball", arVector3(1,0,0)) ss=arSphereMesh(20) ss.attachMesh("ball1","ballcolor") mm=ar_translationMatrix(0,1,0) dgTransform("boxtransform","basetransform", mm ) mm=ar_scaleMatrix(4,0.3,4) dgTransform("boxscale","boxtransform", mm ) dgMaterial("boxcolor","boxscale", arVector3(1,1,0)) bx=arCubeMesh() bx.attachMesh("floor","boxcolor") if not ff.start(): print("startfailed") sys.exit(0) #floor = box(length=4, height=0.5, width=4, color=color.blue) #ball = sphere(pos=(0,4,0), color=color.red) #ball.velocity = vector(0,-1,0) pos = arVector3(0,4,0) velocity = arVector3(0,-1,0) dt = 0.01 while 1: # rate(100) time.sleep(.01) # for ii in range(10): pos = pos + velocity*dt if pos[1] < 1: velocity[1] = -velocity[1] else: velocity[1] = velocity[1] - 9.8*dt dgTransform(tid, ar_translationMatrix(pos[0],pos[1],pos[2]))