00001 from PyQt4 import QtCore
00002
00003 from ost import gfx, gui
00004
00005 class SpacenavControl(QtCore.QObject):
00006 def __init__(self, spnav,
00007 parent=None):
00008 QtCore.QObject.__init__(self, parent)
00009 QtCore.QObject.connect(spnav,QtCore.SIGNAL("deviceTransformed(int,int,int,int,int,int)"), self.Changed)
00010 QtCore.QObject.connect(spnav,QtCore.SIGNAL("deviceButtonPressed(int)"), self.Toggle)
00011
00012 self.trans = True
00013 self.rot = True
00014
00015 def Changed(self, tx,ty,tz,rx,ry,rz):
00016 transf = gfx.Scene().GetTransform()
00017 if(self.trans):
00018 transf.ApplyXAxisTranslation(tx/480.0)
00019 transf.ApplyYAxisTranslation(ty/480.0)
00020 transf.ApplyZAxisTranslation(-tz/480.0)
00021 if(self.rot):
00022 transf.ApplyXAxisRotation(rx/480.0)
00023 transf.ApplyYAxisRotation(ry/480.0)
00024 transf.ApplyZAxisRotation(rz/480.0)
00025 gfx.Scene().SetTransform(transf)
00026 gfx.Scene().RequestRedraw()
00027
00028 def Toggle(self, button):
00029 if button == 0:
00030 self.trans = not self.trans
00031 print "Translation Enabled:",self.trans
00032 elif button == 1:
00033 self.rot = not self.rot
00034 print "Rotation Enabled:",self.rot
00035
00036 def _InitSpaceNav(app):
00037 try:
00038 spnav = gui.SpnavInput.GetQThread()
00039 spnav.start()
00040 parent = app.gl_win.qobject
00041 SpacenavControl(spnav,parent)
00042 except AttributeError:
00043 pass