Vizard 8 » Tutorials & Examples » Example scripts » 3D Models » Translation
8.0

translation

\examples\nodes\translation.py

This script will demonstrate how to manually animate an object using timers.

"""
This script will demonstrate how to manually animate an object using timers.
"""
import viz
import vizact
import math

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

import vizinfo
vizinfo.InfoPanel()

#The speed of the timer.  A value of 0 means the timer function
#Will be called every frame
UPDATE_RATE = 0

#The speed of the translation
SPEED = 50.0

#A variable to hold the angle
angle = 0

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

#Add a model to rotate
h = viz.addChild('tut_hedra.wrl')

#Place the model in front of the viewer
h.setPosition([0,0,6])

def moveModel():
    global angle

    #Increment the angle based on elapsed time
    angle = angle + (SPEED * viz.elapsed())

    #Set the height of the object to double the sine of the angle
    height = math.sin(viz.radians(angle)) * 2.0

    #Update the models rotation
    h.setEuler([angle,0,0])

    #Translate the object
    h.setPosition([0,height,6])

#setup a timer and specify it's rate and the function to call
vizact.ontimer(UPDATE_RATE, moveModel)