##############################################################
# duckwalk
Andy Beall 1999
#
# This program demonstrates how to connect to VRUT sessions
# together using the network features. This only requires
that
# two machines be in the same network domain but does not
# require TCP so the computers don't need IP addresses.
#
# On each computer, the other user is represented as a duck.
When
# the other person move around, you'll see the duck go.
#
# If a third computer runs this program at the same time in the
# same domain, who knows what will happen because this is a
# dumb script that doesn't check who's sending the message.
#
##############################################################
##############################################################
import vrut
from string import *
vrut.go(vrut.NICE)
INITIALIZE = 1
BROADCAST = 2
duck = vrut.addchild('duck.wrl')
maze = vrut.addchild('tankmaze.wrl')
vrut.clearcolor(.2,.2,.4)
mailbox = vrut.addmail()
##############################################################
def mytimer(num):
if num == INITIALIZE:
duck.scale(2,2,2)
if num == BROADCAST:
yaw = vrut.get(vrut.HEAD_ORI);
pos = vrut.get(vrut.HEAD_POS);
out = ' '+str(yaw[0])+' '+str(pos[0])+' '+str(pos[2])
mailbox.send(out)
vrut.starttimer(BROADCAST, .1)
##############################################################
def mymail(message):
s = split(message)
if len(s) == 4:
yaw = atof(s[1])
x = atof(s[2])
z = atof(s[3])
duck.translate(x, 0, z)
duck.rotate(0, 1, 0, yaw+180)
vrut.callback(vrut.TIMER_EVENT, 'mytimer')
vrut.callback(vrut.MAIL_EVENT, 'mymail')
vrut.starttimer(INITIALIZE, .1)
vrut.starttimer(BROADCAST, .1)