Vizard 7 » Reference » Proximity Sensors » vizproximity events
7.7

vizproximity events

The following events are generated by a manager when a target enters/exits a sensor:

Event

vizproximity.ENTER_PROXIMITY_EVENT

vizproximity.EXIT_PROXIMITY_EVENT

Both events provide a single event structure e with the following attributes:

Attribute

Description

sensor

The sensor that was activated.

target

The activating target.

manager

The manager for the sensor/target involved.

There are two ways to work with these events:

Register callback functions with a proximity manager

Use the following methods on the Manager object to register callback functions for proximity events:

Method

Description

<Manager>.onEnter(sensor,

                           func,

                           *args,

                           **kw)

Call the specified function when a target enters the proximity sensor. If sensor is not specified then all sensors will be allowed.

<Manager>.onExit(sensor,

                         func,

                         *args,

                         **kw)

Call the specified function when a target exits the proximity sensor. If sensor is not specified then all sensors will be allowed.

The following code shows how to register callback functions for proximity events:

def EnterProximity(e):
    """@args vizproximity.ProximityEvent()"""
    print('entered',e.sensor)

def ExitProximity(e):
    """@args vizproximity.ProximityEvent()"""
    print('exited',e.sensor)

manager.onEnter(None,EnterProximity)
manager.onExit(None,ExitProximity)

Wait for proximity events in a task function

Task functions, from the viztask library, are useful for controlling program flow. Use the following commands to create viztask conditions that wait for proximity events:

Command

Description

vizproximity.waitEnter(sensor,

                              target,

                              manager)

viztask condition that waits for a proximity sensor enter event.

 

sensor - A Sensor object, list of Sensor objects, or None to allow any sensor

target - A Target object, list of Target objects, or None to allow any target

manager - A Manager object, list of Manager objects, or None to allow any manager

vizproximity.waitExit(sensor,

                            target,

                            manager)

viztask condition that waits for a proximity sensor exit event.

 

sensor - A Sensor object, list of Sensor objects, or None to allow any sensor

target - A Target object, list of Target objects, or None to allow any target

manager - A Manager object, list of Manager objects, or None to allow any manager

The following code shows to wait for a proximity event:

def proximityTask():
    #Add walk action to avatar when user gets close
    yield vizproximity.waitEnter(avatarSensor)
    avatar.runAction(walk)

viztask.schedule(proximityTask())

vizproximity introduction

vizproximity sensor

vizproximity target

vizproximity manager

vizproximity events