basicLinking.py
This script demonstrates linking one node to another.
import viz
import vizact
viz.setMultiSample(4)
viz.fov(60)
viz.go()
import vizinfo
info = vizinfo.add(
'This script demonstrates linking one node to another.\nTo
link nodes, you specify the source node, \nthe node that provides the
position and orientation data, \nand the destination node, \nthe node
that takes on the source\'s position and orientation.' )
info.translate([.98,.3])
viz.addChild( 'lab.osgb'
)
viz.MainView.setPosition( [0, 2, -5] )
sensor = viz.addSensor( 'testtrack_all.dls' )
#Position and orientation data source
arrow = viz.addChild( 'marker.wrl' )
viz.link( sensor,
arrow )
#Model we will move around with the magic of linking
male = viz.addAvatar( 'vcc_male.cfg' )
#Make male to take the position and orientation of sensor
maleLink = viz.link( sensor, male,
enabled=False )
#Offset the position of the male from the sensor by applying
a postTrans operator
#The postTrans operator translates his position in world
coordinates from the source position
maleLink.postTrans( [0, 1, 0] )
#Move camera over male's shoulder
viewLink = viz.link( male, viz.MainView, enabled=False
)
viewLink.preEuler( [0, 45, 0] ) #rotate camera
down 40 degrees
viewLink.preTrans( [0, 0, -5] ) #translate camera back 5 meters in local coordinates, that's
back 2.5 and up 2.5 in world cordinates
viewLink.preEuler( [0, -20, 0] ) #rotate camera up 20 degrees to look forward
linkChanger = vizinfo.add( 'Link objects with the check boxes below.'
)
maleToSensor = linkChanger.add( viz.CHECKBOX,
'Male to Sensor' )
viewToMale = linkChanger.add( viz.CHECKBOX,
'View to Male' )
vizact.onbuttondown( maleToSensor, maleLink.enable )
vizact.onbuttonup( maleToSensor, maleLink.disable )
vizact.onbuttondown(viewToMale, viewLink.enable)
vizact.onbuttonup(viewToMale, viewLink.disable)