multi user
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
HTML 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,left=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,stacks=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_GLOBAL)[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())
|