WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-11-2005, 02:01 AM
exhale exhale is offline
Member
 
Join Date: Feb 2005
Posts: 19
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
Reply With Quote
  #2  
Old 03-11-2005, 11:03 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
  #3  
Old 03-14-2005, 02:03 AM
exhale exhale is offline
Member
 
Join Date: Feb 2005
Posts: 19
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 02:17 AM.
Reply With Quote
  #4  
Old 03-14-2005, 02:26 AM
exhale exhale is offline
Member
 
Join Date: Feb 2005
Posts: 19
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
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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