WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 21 votes, 5.00 average. Display Modes
  #1  
Old 01-14-2004, 04:57 PM
Karthi Karthi is offline
Member
 
Join Date: Dec 2003
Posts: 21
Setting up a 'reaction area'

HI
I'm not a very experienced Python programmer, so i'm not quite sure how to go about doing the following thing.
What i want to do is set up some area (inside my vr world) around each avatar, this area i call the 'reaction area'. I need to set up this area becuase i want to trigger a reaction from the corresponding avatar if a user (i.e. person wearing headset) walks into the reaction area. I just don't know how to start setting up this 'reaction area'. Are there any tutorials that set this sort of thing up?

I would like my 'reaction area' to be in the shape of an arc.


karthi
Reply With Quote
  #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
  #3  
Old 01-15-2004, 03:01 PM
Karthi Karthi is offline
Member
 
Join Date: Dec 2003
Posts: 21
Thankyou very much!!!! I'll give this a try
Cheers
karthi
Reply With Quote
  #4  
Old 01-29-2004, 04:22 PM
Karthi Karthi is offline
Member
 
Join Date: Dec 2003
Posts: 21
Avatar Hotspots

Hi,
I'm just curious, when you set up a hotspot for an avatar say avatar A1. If another avatar in the room, A2 enter the hotpot of A1, will A1 be able to register that the avatar A2 has enetered its hotspot?
Cheers
Karthi
Reply With Quote
  #5  
Old 01-29-2004, 04:39 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Karthi,

Hotspots are only triggered when the viewpoint enters that area, not other objects. You will need to create a timer loop and manually check how far the avatars are from each other. Hear is some sample code that shows the basic idea:
Code:
import vizmat

AVATAR_DISTANCE = 2

def mytimer(num):
	distance = vizmat.Distance(a1.get(viz.POSITION),a2.get(viz.POSITION))
	if distance < AVATAR_DISTANCE:
		print 'Avatar1 and Avatar2 are near each other'
Good luck!
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 04:09 PM.


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