Vizard 8 » Tutorials & Examples » Designing an experimental study » Tutorial: Loading the virtual environment
8.1

Tutorial: Loading the Virtual Environment

Vizard has built-in functionality that can simplify the design process of your own experiment. This tutorial will guide you through creating an experiment skeleton and building the logic necessary for a study with multiple trials. You'll see how to organize you program's flow as well as learn about modules that are useful for the different phases of an experiment.  

 

If you have trouble getting the code in this tutorial to work, you can find the complete example script experimentDesign in the \tutorials\flowControl directory.

Example Experiment

The example experiment in this tutorial is related to spatial recognition. The participant is positioned in the center of a large room. Placed equidistantly in a circle around the participant are 6 spheres that from a distance are white in color. When the participant gets within 1 meter of any sphere it becomes its true color. In the learning phase of the experiment the participant is given the opportunity to move around and remember the true colors of each of the objects. The testing phase of the experiment is organized into multiple trials. For each trial, the participant is instructed to walk to one of the colored spheres and the time to accomplish this is recorded.

Load Models and Program Events

First, spheres are added and the logic to change their colors based on viewpoint proximity is programmed. Add the following code and run the script. Move in and out of the proximity regions to see the objects change color:

import viz
import viztask
import vizact
import vizinfo
import vizproximity
import vizshape

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

#Set up the environment and proximity sensors

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

#Create proximity manager and set debug on. Toggle debug with d key
manager = vizproximity.Manager()
manager.setDebug(viz.ON)
debugEventHandle = vizact.onkeydown('d',manager.setDebug,viz.TOGGLE)

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

#fade to true color when viewpoint moves near
def EnterSphere(e, sphere, color):
    sphere.runAction(vizact.fadeTo(color,time=1))

#fade to white when viewpoint moves away
def ExitSphere(e, sphere):
    sphere.runAction(vizact.fadeTo(viz.WHITE,time=1))

#add spheres and create a proximity sensor around each one
sphereSensors = []
def AddSphere(name, color, position):

    sphere = vizshape.addSphere(radius=0.2)
    sphere.setPosition(position)

    sensor = vizproximity.addBoundingSphereSensor(sphere,scale=5)
    sensor.name = name
    sphereSensors.append(sensor)
    manager.addSensor(sensor)

    manager.onEnter(sensor, EnterSphere, sphere, color)
    manager.onExit(sensor, ExitSphere, sphere)

AddSphere('red', viz.RED, [0,1.8,4])
AddSphere('blue', viz.BLUE, [3.5,1.8,2])
AddSphere('yellow', viz.YELLOW, [3.5,1.8,-2])
AddSphere('green', viz.GREEN, [0,1.8,-4])
AddSphere('purple', viz.PURPLE, [-3.5,1.8,-2])
AddSphere('gray', viz.GRAY, [-3.5,1.8,2])

#Add a sensor in the center of the room for the participant to return to after each trial
centerSensor = vizproximity.Sensor(vizproximity.CircleArea(1.5,center=(0.0,0.0)),None)
manager.addSensor(centerSensor)

#Add vizinfo panel to display instructions
info = vizinfo.InfoPanel("Explore the environment\nPress 'd' to toggle the visibility of the sensors\nPress spacebar to begin the experiment")

Loading the virtual environment

Creating the experiment framework

Entering participant data

Learning phase of experiment

Testing phase of experiment