WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-09-2013, 11:28 PM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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())
Reply With Quote
  #2  
Old 11-18-2013, 09:31 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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,
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi User Environment moneim230 Vizard 5 05-17-2011 05:56 PM
Controlling User Input ohad Vizard 1 03-15-2010 05:16 PM
New user please HELP!!! dj_neo Vizard 1 03-18-2007 12:18 PM
find direction user is facing paulpars Vizard 1 06-16-2006 01:40 PM
user input problem Jerry Vizard 1 11-16-2005 03:15 PM


All times are GMT -7. The time now is 06:17 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC