Vizard 8 » Tutorials & Examples » Proximity Sensors » Tutorial: Sensors and Targets
8.0

Tutorial: Sensors and Targets

 

Now let's get started with our proximity related code. Sensors will be placed on objects that we're interested in determining proximity with. This includes destination objects that the participant is instructed to walk to and avatars that are along the path. The viewpoint will be designated as a proximity target so we know when the participant has entered the space of one of these sensors. A proximity manager will be added to group these sensors and target together and generate proximity events when the viewpoint target enters/exits a sensor region.

 

First, sensors are added to objects that the participant will walk to:

#Create sensors for destinations
plantSensor = vizproximity.Sensor(vizproximity.Box([4,5,5],center=[0,2.5,0]),source=plantMarker)
cratesSensor = vizproximity.Sensor(vizproximity.Box([5,4,4],center=[0,1.7,0]),source=crate1)
cafeSensor = vizproximity.Sensor(vizproximity.Box([5,4,10]),source=viz.Matrix.translate(12,2,7.5))

Next, sensors are added to the avatars:

#Create sensors for avatars
sensorAvatar1 = vizproximity.Sensor(vizproximity.Box([2,2.5,2.5],center=[0,1.3,1]),source=avatar1)
sensorAvatar2 = vizproximity.Sensor(vizproximity.Box([2,2.5,2.5],center=[0,1.3,0.7]),source=avatar2)
sensorAvatar3 = vizproximity.Sensor(vizproximity.Box([2,2.5,2.5],center=[0,1.3,0.7]),source=avatar3)

The viewpoint will be used as the source for a proximity target. This will make it possible to detect when the user enter or exits a sensor region:

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

Next, a proximity manager is created and sensors and targets are added to it:

#Create proximity manager
manager = vizproximity.Manager()

#Add destination sensors to manager
manager.addSensor(plantSensor)
manager.addSensor(cratesSensor)
manager.addSensor(cafeSensor)

#Add avatar sensors to manager
manager.addSensor(sensorAvatar1)
manager.addSensor(sensorAvatar2)
manager.addSensor(sensorAvatar3)

#Add viewpoint target to manager
manager.addTarget(target)

In order to visualize the sensor regions, debug mode is set to toggle with a keypress:

#Toggle debug shapes with keypress
vizact.onkeydown('d',manager.setDebug,viz.TOGGLE)

Run the script and press the 'd' key to see the shapes and locations of the sensors. Although the proximity manager will generate events when the viewpoint target enters/exits a sensor we have not yet added any code to handle those events.

Proximity Sensors

Sensors and Targets

Proximity Events