PDA

View Full Version : How to link the Mainview to a child object


jacky
05-01-2013, 10:22 AM
Hi everyone,

I want to link the Mainview to the box2. The box2 is the child of box1. When the box1 changes its position and orientation, the box1 will follow it and the Mainview too. But it doesn't work. When I operate the position of box1. The Mainview doesn't move. Who knows the reasons? My script is below.

import viz
import vizact
import math
viz.go()

dojo = viz.addChild('dojo.osgb')
box1=viz.addChild('crate.osgb')
box1.setScale(0.1,0.1,0.1)
box1.setPosition(0,1.8,1)
box1.color(viz.RED)

box2=viz.addChild('crate.osgb')
box2.setPosition(0,1,0)
box2.color(viz.BLUE)

box2.setParent(box1)
link1=viz.link(box2,viz.MainView)

def position():
pos=box1.getPosition()
pos[0]=pos[0]+0.01
box1.setPosition(pos)

vizact.onkeydown('1',position)

Jeff
05-02-2013, 09:51 AM
You'll need to specify that the link is getting the source object's position in global coordinates. Otherwise the link takes the position of box2 in it's parent's coordinate system which is fixed at [0,1,0].
link1=viz.link(box2,viz.MainView,srcFlag=viz.ABS_G LOBAL)