animateView.py

This script demonstrates how to animate the viewpoint.

 

import viz
import vizact

viz.setMultiSample(4)
viz.fov(60)
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.addChild('ground.osgb')

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

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

#Add radiobuttons
blend = viz.addRadioButton(0,pos=[0.19,0.78,0],scale=[0.77, 0.77, 1])
pivot = viz.addRadioButton(0,pos=[0.19,0.835,0],scale=[0.77, 0.77, 1])
none = viz.addRadioButton(0,pos=[0.19,0.88,0],scale=[0.77, 0.77, 1])
none.set(viz.ON)

#Add labels
label = viz.addText('Rotate mode:', parent = viz.SCREEN, pos=[0.012,0.935,0], scale=[0.596,0.596,1], color=viz.RED)
label.setBackdrop(viz.BACKDROP_CENTER_BOTTOM)
label1 = viz.addText('None', parent = viz.SCREEN, pos=[0.039,0.872,0], scale=[0.515,0.515,1])
label1.setBackdrop(viz.BACKDROP_CENTER_BOTTOM)
label2 = viz.addText('Pivot', parent = viz.SCREEN, pos=[0.039,0.817,0], scale=[0.515,0.515,1])
label2.setBackdrop(viz.BACKDROP_CENTER_BOTTOM)
label3 = viz.addText('Blend', parent = viz.SCREEN, pos=[0.039,0.767,0], scale=[0.515,0.515,1])
label3.setBackdrop(viz.BACKDROP_CENTER_BOTTOM)

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