Vizard 7 » Tutorials & Examples » Viewpoints & windows » Viewpoint control » Tutorial: Viewpoint control
7.7

Tutorial: Viewpoint control

This tutorial will show you the different ways you can control the viewpoint. In this example the viewer will be placed inside a car. The user will press the arrow keys to move the car around and use the mouse to look around.

This content is discussed in more detail in the reference section.

Setting up a vehicle

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

 

After creating the empty script add the following initial code to it:

import viz
import vizact

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

viz.clearcolor(viz.SKYBLUE)

Before we add any objects, let's create some variables that will control how fast the viewpoint will move and turn:

MOVE_SPEED = 5
TURN_SPEED = 60

This isn't required, but it makes it easier to quickly change the movement and turning speed.

Now let's add some 3d models to your world. Add the following code:

car = viz.addChild('mini.osg')
ground = viz.addChild('ground.osgb')

This will add the car and ground.

Setting up a vehicle

Forward/back motion

Left/right turning

Getting viewpoint information

Head and body motion