View Single Post
  #1  
Old 04-10-2009, 12:13 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
multiple objects

Im trying to think of a faster way to write this code. I have 3 objects. All 3 objects work as a whole. For example. Object 1 fits inside of object 2 and object 2 fits inside of object 3. So image a telescope that collapses. Below is the code that goes with these objects. How can I make multiple instance of these objects without writing a ton of extra code. Like I dont want to do bottom, bottom2, bottom3...etc. But maybe that is the only way. Any suggestions? I can clarify more if need be.

Thanks


Code:
import viz
import vizact
import viztask
import random

viz.go()

PORT_PPT = 6

viz.add('tut_ground.wrl')

viz.MainView.setPosition([0,10,-35]) #sets camera position
viz.MainView.setEuler([0,2,0]) #sets camera pitch

bottom = viz.add('growthBOTTOM.wrl')
middle = viz.add('growthMIDDLE.wrl')
top = viz.add('growthTOP.wrl')

#sets them on the same x z axis but different on the y axis
bottom.setPosition([0,5,0])
bottom.scale(.2,.2,.2)
middle.setPosition([0,7,0])
middle.scale(.2,.2,.2)
top.setPosition([0,9,0])
top.scale(.2,.2,.2)

ppt1 = viz.add('vizppt.dls')

ball1 = viz.add('white_ball.wrl')
ball1.scale(1,1,1)
ballLink1 = viz.link(ppt1, ball1)
ballLink1.postScale([8,1,13],target = viz.LINK_FULL_OP)

def moveFlower():
	x,y,z = ball1.getPosition()
	

	if y <= 6:
		middle.setPosition([0,6,0])
		top.setPosition([0,7,0])

             #moves top piece with middle piece
	elif y < 6 and y <= 10:
		middle.setPosition([0,y,0])
		top.setPosition([0,y+1,0])

             #just moves top piece
	elif y > 10:
		middle.setPosition([0,10,0])
		top.setPosition([0,y,0])
		
vizact.ontimer2(0,viz.FOREVER,moveFlower)
Reply With Quote