WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-23-2013, 09:35 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
Exclamation multi user environment tutorial

hi,

I have been exploring the multi user tutorial in the reference.
I was trying to control the movement of the avatar (selected object from the object list) using keyboard. I have the code for the movement, but I didn't know how to do it.

this is the code for movement:

Code:
import viz
import viztask
import vizmat
viz.go()

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

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]
		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())
my questions are:
1. in the moveAvatar function, the position of the avatar is saved in a variable newPos. what part of the multi user tutorial sets the selected object position?

2. how can I change the position of the selected object in the multi user tutorial

multi user environment code:
Code:
objectList = ['duck.wrl','logo.wrl','vcc_male.cfg','vcc_female.cfg'] 
obj_choice=vizinput.choose('Connected. Select your character',objectList)
Code:
def sendUpdate():
     ori= viz.MainView.getEuler()
     pos = viz.MainView.getPosition()
     viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori)
 vizact.ontimer(.05,sendUpdate)
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 maya Vizard 1 11-18-2013 10:31 AM
Multi User Environment moneim230 Vizard 5 05-17-2011 06:56 PM
begginer tutorial shader? Darkmax Vizard 1 04-15-2010 05:26 PM
Controlling User Input ohad Vizard 1 03-15-2010 06:16 PM
Getting a mirror to work in any environment Frank Verberne Vizard 5 03-27-2008 09:21 AM


All times are GMT -7. The time now is 08:21 PM.


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