Vizard 8 » Tutorials & Examples » Vizconnect » Inputs and Transports » Tutorial: Transport Commands
8.0

Tutorial: Vizconnect Transport Commands

In this section we'll learn how to toggle the transport on and off and change its speed using transport commands.

Note: This section continues with the configuration and script used in the previous section.

Transport Speed

We can use the transport.setMovementSpeed command to scale the transport movement by any given factor. Add the following code and run the script again. Use the F5 - F8 keys to change speed:

#Change transport speed with key presses
vizact.onkeydown(viz.KEY_F5,transport.setMovementSpeed,1)
vizact.onkeydown(viz.KEY_F6,transport.setMovementSpeed,2)
vizact.onkeydown(viz.KEY_F7,transport.setMovementSpeed,3)
vizact.onkeydown(viz.KEY_F8,transport.setMovementSpeed,4)

Transport Toggle

The way the simulation is currently set up, the user can drive the car from any location in the environment. To make it more realistic, the script can be modified so the transport is only enabled when the user is inside the car. To do this we'll use the vizproximity library to detect viewpoint movements in and out of the car's bounding box area. Once a change is detected the transport.setEnabled command will be called and passed a parameter that turns it on or off. Don't worry about all the details of the proximity code below, that will be covered in later tutorials. For now, just notice how the transport state is set in the EnterProximity and ExitProximity callback functions.

 

Add the following code and run the script. Now, the transport only moves when the viewpoint is inside the car's bounding box area. Use the 'p' key to toggle the box's visibility:

import vizproximity

manager = vizproximity.Manager()
manager.setDebug(viz.ON)

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

#Create sensor using mini
sensor = vizproximity.addBoundingBoxSensor(mini)
manager.addSensor(sensor)

#Enable the transport when the user is in the car
def EnterProximity(e):
    transport.setEnabled(viz.ON)

#Disable the transport when user leaves the car
def ExitProximity(e):
    transport.setEnabled(viz.OFF)

manager.onEnter(sensor,EnterProximity)
manager.onExit(sensor,ExitProximity)
 
vizact.onkeydown('p',manager.setDebug,viz.TOGGLE)

Input and Transport Basics

Transport and Tracker Integration

Transport Commands