示例#1
0
 def driverFunc(self):
     startTime = time.clock()
     while True:
         time.sleep(1.)
         buttonIndex = random.choice(range(8))
         # the send...() and queue...() methods all have the same signature
         # as the arButtonEvent(), arAxisEvent(), arMatrixEvent() constructors:
         # ( event index, event value ).
         self.driver.sendButton(buttonIndex, 1)
         time.sleep(.1)
         self.driver.queueButton(buttonIndex, 0)
         self.driver.queueMatrix(0, szg.ar_translationMatrix(0, 5.5, 0))
         self.driver.queueMatrix(1, szg.ar_translationMatrix(1, 3.5, -1))
         self.driver.sendQueue()
示例#2
0
 def handle_tmatrix( self, index, *args ):
   """'tmatrix' sends a placement matrix event for a specified translation (position).
   usage: tmatrix <index> <3 floats(x,y,z)>"""
   if len(args) != 3:
     raise EventConsoleError
   floats = map( float, args )
   self.driver.sendMatrix( index, szg.ar_translationMatrix( *floats ) )
示例#3
0
  def __init__( self ):
    szg.arIOFilter.__init__( self )

    axisSwap = szg.arMatrix4( 
          1, 0, 0, 0, \
          0, 0,-1, 0, \
          0, 1, 0, 0, \
          0, 0, 0, 1 )
    inverseAxisSwap = szg.arMatrix4( 
          1, 0, 0, 0, \
          0, 0, 1, 0, \
          0,-1, 0, 0, \
          0, 0, 0, 1 )

    headRotMatrix = szg.ar_rotationMatrix( 'z', math.radians(-80.) ) * \
        szg.ar_rotationMatrix( 'y', math.radians( 20. ) )
    wandRotMatrix = szg.ar_rotationMatrix( 'y', math.radians(-90.) ) * \
        szg.ar_rotationMatrix( 'x', math.radians( 180. ) )

    originOffset = szg.ar_translationMatrix( .6, 9.2, -4.5 )

    self.headPreMatrix = originOffset * axisSwap
    self.headPostMatrix = inverseAxisSwap * headRotMatrix

    self.wandPreMatrix = originOffset * axisSwap
    self.wandPostMatrix = inverseAxisSwap * wandRotMatrix
示例#4
0
 def driverFunc(self):
   startTime = time.clock()
   while True:
     time.sleep( .02 )
     angle = math.radians((time.clock()-startTime)*ROTATION_RATE)
     x = RADIUS*math.sin( angle )
     z = RADIUS*(math.cos( angle )-1)
     viewMatrix = szg.ar_translationMatrix(x, 0, z) * szg.ar_rotationMatrix( 'y', angle )
     self.driver.sendMatrix( viewMatrix )
示例#5
0
 def handle_matrix( self, index, *args ):
   """'matrix' sends a placement (translation+rotation) matrix event.
   usage 1: matrix <index> <3 floats(x,y,z)> <char(x,y,or z)> <float(degrees)> or
   usage 2: matrix <index> <3 floats(x,y,z)> <4 floats(xaxis,yaxis,zaxis,degrees)>"""
   if len(args) != 5 and len(args) != 7:
     raise EventConsoleError
   tMatrix = szg.ar_translationMatrix( *map( float, args[:3] ) )
   args = args[3:]
   if len(args) == 2:
     axes = {'x':szg.arVector3(1,0,0), 'y':szg.arVector3(0,1,0), 'z':szg.arVector3(0,0,1) }
     rotAxis = axes[ args[0] ]
     rotAngle = math.radians( float( args[1] ) )
   else:
     floats = map( float, args )
     print floats[:3], '/', floats[-1:]
     rotAxis = szg.arVector3( floats[:3] )
     rotAngle = math.radians( floats[-1] )
   print rotAxis, rotAngle
   self.driver.sendMatrix( index, tMatrix*szg.ar_rotationMatrix( rotAxis, rotAngle ) )
示例#6
0
# device in Python. Drag the mouse around in the GLUT window to send joystick events.
# You would use it by:
# 1) Make sure you have defined SZG_PYTHON/executable for the computer it's on.
# 2) Place it in a directory on your SZG_PYTHON/path (or one level down).
# 3) Add it to a virtual computer input map, e.g.:
#        vcpyin  SZG_INPUT0  map  this_computer/event_console.py
#

import szg
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
import thread

HEAD_MATRIX = szg.ar_translationMatrix(0,5.5,0)
WAND_MATRIX =  szg.ar_translationMatrix(1,3.5,-1)


class JoystickSimulator( szg.arPyDeviceServerFramework ):
  def __init__(self):
    szg.arPyDeviceServerFramework.__init__(self)
    self.axes = [0.,0.]
    self.width = 0
    self.height = 0
    self.running = True

  def configureInputNode(self):
    self.driver = szg.arGenericDriver()
    # signature = # buttons, # axes, # matrices
    self.driver.setSignature( 0,2,2 )