You can use the
getPosition command with any node3D object. This returns the position of the object's center point which is defined in the modeling software. In the case of the avatar, this center point is at the avatar's feet level. To get the distance between points use the
vizmat.Distance command. If you're checking the distance between an avatar and the viewpoint you'll want to take into account the different height values of each. The following code prints out the distance between avatars and an avatar and the viewpoint:
Code:
import viz
import vizact
import vizmat
viz.go()
viz.add('piazza.osgb')
avatar1 = viz.addAvatar('vcc_male2.cfg',pos=[0.5,0,0])
avatar2 = viz.addAvatar('vcc_male2.cfg',pos=[-0.5,0,0])
walk1 = vizact.walkTo([5,0,15])
walk2 = vizact.walkTo([-5,0,15])
avatar1.addAction(walk1)
avatar2.addAction(walk2)
def printDistances():
avatar1_pos = avatar1.getPosition()
avatar2_pos = avatar2.getPosition()
x,y,z = viz.MainView.getPosition()
print "Distance between avatars", vizmat.Distance(avatar1_pos,avatar2_pos)
# zero viewpoint height and check distance to avatar
print "Distance between view and avatar1", vizmat.Distance([x,0,z],avatar1_pos)
vizact.ontimer(1,printDistances)