PDA

View Full Version : 3dcompass


brunomartelli
07-22-2013, 12:10 PM
Hi im trying to make a 3d compass like a flat disc that sits on the ground and rotates in place.

so far i am doing this:


compass = viz.addChild('arrow.osgb')
compass.color( 0.2,0.8,0.8 )
###########################################
# get the main viewpoint and link a compass to it
view = viz.MainView

#link compass pos to viewpoint
compasslink = viz.link(view, compass)


pitch, roll, yaw = view.getEuler()


compasslink.setEuler([0,0,-yaw])

#offset compass origion before linking to view
compasslink.preTrans([0, -0.5, 0])

this rotates fine, opposite to the view rotate. However if I pitch up the view LMB+RMB the compass doesn't rotate up with the view.
so i figure that i can set the -pitch to rotate it opposite.

compasslink.setEuler([-pitch,0,-yaw])

However That does nothing. I know there is HEAD_ori etc but that does nothing too. Any ideas???? im really stuck....

Jeff
07-23-2013, 03:22 PM
If you want the compass to rotate with the viewpoint you can create a link and set the mask to orientation only. If you want the compass yaw to be the opposite of the viewpoint use the link.swapEuler command:
import viz
import vizshape
viz.go()

viz.add('dojo.osgb')

compass = vizshape.addArrow()
compass.setPosition([0,0.5,0])
compassLink = viz.link(viz.MainView,compass,mask=viz.LINK_ORI)

#Negate yaw value
#compassLink.swapEuler([-1,2,3])

subWindow = viz.addWindow(pos=[0.5,1])
subWindow.setSize(0.5,0.5)
view = viz.addView()
view.move([0,-1,-4])
subWindow.setView(view)