Vizard 7 » Tutorials & Examples » Getting your feet wet » Moving the Viewpoint
7.6

Tutorial: Moving the viewpoint

It's often useful to move the viewpoint manually. For example, we may want the starting position to be in the cafe or up in a balcony looking down on the courtyard. To get a handle to the viewpoint use viz.MainView.

Viewpoint position

To move the viewpoint relative to it's current position use the  viewpoint.move  command. The following code will move the viewpoint right 3 meters (+ X direction), back 7 meters (- Z direction) and leave the height (Y direction) unchanged:

viz.MainView.move([3,0,-7])

Run the script and see how the viewpoint position has changed. The new location is [3,1.8,-7] in world coordinates. This is the result of adding [3,0,-7] to the initial position, [0,1.8,0].

 

To place the viewpoint in world coordinates use the viewpoint.setPosition command. Add the following line to move the viewpoint 15 meters up ( + Y direction ) and 15 meters back ( -Z direction) from the origin:

viz.MainView.setPosition([0,15,-15])

Run the script and you'll find yourself above the ground and towards the back of the courtyard.

Viewpoint orientation

To change viewpoint orientation use the viewpoint.setEuler command. This command takes a list of yaw, pitch, and roll values. Yaw specifies the rotation around the Y-axis , pitch specifies the rotation around the X-axis, and roll specifies the rotation around the Z-axis. Images B-D below illustrate the effect of rotation around the different axes.

 

A. Initial viewpoint orientation  (yaw=0,pitch=0,roll=0)                 

B. Change in viewpoint yaw     (yaw=30,pitch=0,roll=0)

C. Change in viewpoint pitch   (yaw=0,pitch=30,roll=0)

D. Change in viewpoint roll      (yaw=0,pitch=0,roll=30)

Add the following line of code to give the feeling you're looking down on the courtyard from one of the balconies and run the script.

viz.MainView.setEuler([0,30,0])

Exercise: Aerial view of the piazza: Change the setPosition and setEuler values from the last two lines of codes so that you're 20 meters directly above the origin looking down.

Launch into a new world

Creating a new Script

Setting the Scene

Moving the Viewpoint

Manipulating 3D Models

Animating 3D Models

Timer Events

Adding Avatars

Inserting User Interaction