Vizard 8 » Reference » Vizconnect » Viewpoints
8.1

Viewpoints

Each Vizard window renders the 3D scene from a viewpoint. This is sometimes referred to as a camera in other 3D software. In a Vizard application that is not vizconnect based, there are a number of commands that can be used to set and animate the view. In a vizconnect application, view updates are based on parent nodes (e.g. trackers, transports). All standard Vizard commands that set the view are overwritten. There are, however, vizconnect alternatives to achieve the same results.

Getting view information

To get the view position and orientation, get a handle to the view as in any other script. Although vizconnect overrides view set commands, get commands are not affected:

view = viz.MainView
pos = view.getPosition()
euler = view.getEuler()

Setting the view

Use the vizconnect viewpoint object described below to help set the view. This forces the view to a location while taking into account the hierarchy of parent objects. Moving the user to a general location within the environment can be accomplished by setting the position of a parent transport’s node3D object. In this case, the final viewpoint position is equal to the transport position plus offsets from other nodes (e.g. trackers) in the scenegraph:

transportNode = vizconnect.getTransport('main_transport').getNode3d()
transportNode.setPosition([0,0,20])

Vizconnect Viewpoint

As mentioned earlier, the view (i.e. viz.View) location can't be set directly when running a vizconnect based application:

# Incorrect code for  a vizconnect application
view = viz.MainView
view.setPosition([x,y,z])
view.setEuler([yaw,pitch,roll])

The view’s position will be overwritten by the associated vizconnect.Display object. Instead, use a vizconnect viewpoint object to achieve the same result and place the user and their viz.View at a specific location in the virtual scene. The following example adds a vizconnect viewpoint located on the piazza balcony:

import viz
import vizact
import vizconnect

# Create a vizconnect desktop walking config from the presets menu
# And save that in the same folder as this script
vizconnect.go('vizconnect_config.py')

viz.add('piazza.osgb')

oriMode = vizconnect.VIEWPOINT_MATCH_DISPLAY
posMode = vizconnect.VIEWPOINT_MATCH_FEET

# Add a vizconnect viewpoint.
vp = vizconnect.addViewpoint(   pos=[-13.25, 12.3, 8.83],
                                euler=[90, 0, 0],
                                posMode=posMode,
                                oriMode=oriMode,
)

# Displays are added to vizconnect viewpoints
vp.add(vizconnect.getDisplay())

# Call reset viewpoints, which forces the display into the vizconnect viewpoint position.
vizconnect.resetViewpoints()
# add a reset key so when r is pressed the user is moved back to the viewpoint
vizact.onkeydown('r', vizconnect.resetViewpoints)

This method works by internally adding a node to the scenegraph and setting it's transform to compensate for the transforms of transports, trackers, and other nodes that affect the Display and/or Avatar location. The vizconnect viewpoint object is not a viz.View object, rather it is a helper object to place the user or the user’s view into the correct location.

 

The following command returns a vizconnect viewpoint:

Command Description

vizconnect.addViewpoint( pos=None,

                                                 euler=None,

                                                 enabled=True,

                                                 constant=False,

                                                 oriMode=VIEWPOINT_MATCH_BASE,

                                                 posMode=VIEWPOINT_MATCH_FEET

 

Returns a handle to the vizconnect viewpoint

pos: The viewpoint position

euler: The viewpoint orientation

enabled: Sets the state of the viewpoint

constant: When set to True, the display is locked to the viewpoint location oriMode: See section on modes below

posMode: See section on modes below

The following modes determine how the vizconnect viewpoint's transformation is applied to the display’s viz.View object:

Mode Description
vizconnect.VIEWPOINT_MATCH_BASE Matches the base object to the viewpoint. The base appears directly below the root of the scenegraph tree. Once reset, the viz.View location is equal to the viewpoint transform plus the transforms of any other nodes between the display and base.
vizconnect.VIEWPOINT_MATCH_FEET Matches the avatar feet to the viewpoint. Once reset, the viz.View location is equal to the viewpoint transform plus any offset between the avatar’s head and feet.
vizconnect.VIEWPOINT_MATCH_DISPLAY Matches the display and it’s viz.View object to the viewpoint.

The following methods are available on the vizconnect viewpoint:

Method Description
<viewpoint>.add(wrappedDisplay) Adds a wrapped display to the viewpoint
<viewpoint>.remove(wrappedDisplay=None) If a name is specified, the wrapped display object is removed from the viewpoint. If None, then the viewpoint is removed.
<viewpoint>.reset() Returns base, avatar, or display assigned to the viewpoint to the starting viewpoint location.
<viewpoint>.setEnabled(state)

Sets the state of the viewpoint

state: viz.ON, viz.OFF, or viz.TOGGLE