#1
|
|||
|
|||
triggering actions on proximity
Hello,
i run through the api but couldn't find a feasable solution. This is my problem: I would like to trigger an event / action when the viewpoint is near a certain object or in a certain area, how can i make this happen? greetz, Kevin |
#2
|
|||
|
|||
You can use hotspots to detect when the viewpoint has entered or left a given area. Here is a simple script that creates a circular hotspot at the location (0,3) with radius 1.
Code:
import viz viz.go() viz.add('tut_ground.wrl') #Declare some hotspot IDs ENTER = 0 LEAVE = 1 #Declare Radius of hotspot RADIUS = 1 #Declare position of hotspot HOTSPOT_X = 0 HOTSPOT_Z = 3 def onhotspot(id,x,y,z): if id == ENTER: print 'Entered hotspot' #Create a hotspot that will be triggered when we leave the circle viz.starthotspot(LEAVE,viz.CIRCLE_HOTSPOT_OUT,HOTSPOT_X,HOTSPOT_Z,RADIUS) elif id == LEAVE: print 'Leaving hotspot' #Create a hotspot that will be triggered when we enter the circle viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,HOTSPOT_X,HOTSPOT_Z,RADIUS) viz.callback(viz.HOTSPOT_EVENT,onhotspot) #Create a hotspot that will be triggered when we enter the circle viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,HOTSPOT_X,HOTSPOT_Z,RADIUS) |
#3
|
|||
|
|||
Hello,
thanks for your help, but i can't get it to trigger.. The text in the if statements isn't printed, so i guess it's never reached. I only changed the X, Z values of your script so it was surrounding my object. I'll post an excerpt of the code: #hotspot IDs ENTER = 0 LEAVE = 1 #Radius of hotspot RADIUS = 5 #position of hotspot HOTSPOT_X = 30 HOTSPOT_Z = 17.5 tbox = viz.add('tbox_paars.wrl') tbox.translate(30,0,17.5) tbox2 = viz.add('tbox_rood.wrl') tbox2.translate(30,0,17.5) tbox2.visible(viz.OFF) def onhotspot(id,x,y,z): if id == ENTER: print 'Entered hotspot' tbox.visible(viz.TOGGLE) tbox2.visible(viz.TOGGLE) #Create a hotspot that will be triggered when we leave the circle viz.starthotspot(LEAVE,viz.CIRCLE_HOTSPOT_OUT,HOTS POT_X,HOTSPOT_Z,RADIUS) elif id == LEAVE: print 'Leaving hotspot' tbox.visible(viz.TOGGLE) tbox2.visible(viz.TOGGLE) #Create a hotspot that will be triggered when we enter the circle viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,HOTSP OT_X,HOTSPOT_Z,RADIUS) #hotspot -> onhotspot viz.callback(viz.HOTSPOT_EVENT,onhotspot) #Create a hotspot that will be triggered when we enter the circle viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,HOTSP OT_X,HOTSPOT_Z,RADIUS) ps: Code is indented correctly in the editor any ideas why this isn't working? EDIT: i also tried leaving out the if statements and doing the visible toggling straight away, which didn't work either. The method is never entered. I also tried with a rectangle, put collision on or off, which didn't give me any success.. greets and thanks in advance! Kevin Last edited by exhale; 03-14-2005 at 03:17 AM. |
#4
|
|||
|
|||
Hello,
ok i did manage to get it to work with the rectangular option. Will try with circle too. Maybe my width & depth were to small. Thanks & greets, Kevin |
Thread Tools | |
Display Modes | Rate This Thread |
|
|