Vizard 8 » Tutorials & Examples » Example scripts » Viewpoint » Viewpoint animation
8.1

Viewpoint Animation

\examples\viewAnimate\animateview.py

This script demonstrates how to animate the viewpoint.

"""
This script demonstrates how to animate the viewpoint
The keys 1-4 move the viewpoint to a different location
Try changing the rotation mode for interesting effects
"""
import viz
import vizact

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

import vizinfo
info = vizinfo.InfoPanel(align=viz.ALIGN_RIGHT_TOP)

# Create info panel for rotate mode
modePanel = vizinfo.InfoPanel('', title='Rotate Mode', align=viz.ALIGN_LEFT_TOP, icon=False)
none = modePanel.addLabelItem('None',viz.addRadioButton('RotateMode'))
pivot = modePanel.addLabelItem('Pivot',viz.addRadioButton('RotateMode'))
blend = modePanel.addLabelItem('Blend',viz.addRadioButton('RotateMode'))
none.set(True)

#Add a ground plane
viz.addChild('ground.osgb')

#Set the background color
viz.clearcolor(viz.SLATE)

#Add the vizard logo
logo = viz.addChild('logo.ive')

#Set the animation speed and mode
SPEED = 2.5
MODE = viz.SPEED
ROTATE_MODE = viz.NO_ROTATE

def SetRotateMode(mode):
    global ROTATE_MODE
    ROTATE_MODE = mode

def AnimateView(pos):
    action = vizact.goto(pos,SPEED,MODE,pivot=(0,1,0),rotate_mode=ROTATE_MODE)
    viz.MainView.runAction(action)

#Setup keyboard events
vizact.onkeydown('1',AnimateView,[0,1,-3])
vizact.onkeydown('2',AnimateView,[3,0.1,0])
vizact.onkeydown('3',AnimateView,[0,1,3])
vizact.onkeydown('4',AnimateView,[-3,2,0])

#Setup button click events
vizact.onbuttondown(none,SetRotateMode,viz.NO_ROTATE)       #The viewpoint will not rotate while it's  moving
vizact.onbuttondown(pivot,SetRotateMode,viz.PIVOT_ROTATE)   #The viewpoint will look at the pivot point while it's moving
vizact.onbuttondown(blend,SetRotateMode,viz.BLEND_ROTATE)   #The viewpoint will blend to looking at the pivot point

#Start off by moving to the first location
AnimateView([0,1,-3])