Vizard 7 » Reference » Proximity Sensors » vizproximity introduction
7.7

vizproximity introduction

Use the vizproximity library to check for proximity between Vizard objects and trigger events based on proximity. There are three classes that form the foundation of this library; Sensor, Target, and Manager. A sensor object detects when a target is within its range. Sensor and target positions are based on a source object which can be a node, view, tracker, bone, matrix, or any other linkable object.  A Manager object manages a collection of sensors and targets and automatically triggers events when a target enters/exits a sensor range.

The \examples\proximity folder contains additional example scripts that demonstrate how to use the vizproximity library.

The following example code creates a sensor around an avatar who begins talking when the user moves near and stops talking when the user moves away. Press the 'd' key to toggle the sensor shape debugger:

import viz
import vizact
import vizproximity

viz.setMultiSample(4)
viz.fov(60)
viz.go()

dojo = viz.addChild('dojo.osgb')

#Create proximity manager
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

#Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)

#Create sensor using male avatar
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,4],euler=[180,0,0])
avatar.state(1)
sensor = vizproximity.addBoundingSphereSensor(avatar,scale=2)
manager.addSensor(sensor)

#Change state of avatar to talking when the user gets near
def EnterProximity(e):
    avatar.state(4)

#Change state of avatar to idle when the user moves away
def ExitProximity(e):
    avatar.state(1)

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

vizact.onkeydown('d',manager.setDebug,viz.TOGGLE) 

vizproximity introduction

vizproximity sensor

vizproximity target

vizproximity manager

vizproximity events