View Single Post
  #2  
Old 01-15-2004, 12:33 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Karthi,

There are two ways of doing this and it depends on whether your avatar will be moving around or standing in the same place.

If your avatar will be standing in the same place then you can use hotspots. The following code creates a circular hotspot that is triggered when the head position comes within 1 meter from the position (POS_X,POS_Z):
Code:
import viz
viz.go()

POS_X = 3
POS_Z = 6

avatar = viz.add('female.cfg')
avatar.translate(POS_X,0,POS_Z)

DISTANCE = 1

ENTER = 1
EXIT = 2

def myhotspot(id,x,y,z):
	if id == ENTER:
		print 'entering reaction area'
		viz.starthotspot(EXIT,viz.CIRCLE_HOTSPOT_OUT,POS_X,POS_Z,DISTANCE)
	if id == EXIT:
		print 'leaving reaction area'
		viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,POS_X,POS_Z,DISTANCE)
		
viz.callback(viz.HOTSPOT_EVENT,myhotspot)
viz.starthotspot(ENTER,viz.CIRCLE_HOTSPOT_IN,POS_X,POS_Z,DISTANCE)
If you have multiple avatars then you can create multiple hotspot events for each avatar.

If your avatar is moving then you can create a timer loop that contantly checks whether the head position is inside the reaction area, like the following code:
Code:
import viz
import vizmat
viz.go()

avatar = viz.add('female.cfg')
avatar.translate(2,0,5)
avatar.outside = 1

DISTANCE = 1

def mytimer(num):
	headPos = viz.get(viz.HEAD_POS)
	headPos[1] = 0
	
	avatarPos = avatar.get(viz.POSITION)
	avatarPos[1] = 0
	
	distance = vizmat.Distance(headPos,avatarPos)
	if avatar.outside:
		if distance < DISTANCE:
			print 'entered reaction area'
			avatar.outside = 0
	else:
		if distance > DISTANCE:
			print 'leaving reaction area'
			avatar.outside = 1
	
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.05,viz.FOREVER)
Good luck and let me know if you need anymore help
Reply With Quote