Vizard 7 » Tutorials & Examples » Example scripts » 3D Models » Rotation
7.2.1

Rotation

\examples\nodes\rotation.py

This script will demonstrate how to animate simple rotations using timers.

"""
This script demonstrates how to animate simple rotations using timers
"""
import viz
import vizact

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 rotation
SPEED = 50.0

#A variable that will hold the angle
angle = 0

#Add a ground plane
viz.addChild('ground_gray.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 rotateModel():
    global angle

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

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

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