Proximity Sensors
See this page in the Vizard Documentation for more information on Proximity Sensors
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.
See ExampleScipts- Proximity Sensors - proximitySensors_example.py for sample code
import vizinput
import vizshape
import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *
sightlab = sl.SightLab(gui = False)
sightlab.headLight.enable()
env = vizfx.addChild('sightlab_resources/environments/DeckersOffice.OSGB')
sightlab.setEnvironment(env)
# Create objects
ball = vizshape.addSphere(radius= 0.1)
ball.color(viz.BLUE)
ball.setPosition(0,1.5,2)
audio1 = viz.playSound('sightlab_resources/audio/beep.wav',viz.SOUND_PRELOAD)
#copy and paste this section, replacing the basketball with whatever you want to use as a sensor
import vizproximity
manager = vizproximity.Manager()
# Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)
#Add hand or finger as second target
avatar= vizconnect.getAvatar()
rhand = avatar.getAttachmentPoint('r_hand').getNode3d()
rhand_target = vizproximity.Target(rhand)
lhand = avatar.getAttachmentPoint('l_hand').getNode3d()
lhand_target = vizproximity.Target(lhand)
manager.addTarget(lhand_target)
manager.addTarget(rhand_target)
#Add sensors
BallSensor = vizproximity.addBoundingSphereSensor(ball)
manager.addSensor(BallSensor)
# Add circle area
shape = vizproximity.Sensor( vizproximity.RectangleArea([1,1],center=[0,0.5]), None )
manager.addSensor(shape)
# Register callbacks for proximity sensors
def EnterProximity(e):
viz.playSound('sightlab_resources/audio/beep.wav')
print('Entered Sensor')
def ExitProximity(e):
print('Exited Sensor')
manager.onEnter(None, EnterProximity)
manager.onExit(None, ExitProximity)
def activateBallSensor(e):
viz.playSound('sightlab_resources/audio/beep.wav')
print('sensor entered')
manager.onEnter(BallSensor,activateBallSensor)
# Press "d" to toggle debug shapes
manager.setDebug(True)
vizact.onkeydown('d',manager.setDebug,viz.TOGGLE)
import viztask
def sightLabExperiment():
while True:
yield viztask.waitKeyDown(' ')
yield sightlab.startTrial()
yield vizproximity.waitEnter(BallSensor,rhand_target)
print('hand sensor activated')
yield viztask.waitKeyDown(' ')
yield sightlab.endTrial()
viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)
viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)
For more information see Vizard Documentation on Proximity Sensors