View Full Version : triggering actions on proximity
exhale
03-11-2005, 02:01 AM
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
farshizzo
03-11-2005, 11:03 AM
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.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,HOTS POT_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,HOTSP OT_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,HOTSP OT_X,HOTSPOT_Z,RADIUS)
exhale
03-14-2005, 02:03 AM
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
exhale
03-14-2005, 02:26 AM
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
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.