Thread: Coldspots?
View Single Post
  #2  
Old 02-20-2007, 03:11 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
An event class should be able to handle hotspots. However, unlike timers, hotspot IDs are not unique to each class, but are shared globally. So you need to make sure each event class has its own unique hotspot ID. Here is a sample script that shows how to use event classes with hotspots:
Code:
import viz
viz.go()

viz.add('tut_ground.wrl')

#Declare Radius of hotspot
RADIUS = 1

#Declare position of hotspot
HOTSPOT_X = 0
HOTSPOT_Z = 3

class HotspotClass(viz.EventClass):
	def __init__(self,enter,leave):
		viz.EventClass.__init__(self)
		
		self.enter = enter
		self.leave = leave
		
		#Create a hotspot that will be triggered when we enter the circle
		viz.starthotspot(self.enter,viz.CIRCLE_HOTSPOT_IN,HOTSPOT_X,HOTSPOT_Z,RADIUS)
		
		self.callback(viz.HOTSPOT_EVENT,self.onhotspot)
		
	def onhotspot(self,id,x,y,z):
		if id == self.enter:
			print 'Entered hotspot',self.enter
			#Create a hotspot that will be triggered when we leave the circle
			viz.starthotspot(self.leave,viz.CIRCLE_HOTSPOT_OUT,HOTSPOT_X,HOTSPOT_Z,RADIUS)
		elif id == self.leave:
			print 'Leaving hotspot',self.leave
			#Create a hotspot that will be triggered when we enter the circle
			viz.starthotspot(self.enter,viz.CIRCLE_HOTSPOT_IN,HOTSPOT_X,HOTSPOT_Z,RADIUS)

HotspotClass(0,1)
HotspotClass(2,3)
Let me know if I misunderstood your question.
Reply With Quote