Vizard 7 » Tutorials & Examples » Example scripts » Linking » Basic linking
7.6

Basic linking

\examples\linking\basicLinking.py

This script demonstrates linking one node to another.

"""
This script demonstrates linking one node to another.
To link nodes, you specify the source node,
the node that provides the position and orientation data,
and the destination node,
the node that takes on the source's position and orientation.
"""
import viz
import vizact
import vizconfig

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

import vizinfo
vizinfo.InfoPanel(align=viz.ALIGN_RIGHT_BOTTOM)

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


linkConfig = vizconfig.BasicConfigurable('Link objects with checkboxes below')
linkConfig.addBoolItem('Male to Sensor', fset=maleLink.setEnabled)
linkConfig.addBoolItem('View to Male', fset=viewLink.setEnabled)
vizconfig.register(linkConfig)
vizconfig.getConfigWindow().setWindowVisible(True)