WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   when a sensor moves over some other object (https://forum.worldviz.com/showthread.php?t=1879)

durf 03-03-2009 11:59 AM

when a sensor moves over some other object
 
Hello,

Still kind of new to python language.

Lets say I have a "white_ball.wrl"(ball) that is linked to a ppt sensor. And I have a block that is located at position (10,0,0). What I want to happen is if the ball moves over to position (10,0,0) the block will have a new set position at (10,-10,0). The ball can be at any level on the y-axis by the way. I only want to worry about where the ball is on the x and z axis.

What I need to know:

What do I have to do to compare the position of the ball == to the position of the block(keeping in mind that there is a surface area on the block of unknown size.)?

After it compares the two to see if the ball is over the area of the block, how do I set the position of the block.

Any help will be much appreciated.
Thank You

Jeff 03-03-2009 12:59 PM

you could use viz.intersect and have your line start just below the ball and then go straight down far enough to cross the plane the block is in. If an intersection happens then you reset the position of the block. Something like this.

Code:

def moveBlock():
       
        x,y,z = ball.getPosition()
        info = viz.intersect([x,y-1,z],[x,y-5,z])
        if info.valid:
                info.object.setPosition([0,-10,0], viz.REL_LOCAL)
       
vizact.ontimer(0,moveBlock)


durf 03-03-2009 01:04 PM

Ok thanks for the quick response. Now if I set my pillars(the blocks) like this, can I impliment the same code that was posted above into this... or do I have to construct it differently?


Code:

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 = OrginalPillar.copy()
          pillar.translate(0+x, 0, 0+y)
          pillar.setScale(1,1,1)
          pillar.visible(viz.OFF)
          pillars.append(pillar)

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


Jeff 03-03-2009 01:26 PM

that should work as long as the line you draw from the ball is long enought to make it through the y coordinate of the block plane. If the line you draw is long and an intersection occurs again on the same object, it will move down again. So you might want to check for that.


All times are GMT -7. The time now is 02:08 AM.

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