PDA

View Full Version : Setting up a 'reaction area'


Karthi
01-14-2004, 05:57 PM
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

farshizzo
01-15-2004, 01:33 PM
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):

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:
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

Karthi
01-15-2004, 04:01 PM
Thankyou very much!!!! I'll give this a try
Cheers
karthi

Karthi
01-29-2004, 05:22 PM
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

farshizzo
01-29-2004, 05:39 PM
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:
import vizmat

AVATAR_DISTANCE = 2

def mytimer(num):
distance = vizmat.Distance(a1.get(viz.POSITION),a2.get(viz.PO SITION))
if distance < AVATAR_DISTANCE:
print 'Avatar1 and Avatar2 are near each other'

Good luck!