Vizard 7 » Reference » Viewpoints & Windows » Viewpoints » Moving & rotating a viewpoint
7.6

Moving & rotating a viewpoint

You don't need a navigation devices to move a viewpoint. Vizard has a host of commands that either discretely or fluidly reposition or rotate viewpoints. Note: when you're applying these transforms to the viewpoint, you can apply them to either the head or body of the viewpoint.

Discreet movements and rotations

Translate or rotate the viewpoint relative to a specified frame of reference using <viewpoint>.setPosition(<x,y,z>), <viewpoint>.setAxisAngle(<axis angle>), <viewpoint>.setEuler(<yaw, pitch and roll>), or <viewpoint>.setQuat(<quaternions>). You can also set the viewpoint's transform matrix with <viewpoint>.setMatrix(<matrix>).  The <viewpoint>.move(<direction>) command moves the viewpoint in the given <direction> relative to the viewpoint's current position and orientation. The <viewpoint>.lookAt(<x,y,z>) command orients the viewpoint to  face a given point (<x,y,z>) in space.

#Add an object somewhere in the world.
thing = viz.add('wheelbarrow.ive')
thing.setPosition([1,2,3])
#Rotate the viewpoint to face the object.
viz.MainView.lookAt( thing.getPosition() )

Fluid movements and rotations

To fluidly move your viewpoint in a given direction at a specified speed, use <viewpoint>.velocity (<vector coordinates>).

viz.add('court.ive')
#Use a keyboard action to move the viewpoint forward
#at .5 meters per second.
vizact.onkeydown(' ', viz.MainView.velocity, [0,0,.5 ]  )

To fluidly move your viewpoint to a specific location or set of locations, use <vizact>.goto(<point>). When using vizact.goto, you can optionally specify a pivot point using the pivot keyword argument. To use the pivot point, set the vizact.goto rotation mode using the rotate_mode option and specify how the rotations about the pivot point should be applied-- you can either set the mode so that the viewpoint immediately rotates to face the pivot point when vizact.goto is called (viz.PIVOT_ROTATE), or you can set it to smoothly blend from its current orientation to the orientation that faces the pivot point (viz.BLEND_ROTATE). To specify whether the body or the head of the viewpoint is affected by pivoting use the ori_mask option, where mask can be viz.BODY_ORI or viz.HEAD_ORI.

viz.add('court.ive')

"""
Set the pivot point 2 meters above the origin.
Set the rotation mode to blend its orientation
from its current orientation to that associated
with the pivot.
"""
gotoRight = vizact.goto([2,1,-2],rotate_mode=viz.BLEND_ROTATE,pivot=[0,2,0],ori_mask=viz.BODY_ORI)
gotoLeft = vizact.goto([-2,2,-2],rotate_mode=viz.BLEND_ROTATE,pivot=[0,2,0],ori_mask=viz.BODY_ORI)

#Use keyboard actions to move the viewpoint.
vizact.onkeydown(viz.KEY_RIGHT, viz.MainView.runAction, gotoRight )
vizact.onkeydown(viz.KEY_LEFT, viz.MainView.runAction, gotoLeft )

To fluidly rotate your viewpoint independently of a vizact.goto command, use vizact.spinto. To specify whether the spinning should effect the body or the head of the viewpoint, use the ori_mask option.

viz.add('court.ive')
#Spin the view 180 degrees at 30 degrees/s.
spinAction = vizact.spinto(0,1,0,180,30,ori_mask=viz.BODY_ORI)
vizact.onkeydown(' ', viz.MainView.runAction, spinAction )

See also

In this section:

Viewpoint basics

Camera handlers

Viewpoint collision and gravity

Viewpoint command table

Other sections:

Linking basics

Viewpoint and Window basics

Stereo basics

Animation path basics

Action basics

Tutorial: Viewpoint control

Tutorial: Windows & views

Example scripts:

Viewpoint camera control

Viewpoint animation

Viewpoint collision

Window views