PDA

View Full Version : multi user


maya
11-09-2013, 11:28 PM
hi,

I am implementing a search and rescue mission scenario that includes a team of robots and humans. each robot must perform a specific task.

so far, I am controlling only one avatar.
I am trying to control 2 avatars at the same time.

how can I do it?

this is my code

import viz
import viztask
import vizmat
import vizact
import vizshape
import vizinfo

viz.go()

#Enable full screen anti-aliasing (FSAA) to smooth edges
viz.setMultiSample(4)

#Increase the Field of View
viz.MainWindow.fov(60)

piazza = viz.add('piazza.osgb')
#avatarRoot = viz.addGroup()
avatarRoot = viz.add('marker.wrl')
#cameraLookAtNode = viz.addGroup(parent=avatarRoot, pos=[100, 0, 0])
avatar = viz.add('vcc_male.cfg', parent=avatarRoot)
#viz.add('tut_ground.wrl')

#add radiation source
#vizshape.addBox(size=(1.0,1.0,1.0),right=True,lef t=True,top=True,bottom=True, front=True,back=True,splitFaces=False)
#box = vizshape.addBox([1,1,1],splitFaces=True,pos=(0,0,4))
#box=vizshape.addSphere()
sphere=vizshape.addSphere(radius=0.25,slices=20,st acks=20, axis=vizshape.AXIS_Y)

sphere.setPosition(0,0, 20)
sphere.color(viz.RED)
sphere.texture

#if viz.iskeydown('i'):
##info.translate( [.98, .3] )
#Add text to the screen.
text_2D = viz.addText('i am radiation', viz.SCREEN )
text_2D.setPosition(0,0,20)
#text_2D.visible(viz.OFF)



def checkPos(newPos):
#newPos=vizmat.Vector()
newPos1=newPos.get
newPos2=[0,0,22]
if newPos1==newPos2:
print"h"

print "rad target"
yield None
def moveAvatar():
while True:
#get user input
newPos = vizmat.Vector()
newPos.set([0,0,0])
if viz.iskeydown('w'):
#walk forward
newPos = newPos + [0, 0, 1]
checkPos(newPos)
if viz.iskeydown('s'):
newPos = newPos + [0, 0, -1]
if viz.iskeydown('a'):
newPos = newPos + [-1, 0, 0]
if viz.iskeydown('d'):
newPos = newPos + [1, 0, 0]
isJumping = False
isAttacking = False
if viz.iskeydown(' '):
#jump
isJumping = True
elif viz.iskeydown('v'):
isAttacking = True

if isAttacking:
avatar.state(6)
yield viztask.waitTime( 1.5 )
if newPos.length() > 0 or isJumping:
if newPos.length() == 0:
#jumping but no direction key, use current heading
t = vizmat.Transform()
t.setTrans([0, 0, 1.8])
t.postEuler(avatar.getEuler()[0],0,0)
newPos = vizmat.Vector( t.getTrans() )
newYaw = vizmat.AngleToPoint(0, 0, newPos[0], newPos[2])
avatar.setEuler(newYaw, 0, 0)
if not isJumping:
#just walking
cameraEuler = viz.MainView.getEuler()
avatarRoot.setEuler(cameraEuler[0], 0, 0)
newPos = newPos * viz.getFrameElapsed()
avatarRoot.setPosition(newPos, viz.REL_LOCAL)
avatar.state(2)
else:
#jumping
avatar.state(7)
yield viztask.waitTime( avatar.getDuration(7)+.01 )
#compute jump direction
newJumpPos = vizmat.Transform()
newJumpPos.setTrans([0, 0, 1.8])
newJumpPos.postEuler(avatar.getEuler(viz.ABS_GLOBA L)[0], 0, 0)
avatarRoot.setPosition(newJumpPos.getTrans(), viz.REL_GLOBAL)



if not (viz.iskeydown(' ') or viz.iskeydown('w') or viz.iskeydown('s') or viz.iskeydown('a') or viz.iskeydown('d') ):
avatar.state(1)

yield None




viztask.schedule(moveAvatar())


import vizcam
camera = vizcam.PivotNavigate()
camera.setDistance(5)

def moveCamera():
while True:
lookAtPos = avatar.getBone('Bip01 Pelvis').getPosition(viz.ABS_GLOBAL)
lookAtPos[1] = lookAtPos[1] + .5
camera.setCenter(lookAtPos)
camera.updateCenter()
yield None

viztask.schedule(moveCamera())

maya
11-18-2013, 09:31 AM
one more thing, I have checked the multi user environment example in the reference>networking and I am trying to link this example with my code.
I don't know how to do it with the function moveAvatar since it gets the user input and saves it in a variable newPos.
in the multi user environment example, the user selects an object from a list of objects.
what I want to do is send the position of the selected object to the moveAvatar function so I can control the avatar movement.
thanks,