matrix.py

This script demonstrates how to apply your own 4x4 matrix to an object.

 

import viz
import vizact
import vizshape

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

import vizinfo
vizinfo.add('This script demonstrates how to apply your own 4x4 matrix to an object.\nPress the spacebar to switch between transforming the cone and viewpoint')

#Variable for translation
translation = 0

mode = 0

viz.addChild('ground.osgb')
cone = viz.addChild('tut_cone.wrl')

X = viz.Transform()
X.makeIdent()
X.postTrans(translation,1.6,7)
viz.MainView.setMatrix(X)
cone.setMatrix(X)

def changeMode():
    global mode
    mode = mode ^ 1
   
vizact.onkeydown(' ', changeMode)
   
def animate():
    global translation
    X.makeIdent()
    X.postTrans(translation,1.6,7)
    translation = translation + .01
    if translation > 3:
        translation = -3
       
    if mode:
        viz.MainView.setMatrix(X)
    else:
        cone.setMatrix(X)

vizact.ontimer(0, animate)

viz.clearcolor(viz.SKYBLUE)