WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   multiple objects (https://forum.worldviz.com/showthread.php?t=1963)

durf 04-10-2009 12:13 PM

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)


moooh 04-10-2009 01:42 PM

Sounds like all you need is to make a class to put the code in. Instantiate the class and you'll have a copy of the object that does not require code duplication.


All times are GMT -7. The time now is 04:14 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC