WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-03-2017, 10:49 PM
imnotamember imnotamember is offline
Member
 
Join Date: Jan 2017
Posts: 2
Problem Rotating object linked to viz.HEAD

Hi all,

I'm trying to make a compass to guide a person to their next location in a room and having the hardest time doing it. I've been creating an arrow that sits just before the main view and every second the .lookAt() method is run to turn the arrow towards the next spot. The problem I'm currently stuck with is that the arrow doesn't turn independently relative to the main view's position.

Here is code using the gallery sample to highlight how the arrow is working:

Code:
import viz
import vizact
import vizshape

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

viz.MainView.move([0,0,-1])

#Create skylight
viz.MainView.getHeadLight().disable()
sky_light = viz.addLight(euler=(0,90,0))
sky_light.position(0,0,-1,0)
sky_light.color(viz.WHITE)
sky_light.ambient([0.9,0.9,1])

#Add the gallery model
gallery = viz.addChild('gallery.osgb')

#Add audio
music = viz.addAudio('bach_air.mid',loop=1)
music.loop(viz.ON)
music.play()

#Add an avatar
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,1])
avatar.state(1)

#Create static drop shadow to avatar
shadow_texture = viz.addTexture('shadow.png')
shadow = vizshape.addQuad(parent=avatar,axis=vizshape.AXIS_Y)
shadow.texture(shadow_texture)
shadow.zoffset()

#Move avatar around the room with a sequence of walk, turn, and wait actions

#Create action to wait 5-10 seconds
RandomWait = vizact.waittime(vizact.randfloat(5,10))

#A list of painting locations
avatarMove = [[-3.7,2.2,300],[-3.7,6.5,270],[0,8,0],[3.7,6.5,90],[3.7,2.6,90],[3.7,1,130]]
actions = []
for loc in avatarMove:
	#Add an action to walk to the next painting, turn towards it, and wait a few seconds
	actions.append(vizact.method.playsound('footsteps.wav',viz.LOOP))
	actions.append(vizact.walkTo([loc[0],0,loc[1]],turnSpeed=250.0))
	actions.append(vizact.method.playsound('footsteps.wav',viz.STOP))
	actions.append(vizact.turn(loc[2],250.0))
	actions.append(RandomWait)

#Repeat the sequence of actions forever
avatar.addAction(vizact.sequence(actions,viz.FOREVER))

arrow = viz.addChild('marker.wrl', parent=viz.HEAD)
arrow.alpha(.8)
arrow.setScale([.25]*3)
arrow.setPosition(0,0,.5)

def updateArrow():
	arrow.lookAt(avatar.getPosition(mode=viz.ABS_GLOBAL), mode=viz.ABS_GLOBAL)

vizact.ontimer(0,updateArrow)
As you'll see, regardless of where you (viz.HEAD) move or turn in the gallery, the arrow responds only as though it were permanently located at the spot it first started. I want it to make real-time updates on where the guy and look towards him regardless of where the viz.MainView is located/turned towards. Thank you in advance for any ideas you might have.
Reply With Quote
  #2  
Old 01-04-2017, 04:43 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,455
Take a look at the example code in this post.
Reply With Quote
  #3  
Old 01-04-2017, 11:44 PM
imnotamember imnotamember is offline
Member
 
Join Date: Jan 2017
Posts: 2
Thanks Jeff,

While that is really helpful (helped resolve some other issues) it didn't quite resolve my problem. The problem I'm stuck on is how to have the arrow point to the avatar while remaining independent from the main view's orientation. In the current situation, it is now independent of the main view but not pointing toward the avatar. I have a feeling I need to unlink the arrow from the avatar but then it becomes dependent on the main view's orientation again.

In the post you linked to you described it as an HUD, which is essentially what I'm going for. I just want this arrow to act like a compass that is always pointing toward the avatar. Here is my integration of your post-linked code and my own:
Code:
import viz
import vizact
import vizshape

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

viz.MainView.move([0,0,-1])

#Create skylight
viz.MainView.getHeadLight().disable()
sky_light = viz.addLight(euler=(0,90,0))
sky_light.position(0,0,-1,0)
sky_light.color(viz.WHITE)
sky_light.ambient([0.9,0.9,1])

#Add the gallery model
gallery = viz.addChild('gallery.osgb')

#Add audio
music = viz.addAudio('bach_air.mid',loop=1)
music.loop(viz.ON)
music.play()

#Add an avatar
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,1])
avatar.state(1)

#Create static drop shadow to avatar
shadow_texture = viz.addTexture('shadow.png')
shadow = vizshape.addQuad(parent=avatar,axis=vizshape.AXIS_Y)
shadow.texture(shadow_texture)
shadow.zoffset()

#Move avatar around the room with a sequence of walk, turn, and wait actions

#Create action to wait 5-10 seconds
RandomWait = vizact.waittime(vizact.randfloat(5,10))

#A list of painting locations
avatarMove = [[-3.7,2.2,300],[-3.7,6.5,270],[0,8,0],[3.7,6.5,90],[3.7,2.6,90],[3.7,1,130]]
actions = []
for loc in avatarMove:
	#Add an action to walk to the next painting, turn towards it, and wait a few seconds
	actions.append(vizact.method.playsound('footsteps.wav',viz.LOOP))
	actions.append(vizact.walkTo([loc[0],0,loc[1]],turnSpeed=250.0))
	actions.append(vizact.method.playsound('footsteps.wav',viz.STOP))
	actions.append(vizact.turn(loc[2],250.0))
	actions.append(RandomWait)

#Repeat the sequence of actions forever
avatar.addAction(vizact.sequence(actions,viz.FOREVER))
DESKTOP_MODE = True
canvas = viz.addGUICanvas()
canvas.alignment(viz.ALIGN_CENTER)
canvas.setPosition([0,-1,0])
canvas.setRenderWorldOverlay([800, 600], fov=40.0, distance=3.0)
canvasUpscale = [500, 500, 500]
arrow = vizshape.addArrow(color=viz.GREEN,parent=canvas)
arrow.setScale(200,200,200)
link = viz.link(gallery, arrow, mask=viz.LINK_ORI)
link.postMultInverseLinkable(viz.MainView)

def updateArrow():
	arrow.lookAt(avatar.getPosition())
	
vizact.ontimer(0,updateArrow)
Reply With Quote
Reply

Tags
compass, coordinate system, mainview, orientation

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
Problem with object position Ryvan Vizard 2 01-22-2015 01:01 PM
Object + InteriaCube + Viewport problem Gekitatsu Vizard 1 02-22-2012 10:55 AM
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
Freeform view on an animated object problem jaylocco Vizard 2 06-08-2009 08:09 PM
Object rotating around world axis, not own axis tacbob Vizard 1 02-15-2007 09:12 AM


All times are GMT -7. The time now is 05:31 AM.


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