WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   reseting an object (https://forum.worldviz.com/showthread.php?t=1894)

durf 03-10-2009 09:40 AM

reseting an object
 
Hello,

I am trying to reset an object. Right now when my sensor passes over and object and then sets the position to to -10 on the y axis. What I want to do is when my sensor leaves that object how do I reset that particular object to 0 on the y - axis.

I have my objects arranged in an array which lays the objects out on the x and z -axis flat on the y -axis. The array is 4 x 5.


Thanks for any help

Jeff 03-10-2009 12:45 PM

Are you using viz.intersect to see whether or not the sensor is over the block?

You can continue to us viz.intersect to see whether or not the line drawn from below the sensor is still intersecting the block. If it is you don't need to do anything since the block has already been moved down. If it's not intersecting that object anymore the sensor has moved beyond it and you can reset the object's position.

if you're still using the vizintersect code from the other thread you started than you could change it to something like this.

Code:

currentBlock = None
def moveBlock():
       
        global currentBlock
       
        x,y,z = ball.getPosition()
        info = viz.intersect([x,y-1,z],[x,y-20,z])
        if info.valid and currentBlock == None:
                currentBlock = info.object
                currentBlock.setPosition([0,-10,0], viz.REL_LOCAL)
        elif not info.valid and currentBlock is not None:
                currentBlock.setPosition([0,10,0], viz.REL_LOCAL)
                currentBlock = None
       
vizact.ontimer(0,moveBlock)


durf 03-17-2009 05:36 PM

Still not working... Below is the code I have created for it. Im thinking it has something to do with the array. Just getting confused with it.

Code:

import viz
viz.go()

OriginalPillar = viz.add('pillarWRL.wrl')
OriginalPillar.visible(viz.OFF)

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

PORT_PPT = 6

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

for x in range(numLights): #creates sensor and call
       
        #Add ground
        ground = viz.add( 'tut_ground.wrl' )
        ground.setPosition([0,-5,0])
       
        #Create sensor
        ppt = viz.add('vizppt.dls')
       
        #Create ball
        ball = viz.add('white_ball.wrl')
        ball.scale(1,1,1)
        ballLink = viz.link(ppt, ball)
        #controls distance in virtual world
        ballLink.postScale([8,1,13],target = viz.LINK_FULL_OP)

        columns = [-20, -10, 0, 10, 20]
        rows = [0, 6, 12, 18]
pillars = []
for x in columns:  #creates an array of pillars
        for y in rows:
                pillar = OriginalPillar.copy()
                pillar.translate(0+x, 0, 0+y)
                pillar.setScale(1,1,1)
                pillar.visible(viz.OFF)
                pillars.append(pillar)

number = 0
def showPillar(): #displays pillars
        global number
        pillars[number].visible(viz.ON)
        number +=1
vizact.ontimer2(.5,len(pillars)-1,showPillar)

currentBlock = None
def moveblock():

        global currentBlock
       
        x,y,z = ball.getPosition()
        info = viz.intersect([x,y-1,z],[x,y-20,z])
        if info.valid and currentBlock == None:
                currentBlock = info.object
                currentBlock.setPosition([0,-10,0], viz.REL_LOCAL)
        elif not info.valid and currentBlock is not None:
                currentBlock.setPosition([0,10,0], viz.REL_LOCAL)
                currentBlock = None
               
vizact.ontimer(0, moveblock)


Jeff 03-17-2009 11:48 PM

I think an intersection occurs with the ground and that interferes with code to move the pillars. Try disabling intersection on the ground
Code:

ground.disable(viz.INTERSECTION)


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

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