WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-15-2013, 09:37 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
Unhappy random walk in piazza environment

hi,

I would like to generate a random walk actions for the avatar in the piazza environment. I want the avatar to walk around the environment by itself (without pressing any key) and to perform some actions when it sees a red sphere.

I have tried to write some code, but the avatar is moving around an oval. I am really stuck .. I don't know how to do it.

this is the code:

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

viz.add('ground.osgb')
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,9])
avatar.state(1)

walkLeft = vizact.walkTo([2.5,0,9])
walkRight = vizact.walkTo([-2.5,0,9])
walkActions = viz.cycle([walkLeft,walkRight])

waitSpaceBar = viztask.waitKeyDown(' ')
waitLeft = viztask.waitActionEnd(avatar,walkLeft)
waitRight = viztask.waitActionEnd(avatar,walkRight)
waitActions = viz.cycle([waitLeft,waitRight])

def walkAndStopTask():
	yield waitSpaceBar
	while True:
		condition = waitSpaceBar
		walkAction = walkActions.next()
		waitAction = waitActions.next()
		while condition == waitSpaceBar:
			avatar.runAction(walkAction)
			d = yield viztask.waitAny([waitSpaceBar,waitAction])
			condition = d.condition
			if condition == waitSpaceBar:
				avatar.clearActions()
				yield waitSpaceBar
			
viztask.schedule(walkAndStopTask())


your support is highly appreciated
Reply With Quote
  #2  
Old 12-16-2013, 12:53 PM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
I have posted the wrong code. so plz ignore it. below is the right code.

I managed to simulate an avatar walking randomly. however, I wanted the avatar to pick up the cellphone when he reaches the red sphere. I have the code for that but I did not know how to do it in a simulated way (without pressing any key)

this is the code that I am working on:
Code:
import viz
import viznet
import vizinfo
import vizinput
import viztask
import vizact
import vizshape
import vizproximity
import vizmat
viz.go()

viz.go()
viz.MainView.setPosition([0,0.1,0])
viz.setMultiSample(4)
#Increase the Field of View
viz.MainWindow.fov(60)

#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)
#avatar.state(1)
#viz.collision(viz.ON)



piazza = viz.add('piazza.osgb')
sphere = vizshape.addSphere(radius=0.2)
sphere.setPosition(0,0,20)
sphere.color(viz.RED)

text = viz.addText('radiation source',parent=sphere)
text.setPosition([-0.3,0.3,0])
text.setScale([0.2]*3)
text.color(viz.RED)
text.visible(viz.ON)

text_2D = viz.addText('radiation source area', viz.SCREEN )
text_2D.setPosition(0,0,20)
text_2D.color(viz.RED)
t=text_2D.visible(viz.OFF)

tex = viz.addTexture('logo.jpg')




#maze = viz.add('tankmaze.wrl')
#def onKeyDown(key): 
     #if key == viz.iskeydown ('t' ):
walk1=vizact.walkTo([4,0,0])
walk2=vizact.walkTo([4,0,3])
walk3=vizact.walkTo([7,0,4])

walk4=vizact.walkTo([8.5,0,17])
walk5=vizact.walkTo([10,0,22])
walk6=vizact.walkTo([3,0,23])

#walk=vizact.walkTo([0,0,15])

def changeState() :
    
    #Add the cellphone model
    cell = viz.addChild('phone.3ds')

    #Get the right hand bone of the avatar
    hand = avatar.getBone('Bip01 R Hand')

    #Link the cellphone to the hand
    CellLink = viz.link(hand,cell)

    #Tweek the cellphone link so it fits snuggly in the hand
    CellLink.preTrans( [0.06,-0.08,0.08] )
    CellLink.preEuler( [0,0,180] )
#thick = vizact.method()

walks=vizact.sequence(walk1,walk2, vizact.waittime(1),walk3, vizact.waittime(1),walk4, vizact.waittime(1),walk5,vizact.waittime(1),walk6)
viz.collision(viz.ON)

avatar.addAction(walks)



    #Make the avatar use the cellphone when the 'w' key is pressed
#vizact.onkeydown('w',avatar.execute,15)

#vizact.onkeydown('t',walk)

#Register the callback which to call the 'onKeyDown' function. 
#viz.callback(viz.KEYDOWN_EVENT,onKeyDown) 
	



#Create proximity manager
manager = vizproximity.Manager()

#Add main viewpoint as proximity target
target = vizproximity.Target(avatar)
manager.addTarget(target)

sensor = vizproximity.Sensor( vizproximity.CircleArea(5),source=sphere)

manager.addSensor(sensor)

def EnterProximity(e):
    text_2D.visible(viz.ON)
    quad = viz.addTexQuad()
    quad.setPosition([0,1,20])
    quad.texture(tex) # The quad will now display the tree picture
    spin=vizact.sequence(vizact.waittime(1), vizact.spin(0,1,0,20))
    vizact.addCallback
    quad.addAction(spin)

    
def ExitProximity(e):
    text_2D.visible(viz.OFF)
    

manager.onEnter(sensor,EnterProximity)
manager.onExit(sensor,ExitProximity)
Reply With Quote
  #3  
Old 01-02-2014, 05:59 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Simply add
Code:
avatar.execute(15)
to the EnterProximity function. Now, your avatar will execute its 15th animation (in your case the useitem animation) when it nears the red sphere.
Reply With Quote
  #4  
Old 01-15-2014, 02:44 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
thanks it worked.

I have another question.

I replaced the avatar with the steve module and I added the move to action to the module, but I got this error:

player_matrix.aaddAction(walks)
AttributeError: 'Transform' object has no attribute 'addAction'

how can I simulate the movement of the steve as I did with the avatar in the code provided above?

thanks.
Reply With Quote
  #5  
Old 01-15-2014, 02:56 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
You cannot add an action to a matrix. You can add an action to an avatar. Look carefully how you named the 3D-model of steve, and add the action to that model. That should solve your problem.

And there was a type in your addaction command, it was spelled aaddaction.
Reply With Quote
  #6  
Old 01-15-2014, 03:44 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
thanks it worked. however, I want to c what the steve module sees infront of him (what he is looking at).

I want it to be in this way as reflected in the upper right view:
this is the code:

Code:
import viz
import viznet
import vizinfo
import vizinput
import viztask
import vizact
import vizshape
import vizproximity
import vizmat
import steve

viz.setMultiSample(4)
viz.fov(60)
viz.go()

# Use the steve module to represent the other user.
# You will actually have no representation of yourself on your own monitor.
player_matrix = viz.Matrix()
avatar = steve.Steve()
avatar.setTracker(player_matrix)

# Add the world
maze = viz.addChild('piazza.osgb')

#Use a prompt to ask the user the network name of the other computer.
target_machine = vizinput.input('Enter the name of the other machine').upper()

#Add a mailbox from which to send messages. This is your outbox.
target_mailbox = viz.addNetwork(target_machine) 

def sendPosition():

     #Retrieve current transform of viewpoint
     mat = viz.MainView.getMatrix()

     #Send position/rotation to target network object
     target_mailbox.send(action=updatePlayer, quat=mat.getQuat(), pos=mat.getPosition())

# Start a timer that sends out data over the network every frame
vizact.ontimer(0,sendPosition)

def updatePlayer(e):
     player_matrix.setPosition(e.pos)
     player_matrix.setQuat(e.quat)

# Listens for any incomming messages
def onNetwork(e):
     if e.sender.upper() == target_machine:
         e.action(e)

# Register network to listen from incomming messages
viz.callback(viz.NETWORK_EVENT, onNetwork)

# Create a new window in the upper left corner
UpperLeftWindow = viz.addWindow(pos=(0,1.0),size=(0.5,0.5))
UpperLeftWindow.visible(0,viz.SCREEN)

#Create a new window in the upper right corner
UpperRightWindow = viz.addWindow(pos=(0.5,1.0),size=(0.5,0.5))
UpperRightWindow.visible(0,viz.SCREEN)

# Create a new viewpoint
BirdView = viz.addView()

#Attach the bird's eye view to the upper left window
UpperLeftWindow.setView(BirdView)

#Move the view above the center of the room
BirdView.setPosition([0,25,0])

#Rotate the view so that it looks down
BirdView.setEuler([0,90,0])

#Create another viewpoint
RearView = viz.addView()

#Attach the rear view to the upper right window
UpperRightWindow.setView(RearView)

#Increase the field-of-view for both windows
UpperLeftWindow.fov(70)
UpperRightWindow.fov(60)

#Add an arrow marker to bird's eye view window to represent our current position/orientation
arrow = viz.addTexQuad(parent=viz.ORTHO,scene=UpperLeftWindow,size=20)
arrow.texture(viz.add('arrow.tif'))

def UpdateViews():

	#Get the current head orientation and position
	yaw,pitch,roll = player_matrix.getEuler()
	pos = player_matrix.getPosition()

	#Move the rear view to the current position
	RearView.setPosition(pos)

	#Rotate the rear view so that it faces behind us
	RearView.setEuler([yaw,0,0])

	#Move arrow to our current location
	x,y,z = UpperLeftWindow.worldToScreen(pos,mode=viz.WINDOW_PIXELS)
	arrow.setPosition([x,y,0])
	arrow.setEuler([0,0,-yaw])

vizact.ontimer(0,UpdateViews)

# Turn on collision detection so we can't go through walls
#viz.collision(viz.ON)
walk1=vizact.moveTo([4,0,0])

walk2=vizact.moveTo([4,0,3])
walk3=vizact.moveTo([7,0,4])

walk4=vizact.moveTo([8.5,0,17])
walk5=vizact.moveTo([10,0,22])
walk6=vizact.moveTo([3,0,23])
walks=vizact.sequence(walk1,walk2, vizact.waittime(1),walk3, vizact.waittime(1),walk4, vizact.waittime(1),walk5,vizact.waittime(1),walk6)
#avatar.addAction(walks)


#avatar.addAction(vizact.walkTo([0,0,7]))

btw, I commented the "add action" .
thanx
Reply With Quote
  #7  
Old 01-15-2014, 04:20 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Not sure if this will work, but you could try:
Code:
viz.link(player_matrix, RearView)
Reply With Quote
  #8  
Old 01-15-2014, 05:58 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
it did not work.

what is happening know is that the movement of the steve module is linked with the mainview. so, when I move the mouse, the representation of the steve module moves as well.

basically what I want is to make the movement of Steve in a random way instead linking it with a mouse. this is done by the moveTo action. but, I want the user feel as if he is the one who is moving. I want the metal head cover to appear in the to right screen as it is the case for the mouse movement.

I hope it is clear.

thanx.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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
random coding Saz Vizard 1 05-27-2010 06:44 PM
random speed and associated coding Saz Vizard 1 05-20-2010 05:03 AM
Getting a mirror to work in any environment Frank Verberne Vizard 5 03-27-2008 09:21 AM
custom avatar random walk krimble Vizard 2 03-20-2007 04:23 AM
Random Seeds Vygreif Vizard 1 04-27-2006 10:21 PM


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


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