animateView.py

This script demonstrates how to animate the viewpoint.

 

If you run the script animateView.py included in the  /examples/Viewpoint folder, GUI controls are provided to control viewpoint animation.  These are saved in the associated .viz file in that folder.

 

import viz
viz.go()

import vizinfo
vizinfo.add('This script demonstrates how to animate the viewpoint\nThe keys 1-4 move the viewpoint to a different location\nTry changing the rotation mode for interesting effects')

#Add a ground plane
viz.add('tut_ground.wrl')

#Set the background color
viz.clearcolor(0.5,0.5,1)

#Add the vizard logo
logo = viz.add('logo.wrl',pos=(0,1,0))

#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])