Vizard 8 » Reference » Viewpoints & Windows » Viewpoints » Viewpoint basics
8.0

Viewpoint basics

3D scenes are always rendered from a viewpoint (sometimes called a camera).  In Vizard you can create as many viewpoints as you wish, although the main viewpoint is provided automatically and is used to render the standard 3D window. By default this viewpoint navigates via the mouse. You have a number of different options, though, when it comes to moving, rotating, and linking viewpoints (see below). The main library of commands for viewpoints is the <viewpoint> library.

Note: to turn off mouse navigation, use viz.mouse(<on or off>).

Grabbing the main viewpoint and creating new views

To grab the main view, use viz.MainView. To create new viewpoints, use viz.addView. Use commands from the <viewpoint> class to manipulate your views.

viz.add('tut_ground.wrl')
view = viz.MainView #Grab the main view.
vizact.onkeydown( ' ', view.move,0,0,1) # Move it 1 meter forward

Linking a viewpoint to a sensor or an object

By default, the main view navigates via the mouse. If you're using a position or orientation tracking device to navigate through your world, you'll want to link your view to that sensor using viz.link( <sensor>, <view> ). Of course you can link any your main view or any other view to any object as well using link. For more options here, check out the section on linking.  For more options on mouse navigation, check out the section on creating your own camera handlers.

#Grab the main view.
view = viz.MainView

#Add a tracker.
isense = viz.add('intersense.dle')
tracker = isense.addTracker()

#Link the tracker to the view.
viz.link( tracker, view )

The head and the body of a viewpoint

Every viewpoint has a body and a head. The head and body are reference frames controlled in a hierarchical fashion. You can think of the head as a child of the body-- any motions applied to the body are passed onto the head, but motions applied to the head don't affect the body. This distinction is important in many of the commands you use to move or get information about the viewpoint. In these commands, you can use the flags viz.BODY_ORI to indicate the body orientation or viz.HEAD_ORI to indicate the head orientation. When you're getting information about the head orientation, you can get a composite of the head and body orientations using the viz.VIEW_ORI flag.

viz.add('court.ive')
#Grab the main view.
view = viz.MainView
#Rotate the head (but not the body).
vizact.onkeydown( ' ', view.setAxisAngle, 0,1,0,90, viz.HEAD_ORI)
#Move forward along the body's orientation (which is sideways
#along the head's orientation if the head is rotated).
vizact.onkeydown( viz.KEY_UP, view.move, 0,0,1,viz.BODY_ORI)

Eyeheight

Vizard automatically sets the eyeheight at 1.82 meters (6 feet). To change this default within your script use <view>.eyeheight( <height> ).  When you reset a view with <view>.reset, the view, it will reset to this height.

#Grab the main view.
view = viz.MainView
#Set the eyeheight to 8 meters.
vizact.onkeydown( ' ', view.eyeheight,8)
#Reset the head position.
vizact.onkeydown( 'r', view.reset, viz.HEAD_POS)

Resetting a viewpoint

To reset the viewpoint's position or orientation use <viewpoint>.reset(<what>) where <what> can either be the head's position (viz.HEAD_POS), the head's orientation (viz.HEAD_ORI) or the body's orientation (viz.BODY_ORI). Note: resetting the head's position will place it at eyeheight above the origin.

#Reset the head's orientation and position.
viz.MainView.reset( viz.HEAD_ORI | viz.HEAD_POS )

You can also reset the viewpoint by using Vizard's camera handler. Here the command is viz.cam.reset(). The advantage to using the camera reset is that you can change the location and orientation that the viewpoint will reset to by placing the viewpoint where you want it and then calling viz.cam.setReset(). From that point on, when you call viz.cam.reset(), the view will reset to that position and orientation.

#Set the main viewpoint's position and orientation.
viz.MainView.setPosition(2,2,0)
viz.MainView.setEuler(0,10,10)
#Set the current position and orientation as point to reset to.
viz.cam.setReset()
#Reset the camera to that point.
vizact.onkeydown(' ', viz.cam.reset )

More on viewpoints

For more on controlling and animating viewpoints, check out the sections on view animation and the camera handler. For information on how to handle view collisions and view-triggered events, check out the section on view collision.

See also

In this section:

Camera handlers

Moving and rotating a viewpoint

Viewpoint collision and gravity

Viewpoint command table

Other sections:

Viewpoint and window basics

Window basics

Stereo basics

Linking basics

Animation path basics

Action basics

Tutorial: Viewpoint collision

Tutorial: Viewpoint control

Tutorial: Windows & views

Example scripts:

Viewpoint camera control

Viewpoint animation

Viewpoint collision

Window views