WorldViz User Forum

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

durf 02-10-2009 02:00 PM

Moving multiple objects with ppt
 
Hello,

Just FYI I am new to python and Worldviz.

So far in my program I have created 3 images. A ball, a pillar, and a stage. My goal is to move the ppt sensor up, which will move the ball straight up and at the same time I want the pillar to move in the opposite direction. So in refrence... as ball moves up on the y axis positively the pillar moves down on the y axis negatively. The stage represtents the x axis which is position on y axis 0 and this represents the starting positions of my ball and pillar.

What I need to know is there any code that will make this happen? is this possible with python? and if so how can I set this code up to work?

feel free to contact me at bdoerfer@uwm.edu

Sorry for no indentations. This forum is not allowing me to. Thanks for any input.

Below is the code that i have used:

import viz
import vizinfo
viz.go()

viz.move(0,0,-7)
viz.clearcolor(viz.GRAY)

PORT_PPT = 6

numLights = viz.input('How many lights are you tracking?')
numLights = min(8,numLights)

colors = [
[0, 1, 0.545],
[1, 0, 1],
[0, 1, 1],
[1, 1, 0.545],
[1, 0, 0],
[0, 0.545, 1],
[1, 0.545, 0],
[0.545, 0, 1],
]

sensors = []
balls = []
labels = []

for x in range(numLights):

#Create Stage
stage = viz.add('tut_ground.wrl')
stagepos = stage.get(viz.POSITION)

#Create sensor
ppt = viz.add('vizppt.dls')
sensors.append(ppt)

#Create ball
ball = viz.add('white_ball.wrl')
ball.scale(1,1,1)
ball.color(colors[x])
balls.append(ball)
ball.link(ppt)
ball.pptColor = colors[x]
ball.curColor = colors[x]
ballpos = ball.get(viz.POSITION)

#Create Pillar
pillar = viz.add('pillarWRL.wrl')
pillar.link(ppt)
pillarpos = pillar.get(viz.POSITION)

def ontimer(num):
for i in range(numLights):
if sensors[i].get()[7]:
ball.color(ball.curColor)
else:
ball.color(viz.BLACK)
viz.callback(viz.TIMER_EVENT,ontimer)

def onbutton(obj,state):
if obj == showLight:
for label in labels:
label.visible(state)
elif obj == allWhite:
for ball in balls:
if state:
ball.curColor = viz.WHITE
else:
ball.curColor = ball.pptColor
ball.color(ball.curColor)
elif obj == showBad:
viz.killtimer(0)
if state:
viz.starttimer(0,0,viz.FOREVER)

viz.callback(viz.BUTTON_EVENT,onbutton)
def mytimer(num):
print ppt.get()

viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(0,0.5, viz.FOREVER)

Jeff 02-10-2009 03:03 PM

So it sounds like the ball just needs to be linked directly to the ppt and for the pillar you just want to negate the y coordinate. You could use the link.swapPos method for that

Code:

#create two links
ballLink = viz.link(ppt, ball)
pillarLink = viz.link(ppt, pillar)

#negate the y coordiante
pillarLink.swapPos([1,-2,3])

in the future you can use the code tags to preserve your indentation. Select your code and click on the # icon


All times are GMT -7. The time now is 01:02 PM.

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