View Single Post
  #3  
Old 02-16-2018, 08:45 AM
zmm zmm is offline
Member
 
Join Date: Feb 2018
Posts: 2
Thank you for your reply. I will try out what you suggest for the first point.

For the second point: In my code (see below for the core code), there is not a link to the avatar but selected from the object list, how do I link it to the head if I don't have the tracker?

Code:
###server###
import viz
import viznet
import steve
import random

viz.go()
viz.clearcolor(.2,.2,.4)

viz.MainWindow.fov(60)

viz.MainView.setPosition([0,1.5,-6])
viz.MainView.setEuler([0,0,0])

objectList = ['vcc_male.cfg','vcc_female.cfg'] 
maze = viz.add('piazza.osgb') 

objects = {} 

UPDATE = viznet.id('update') 
CLIENT_DISCONNECTED = viznet.id('client_disconnected') 
CHAT = viznet.id('chat') 


viznet.server.start(port_in=14950,port_out=14951) 

def onStartClient(e): 
    print '** Client joined with username:',e.username 
viz.callback(viznet.CLIENT_CONNECT_EVENT,onStartClient) 

def onStopClient(e): 
    print '** Client left with username:',e.username 
    viznet.server.send(CLIENT_DISCONNECTED,client=e.sender,username=e.username) 
    objects[e.username].remove() 
    del objects[e.username]
viz.callback(viznet.CLIENT_DISCONNECT_EVENT,onStopClient) 

def update(e): 
    try: 
        objects[e.username].setPosition(e.pos) 
        objects[e.username].setEuler(e.ori)  
        objects[e.username].state(e.state)
    except KeyError:
        objects[e.username] = viz.add(objectList[e.object],scale=[1,1,1],pos=e.pos,euler=e.ori) 
        objects[e.username].tooltip = e.username
        objects[e.username].state(e.state)
viz.callback(UPDATE,update)
Code:
###client###
import viz
import viznet
import vizinfo
import vizinput

viz.go()
viz.clearcolor(.2,.2,.4)
maze = viz.add('piazza.osgb')
objects = {}

UPDATE = viznet.id('update') 
CLIENT_DISCONNECTED = viznet.id('client_disconnected') 
CHAT = viznet.id('chat') 

SERVER_NAME='PC04720'

USER_NAME='client1'

while not viznet.client.connect(SERVER_NAME,port_in=14951,port_out=14950,username=USER_NAME): 
    if vizinput.ask('Could not connect to ' + SERVER_NAME + ' would you like to try another?'): 
        SERVER_NAME=vizinput.input('Enter Server Name') 
    else: 
        viz.quit() 
        break 
objectList = ['vcc_male.cfg','vcc_female.cfg'] 
obj_choice=vizinput.choose('Connected. Select your character',objectList)

#set initial position
viz.MainView.setPosition([2, 0 ,0])
viz.MainView.setEuler([270,0,0])
currentState = 1

def sendUpdate():
    ori= viz.MainView.getEuler()
    pos = viz.MainView.getPosition()
    viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori, state=currentState, username=USER_NAME)
vizact.ontimer(.05,sendUpdate)

def update(e): 
    if e.username != USER_NAME: 
        try: 
            objects[e.username].setPosition(e.pos) 
            objects[e.username].setEuler(e.ori) 
        except KeyError: 
            objects[e.username] = viz.add(objectList[e.object],scale=[1,1,1],pos=e.pos,euler=e.ori) 
            objects[e.username].tooltip = e.client 
viz.callback(UPDATE,update) 

def client_disconnected(e): 
    objects[e.username].remove() 
    del objects[e.username] 
viz.callback(CLIENT_DISCONNECTED,client_disconnected) 

def onExit():
    viznet.client.disconnect(username=USER_NAME)
viz.callback(viz.EXIT_EVENT,onExit)

def onStopServer(e): 
    print 'Disconnected from server' 
    viz.quit() 
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopServer)
Reply With Quote