Exemplo n.º 1
0
    def lisenToKeyboard(self):

        for ls in self.dict.itervalues():
           for jEObj in ls:
                if jEObj.key:
                    vizactEObj = vizact.whilekeydown(jEObj.key,self.sendJEvent,self.jEHandler.getEventID("JASON_KEYDOWN_EVENT")
                                                    ,jEObj)
                    self.listForVizact.append(vizactEObj)
        #if we hit spacebar the programm stops reakting to keyboadevents
        unLisen = vizact.onkeydown(" ", self.unLisenToKeyboard)
        self.listForVizact.append(unLisen)
Exemplo n.º 2
0
cam.setInheritView(False)
cam.setPosition([-10.94835, 11.09378, 13.61334])
cam.setRenderTexture(video)
cam.setMultiSample(viz.AUTO_COMPUTE)
cam.setRenderLimit(viz.RENDER_LIMIT_FRAME)

# Get handle to screen object and apply video feed to it
screen = model.getChild('screen')
screen.texture(video)
cam.renderOnlyIfNodeVisible([screen])

# Use up/down keys to zoom camera in/out
def CameraZoom(inc):
    cam.fov = viz.clamp(cam.fov+inc,5.0,70.0)
    cam.setFov(cam.fov,1.77,0.1,1000)
vizact.whilekeydown(viz.KEY_UP,CameraZoom,vizact.elapsed(-20.0))
vizact.whilekeydown(viz.KEY_DOWN,CameraZoom,vizact.elapsed(20.0))
CameraZoom(0.0)

# Have camera always point towards view position
def UpdateCamera():
    cam.lookAt(viz.MainView.getPosition())
vizact.ontimer(0,UpdateCamera)

# Add avatar to represent viewpoint
avatar = steve.Steve()
avatar.setTracker(viz.MainView)
avatar.disable(viz.INTERSECTION)

# Only render avatar for camera
avatar.renderOnlyToRenderNodes([cam],excludeMainPass=True)
Exemplo n.º 3
0
    if gear > -1:
        gear -= 1


def SwapAuto():
    global auto
    global gear
    global speed
    global steer

    if auto == 1:
        auto = 0
    else:
        auto = 1

    gear = 0
    speed = 0
    steer = 0


#vizact.onkeydown('[', ChangeCar, 1)
#vizact.onkeydown(']', ChangeCar, 2)
vizact.ontimer(0.1, CarUpdate)
vizact.whilekeydown(viz.KEY_UP, Accelerate)
vizact.whilekeydown(' ', Brake)
vizact.whilekeydown(viz.KEY_LEFT, SteerLeft)
vizact.whilekeydown(viz.KEY_RIGHT, SteerRight)
vizact.whilekeydown(viz.KEY_DOWN, Reverse)
vizact.onkeydown('z', GearDown)
vizact.onkeydown('x', GearUp)
vizact.onkeydown('g', SwapAuto)
Exemplo n.º 4
0
	def initCamera(self):
				
		self.pointer.setParent(self.camcenter)
	
		#Default camera keys
		vizact.whilekeydown(viz.KEY_RIGHT,self.camlink.setEuler,[vizact.elapsed(-90),0,0],viz.REL_GLOBAL)
		vizact.whilekeydown(viz.KEY_LEFT,self.camlink.setEuler,[vizact.elapsed(90),0,0],viz.REL_GLOBAL)
		vizact.whilekeydown(viz.KEY_UP,self.camlink.setEuler,[0,vizact.elapsed(90),0],viz.REL_LOCAL)
		vizact.whilekeydown(viz.KEY_DOWN,self.camlink.setEuler,[0,vizact.elapsed(-90),0],viz.REL_LOCAL)
		vizact.whilekeydown(viz.KEY_KP_0, camlink.preTrans,[0,0,vizact.elapsed(-4)])
		vizact.whilekeydown(viz.KEY_CONTROL_R, camlink.preTrans,[0,0,vizact.elapsed(4)])		
Exemplo n.º 5
0
def pointerInput(mode, pointer, arena):
	viz.phys.enable()
	"""
	Initialize the pointer tool
	
	Mode selection:
		0 - Keyboard driven
		1 - Spacemouse (WARNING: potential conflict with camera mode 1)
	"""
	
	proxy = vizproximity.Manager()
	proxy.setDebug(viz.TOGGLE)
	
#	theSensor = vizproximity.addBoundingBoxSensor(arena, scale = [0.95, 0.95, 0.95])
	theTarget = vizproximity.Target(pointer)
	
#	proxy.addSensor(theSensor)
	proxy.addTarget(theTarget)
		
	vizact.onkeydown('l',pointer.setPosition,[0,1,0])
	vizact.onkeydown('l',pointer.setVelocity,[0,0,0])	
	vizact.onkeydown('l',pointer.setAngularVelocity,[0,0,0])
	
	if mode == 0:
		# Keyboard driven pointer, in case you don't have a space mouse
		# wx/da/ez control
		
		#For keyboard controls the glove is only linked via orientation
		#linking via position was causing issues with the camera focusing feature
		#fixedRotation = viz.link(viz.MainView,pointer)
		#fixedRotation.setMask(viz.LINK_ORI)
		
		speed = 3.0
		vizact.whilekeydown('w',pointer.setPosition,[0,vizact.elapsed(speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('x',pointer.setPosition,[0,vizact.elapsed(-speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('d',pointer.setPosition,[vizact.elapsed(speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('a',pointer.setPosition,[vizact.elapsed(-speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('e',pointer.setPosition,[0,0,vizact.elapsed(speed)],viz.REL_LOCAL)
		vizact.whilekeydown('z',pointer.setPosition,[0,0,vizact.elapsed(-speed)],viz.REL_LOCAL)
		
	elif mode == 1:
		# Set up pointer control with the Spacemouse
		connexion = viz.add('3dconnexion.dle')
		device = connexion.addDevice()		

		def buttonPress(e):
			pointer.setPosition([0,1,0])
			pointer.setVelocity([0,0,0])
			pointer.setAngularVelocity([0,0,0])
			
		viz.callback(viz.SENSOR_DOWN_EVENT,buttonPress)
		
		#call this every loop
		#all of this should likely go in controls, we need to fix controls!! -ADE
		def getCoords(source, destination, log = False):
			"""
			source should be a 3D connection device, and 
			the destination should be a 3d node type
			"""
			while True:
				yield viztask.waitTime( .01 ) 
				position	= source.getRawTranslation()
				orientation	= source.getRawRotation()
				
				#sets the velocity of the glove (destination) to zero 
				destination.setVelocity([0,0,0], viz.ABS_GLOBAL)
				destination.setAngularVelocity([0,0,0] ,viz.ABS_GLOBAL)
				
				#if selected do log scale on orientation
				if log:
					config.SMEulerScale= [0.5, 0.5 , 0.5]
					orientation = logScale(orientation)

				#rescale position
				position	= list(numpy.multiply(position,config.SMPositionScale))
				orientation	= list(numpy.multiply(orientation,config.SMEulerScale))
				
				#invert signs of x and z 
				x,y,z = position
				
				#invert signs of x and z rotations, and exchange b and a
				a,b,g		= orientation
				orientation	= [b,a,g]
				
				destination.setPosition(position, viz.REL_PARENT)
				destination.setEuler(orientation, viz.REL_PARENT)

		#schedule controller loop with viztask scheduler
		viztask.schedule(getCoords(device, pointer))
		
		return device
		
	else:
		raise ValueError('Invaid control mode selection')	
Exemplo n.º 6
0
	def initPointer(self):
		if self.controlScheme == "default":
			vizact.whilekeydown('w',self.pointer.setPosition,[0,vizact.elapsed(1),0],viz.REL_PARENT)
			vizact.whilekeydown('x',self.pointer.setPosition,[0,vizact.elapsed(-1),0],viz.REL_PARENT)
			vizact.whilekeydown('d',self.pointer.setPosition,[vizact.elapsed(1),0,0],viz.REL_PARENT)
			vizact.whilekeydown('a',self.pointer.setPosition,[vizact.elapsed(-1),0,0],viz.REL_PARENT)
			vizact.whilekeydown('e',self.pointer.setPosition,[0,0,vizact.elapsed(1)],viz.REL_PARENT)
			vizact.whilekeydown('z',self.pointer.setPosition,[0,0,vizact.elapsed(-1)],viz.REL_PARENT)
		elif self.controlScheme == "3dMouse":
			self.init3dMouse()
Exemplo n.º 7
0
    def initCamera(self):

        self.pointer.setParent(self.camcenter)

        #Default camera keys
        vizact.whilekeydown(viz.KEY_RIGHT, self.camlink.setEuler,
                            [vizact.elapsed(-90), 0, 0], viz.REL_GLOBAL)
        vizact.whilekeydown(viz.KEY_LEFT, self.camlink.setEuler,
                            [vizact.elapsed(90), 0, 0], viz.REL_GLOBAL)
        vizact.whilekeydown(viz.KEY_UP, self.camlink.setEuler,
                            [0, vizact.elapsed(90), 0], viz.REL_LOCAL)
        vizact.whilekeydown(viz.KEY_DOWN, self.camlink.setEuler,
                            [0, vizact.elapsed(-90), 0], viz.REL_LOCAL)
        vizact.whilekeydown(viz.KEY_KP_0, camlink.preTrans,
                            [0, 0, vizact.elapsed(-4)])
        vizact.whilekeydown(viz.KEY_CONTROL_R, camlink.preTrans,
                            [0, 0, vizact.elapsed(4)])
Exemplo n.º 8
0
	def cameraInput(self):
		"""
		Initialize the camera movement controls
	
		Mode selection:
			0 - Arrow keys circular movement
			1 - Spacemouse (WARNING: potential conflict with pointer mode 1)
			2 - Wiimote (Not implemented)
		"""
		if self.camMode == 0:
			# Use the arrow keys to move
			self.camcenter = viz.addChild('ball.wrl')
			self.camcenter.setPosition(0,1.4,0)
			self.pointer.setParent(self.camcenter)
			self.camcenter.disable(viz.RENDERING)
		
	#		#occulus Rift enabled
			if(self.displayMode == 2):
				self.hmd = oculus.Rift()
				navigationNode = viz.addGroup()
				viewlink = viz.link(navigationNode, viz.MainView)
				viewlink.preMultLinkable(self.hmd.getSensor())
				camlink = viz.link(self.camcenter,navigationNode)
				
				#set initial positions
				camlink.preEuler([0,0,0])
				camlink.preTrans([0,0,-3.25])
				

			#2D display
			else:
				camlink = viz.link(self.camcenter,viz.MainView)
			
#				#set initial positions
				camlink.preEuler([0,30,0])
#				camlink.preTrans([0,0,0])
				
				self.camcenter.setPosition(0,3.2,-3.5)
				

			
			#instantiate control class
			controlScheme = CameraKeyboardControl()
			
			#schedule the control loop to be called
#			viztask.schedule(controlScheme.performKeyMovements(self.camcenter, camlink))
#			viztask.schedule(controlScheme.cameraFocus(self.camcenter, camlink))		
			
			#backup control functions:
			vizact.whilekeydown(viz.KEY_RIGHT,self.camcenter.setEuler,[vizact.elapsed(90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_LEFT,self.camcenter.setEuler,[vizact.elapsed(-90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_UP,self.camcenter.setEuler,[0,vizact.elapsed(-90),0],viz.REL_LOCAL)
			vizact.whilekeydown(viz.KEY_DOWN,self.camcenter.setEuler,[0,vizact.elapsed(90),0],viz.REL_LOCAL)
			vizact.whilekeydown( 't' , self.camcenter.setPosition,[0,0,vizact.elapsed(4)],viz.REL_LOCAL)
			vizact.whilekeydown( 'g' ,  self.camcenter.setPosition,[0,0,vizact.elapsed(-4)],viz.REL_LOCAL)
		
		
			default = self.camcenter.getPosition()


		elif self.camMode == 1:
			# Use the SpaceMouse to move camera
			MOVE_SCALE = 0.5
			ROTATE_SCALE = 5.0
			
			def UpdateMovement():
				elapsed = viz.getFrameElapsed()
				trans = device.getRawTranslation()
				rx,ry,rz = device.getRawRotation()
				viz.MainView.setAxisAngle([0,1,0,ry*elapsed*ROTATE_SCALE], viz.HEAD_ORI, viz.REL_LOCAL)
				viz.MainView.move(viz.Vector(trans)*elapsed*MOVE_SCALE)
			
			vizact.onupdate(0, UpdateMovement)

	#	elif mode == 2:
	#		# wiimote
	#		pass

		else:
			raise ValueError('Invaid control mode selection')
ballDropper.setPosition( [0, 1.9, .2] )
ballDropper.setScale( [.2, .2, .2] )
ballDropper.setEuler( [180, 0, 0] )
ballDropper.state( 1 )

#Drop ball when spacebar is pressed
def dropBall():
	ball = nextBall.next() #get the next ball to drop
	ball.reset() #zero out physics forces
	ball.setPosition( ballDropper.getPosition() ) #drop ball at ballDropper's position
	ballDropper.execute( 2 )

vizact.onkeydown(' ',dropBall)

#Move ballDropper
vizact.whilekeydown(viz.KEY_UP,ballDropper.setPosition,[0,vizact.elapsed(1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_DOWN,ballDropper.setPosition,[0,vizact.elapsed(-1),0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_RIGHT,ballDropper.setPosition,[vizact.elapsed(1),0,0],viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_LEFT,ballDropper.setPosition,[vizact.elapsed(-1),0,0],viz.REL_PARENT)

#Called when two objects collide in the physics simulator
def onCollide(e):
	#Did ball collide with a bumper?
	if e.obj2 in balls:
		#Change color of bumper
		e.obj1.color( random.choice( [viz.RED,viz.GREEN,viz.SKYBLUE,viz.YELLOW,viz.ORANGE,viz.PURPLE] ) )
		#Play sound at a volume appropriate for ball speed
		speed = viz.Vector( e.obj2.getVelocity() ).length()
		if speed > .7:
			viz.playSound( 'crashNew.wav' )
		elif speed > .4:
Exemplo n.º 10
0
 def initPointer(self):
     if self.controlScheme == "default":
         vizact.whilekeydown('w', self.pointer.setPosition,
                             [0, vizact.elapsed(1), 0], viz.REL_PARENT)
         vizact.whilekeydown('x', self.pointer.setPosition,
                             [0, vizact.elapsed(-1), 0], viz.REL_PARENT)
         vizact.whilekeydown('d', self.pointer.setPosition,
                             [vizact.elapsed(1), 0, 0], viz.REL_PARENT)
         vizact.whilekeydown('a', self.pointer.setPosition,
                             [vizact.elapsed(-1), 0, 0], viz.REL_PARENT)
         vizact.whilekeydown('e', self.pointer.setPosition,
                             [0, 0, vizact.elapsed(1)], viz.REL_PARENT)
         vizact.whilekeydown('z', self.pointer.setPosition,
                             [0, 0, vizact.elapsed(-1)], viz.REL_PARENT)
     elif self.controlScheme == "3dMouse":
         self.init3dMouse()
Exemplo n.º 11
0
def pointerInput(mode, pointer, arena):
    viz.phys.enable()
    """
	Initialize the pointer tool
	
	Mode selection:
		0 - Keyboard driven
		1 - Spacemouse (WARNING: potential conflict with camera mode 1)
	"""

    proxy = vizproximity.Manager()
    proxy.setDebug(viz.TOGGLE)
    theSensor = vizproximity.addBoundingBoxSensor(arena, scale=[.95, .95, .95])
    theTarget = vizproximity.Target(pointer)

    proxy.addSensor(theSensor)
    proxy.addTarget(theTarget)

    def EnterProximity(e):
        #print('Hit the wall')
        pointer.setVelocity([0, 0, 0])
        pointer.setAngularVelocity([0, 0, 0])
        print(e.target.getPosition())
        temp = e.target.getPosition()
        #pointer.setPosition([1,1,1])

    def ExitProximity(e):
        #print('Hit the wall')
        x, y, z = pointer.getPosition()

        if (y < .4):
            y = .5
        elif (y > 4.5):
            y = 4.4
        if (abs(x) > abs(z) and abs(x) > 5):
            if (x < 0):
                x = -4.9
            else:
                x = 4.9
        elif (abs(z) > 4):
            if (z < 0):
                z = -3.9
            elif (z > 0):
                z = 3.9
        pointer.setPosition(x, y, z)
        pointer.setVelocity([0, 0, 0])
        pointer.setAngularVelocity([0, 0, 0])

    proxy.onEnter(None, EnterProximity)
    proxy.onExit(None, ExitProximity)

    vizact.onkeydown('l', pointer.setPosition, [0, 1, 0])
    vizact.onkeydown('l', pointer.setVelocity, [0, 0, 0])
    vizact.onkeydown('l', pointer.setAngularVelocity, [0, 0, 0])

    if mode == 0:
        # Keyboard driven pointer, in case you don't have a space mouse
        # wx/da/ez control

        #For keyboard controls the glove is only linked via orientation
        #linking via position was causing issues with the camera focusing feature
        #fixedRotation = viz.link(viz.MainView,pointer)
        #fixedRotation.setMask(viz.LINK_ORI)

        speed = 3.0
        vizact.whilekeydown('w', pointer.setPosition,
                            [0, vizact.elapsed(speed), 0], viz.REL_LOCAL)
        vizact.whilekeydown('x', pointer.setPosition,
                            [0, vizact.elapsed(-speed), 0], viz.REL_LOCAL)
        vizact.whilekeydown('d', pointer.setPosition,
                            [vizact.elapsed(speed), 0, 0], viz.REL_LOCAL)
        vizact.whilekeydown('a', pointer.setPosition,
                            [vizact.elapsed(-speed), 0, 0], viz.REL_LOCAL)
        vizact.whilekeydown('e', pointer.setPosition,
                            [0, 0, vizact.elapsed(speed)], viz.REL_LOCAL)
        vizact.whilekeydown('z', pointer.setPosition,
                            [0, 0, vizact.elapsed(-speed)], viz.REL_LOCAL)

    elif mode == 1:
        # Set up pointer control with the Spacemouse
        connexion = viz.add('3dconnexion.dle')
        device = connexion.addDevice()

        def buttonPress(e):
            pointer.setPosition([0, 1, 0])
            pointer.setVelocity([0, 0, 0])
            pointer.setAngularVelocity([0, 0, 0])

        viz.callback(viz.SENSOR_DOWN_EVENT, buttonPress)

        #device.setTranslateScale([1,1,1])
        #device.setRotateScale([0,0,0]) # i don't think we need this

        #add 3Dnode object that follows mainview exactly, called MainViewShadow
        #		MainViewShadow = vizshape.addSphere(radius = .5)
        #		MainViewShadow.disable(viz.RENDERING)
        #		viz.link(viz.MainView, MainViewShadow)

        #make glove () child of MainViewShadow

        #fixedRotation = viz.link(MainViewShadow,pointer)
        #fixedRotation.setMask(viz.LINK_ORI)
        #pointer.setParent(MainViewShadow)

        #call this every loop
        #all of this should likely go in controls, we need to fix controls!! -ADE
        def getCoords(source, destination):
            """
			source should be a 3D connection device, and 
			the destination should be a 3d node type
			"""
            def logScale(orientation):
                """ 
				list or len() = 3 -> list of len 3 
				takes the orintation list and returns the log of
				the magnitude of each element , and then keeps the 
				original sign
				
				ex) [ 10 , -10 ,1000] -> [1 , -1, 3]
				
				"""
                import math
                base = 2
                mag_orientation = []
                sign = []  #list of signs

                #make all elements positive, store original signs
                for element in orientation:
                    if math.fabs(element) == element:
                        #element is positive
                        mag_orientation.append(element)
                        sign.append(1)
                    else:
                        #element is negative
                        mag_orientation.append(-1 * element)
                        sign.append(-1)
                #handle case where number is zero, and set to 1
                n = 0
                for element in mag_orientation:
                    if element == 0:
                        mag_orientation[n] = 1
                    n += 1

                #take log of each element
                log_orientation = []
                for element in mag_orientation:
                    log = math.log(element, base)
                    log_orientation.append(log)

                #restablish original signs
                orientation = scalarMult(sign, log_orientation)
                return orientation

            #set source scale


#			scale1 = [.0001,.0001,.0001]
#			scale2 =[.01,.01,.01]

#log
            log = False

            while True:
                yield viztask.waitTime(.01)
                position = source.getRawTranslation()
                orientation = source.getRawRotation()

                #sets the velocity of the glove (destination) to zero
                destination.setVelocity([0, 0, 0], viz.ABS_GLOBAL)
                destination.setAngularVelocity([0, 0, 0], viz.ABS_GLOBAL)

                #if selected do log scale on orientation
                if log == True:
                    config.orientationVector = [.5, .5, .5]
                    orientation = logScale(orientation)

                #rescale position
                position = scalarMult(position, config.positionVector)
                orientation = scalarMult(orientation, config.orientationVector)

                #invert signs of x and z
                x, y, z = position

                #invert signs of x and z rotations, and exchange b and a
                a, b, g = orientation
                orientation = [b, a, g]

                #print(orientation)
                destination.setPosition(position, viz.REL_PARENT)
                destination.setEuler(orientation, viz.REL_PARENT)

        def scalarMult(lst1, lst2):
            """ 
			takes 2 lists, and returns the scalar 
			multiplication of the lists
			*lists must be the same length
			"""
            new_lst = []
            for i in range(len(lst1)):
                n_val = lst1[i] * lst2[i]
                new_lst.append(n_val)

            return new_lst

        #schedule controller loop with viztask scheduler
        viztask.schedule(getCoords(device, pointer))

        #vizact.ontimer2(.01,1, delayedSet )

        #viz.link(device, pointer, viz.REL_PARENT)
        #link.preEuler([0,90,0])

        return device

    else:
        raise ValueError('Invaid control mode selection')

    #question guys. if keyboard is selected, should  the init script call code
    #in the control module to set the functions? - Alex
Exemplo n.º 12
0
def pointerInput(mode, pointer,arena):
	viz.phys.enable()
	"""
	Initialize the pointer tool
	
	Mode selection:
		0 - Keyboard driven
		1 - Spacemouse (WARNING: potential conflict with camera mode 1)
	"""
	
	proxy = vizproximity.Manager()
	proxy.setDebug(viz.TOGGLE)
	theSensor = vizproximity.addBoundingBoxSensor(arena,scale=[.95,.95,.95])
	theTarget = vizproximity.Target(pointer)
	
	proxy.addSensor(theSensor)
	proxy.addTarget(theTarget)

	
	def EnterProximity(e):
		#print('Hit the wall')
		pointer.setVelocity([0,0,0])
		pointer.setAngularVelocity([0,0,0])
		print(e.target.getPosition())
		temp = e.target.getPosition()
		#pointer.setPosition([1,1,1])
	
	def ExitProximity(e):
		#print('Hit the wall')
		x,y,z = pointer.getPosition()
		
		if(y < .4):
			y = .5
		elif(y > 4.5 ):
			y = 4.4
		if(abs(x) > abs(z) and abs(x) > 5):
			if(x<0):
				x = -4.9
			else:
				x = 4.9
		elif(abs(z) > 4):
			if(z<0):
				z = -3.9
			elif(z>0):
				z = 3.9
		pointer.setPosition(x,y,z)
		pointer.setVelocity([0,0,0])
		pointer.setAngularVelocity([0,0,0])
	
	proxy.onEnter(None,EnterProximity)
	proxy.onExit(None,ExitProximity)	
		
	vizact.onkeydown('l',pointer.setPosition,[0,1,0])
	vizact.onkeydown('l',pointer.setVelocity,[0,0,0])	
	vizact.onkeydown('l',pointer.setAngularVelocity,[0,0,0])

	
	if mode == 0:
		# Keyboard driven pointer, in case you don't have a space mouse
		# wx/da/ez control
		
		#For keyboard controls the glove is only linked via orientation
		#linking via position was causing issues with the camera focusing feature
		#fixedRotation = viz.link(viz.MainView,pointer)
		#fixedRotation.setMask(viz.LINK_ORI)
		
		speed = 3.0
		vizact.whilekeydown('w',pointer.setPosition,[0,vizact.elapsed(speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('x',pointer.setPosition,[0,vizact.elapsed(-speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('d',pointer.setPosition,[vizact.elapsed(speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('a',pointer.setPosition,[vizact.elapsed(-speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('e',pointer.setPosition,[0,0,vizact.elapsed(speed)],viz.REL_LOCAL)
		vizact.whilekeydown('z',pointer.setPosition,[0,0,vizact.elapsed(-speed)],viz.REL_LOCAL)
		
		
	elif mode == 1:
		# Set up pointer control with the Spacemouse
		connexion = viz.add('3dconnexion.dle')
		device = connexion.addDevice()		

		def buttonPress(e):
			pointer.setPosition([0,1,0])
			pointer.setVelocity([0,0,0])
			pointer.setAngularVelocity([0,0,0])
			
		viz.callback(viz.SENSOR_DOWN_EVENT,buttonPress)
		
		#device.setTranslateScale([1,1,1])
		#device.setRotateScale([0,0,0]) # i don't think we need this
		
		#add 3Dnode object that follows mainview exactly, called MainViewShadow
#		MainViewShadow = vizshape.addSphere(radius = .5)
#		MainViewShadow.disable(viz.RENDERING)
#		viz.link(viz.MainView, MainViewShadow)
		
		#make glove () child of MainViewShadow
		
		#fixedRotation = viz.link(MainViewShadow,pointer)
		#fixedRotation.setMask(viz.LINK_ORI)
		#pointer.setParent(MainViewShadow)
		
		#call this every loop
		#all of this should likely go in controls, we need to fix controls!! -ADE
		def getCoords(source, destination):
			"""
			source should be a 3D connection device, and 
			the destination should be a 3d node type
			"""
			def logScale(orientation):
				""" 
				list or len() = 3 -> list of len 3 
				takes the orintation list and returns the log of
				the magnitude of each element , and then keeps the 
				original sign
				
				ex) [ 10 , -10 ,1000] -> [1 , -1, 3]
				
				"""
				import math
				base = 2
				mag_orientation = []
				sign = [] #list of signs
				
				#make all elements positive, store original signs
				for element in orientation:
					if math.fabs(element) == element:
						#element is positive
						mag_orientation.append(element)
						sign.append(1)
					else:
						#element is negative
						mag_orientation.append(-1*element)
						sign.append(-1)
				#handle case where number is zero, and set to 1
				n = 0
				for element in mag_orientation:
					if element == 0:
						mag_orientation[n] = 1
					n+=1
				
				#take log of each element
				log_orientation=[]
				for element in mag_orientation:
					log = math.log(element, base)
					log_orientation.append(log)
				
				#restablish original signs
				orientation = scalarMult(sign, log_orientation)
				return orientation
			
			#set source scale
#			scale1 = [.0001,.0001,.0001]
#			scale2 =[.01,.01,.01]
			
			#log
			log = False
			
			while True:
				yield viztask.waitTime( .01 ) 
				position = source.getRawTranslation()
				orientation = source.getRawRotation()
				
				#sets the velocity of the glove (destination) to zero 
				destination.setVelocity([0,0,0], viz.ABS_GLOBAL)
				destination.setAngularVelocity([0,0,0] ,viz.ABS_GLOBAL)
				
				#if selected do log scale on orientation
				if log == True:
					config.orientationVector= [.5, .5 , .5]
					orientation = logScale(orientation)
	
				#rescale position
				position = scalarMult(position,config.positionVector)
				orientation = scalarMult(orientation,config.orientationVector)
				
				#invert signs of x and z 
				x,y,z = position
				
				#invert signs of x and z rotations, and exchange b and a
				a,b,g = orientation
				orientation = [b,a,g]
				
				
				#print(orientation)
				destination.setPosition(position, viz.REL_PARENT)
				destination.setEuler(orientation, viz.REL_PARENT)
		
		def scalarMult(lst1,lst2):
			""" 
			takes 2 lists, and returns the scalar 
			multiplication of the lists
			*lists must be the same length
			"""
			new_lst = []
			for i in range(len(lst1)):
				n_val = lst1[i]*lst2[i]
				new_lst.append(n_val)
				
			return new_lst

		#schedule controller loop with viztask scheduler
		viztask.schedule( getCoords(device,pointer))

		#vizact.ontimer2(.01,1, delayedSet ) 

		#viz.link(device, pointer, viz.REL_PARENT)
		#link.preEuler([0,90,0])
		
		return device
		
	else:
		raise ValueError('Invaid control mode selection')
		
	#question guys. if keyboard is selected, should  the init script call code 
	#in the control module to set the functions? - Alex
Exemplo n.º 13
0
	def cameraInput(self):
		"""
		Initialize the camera movement controls
	
		Mode selection:
			0 - Arrow keys circular movement
			1 - Spacemouse (WARNING: potential conflict with pointer mode 1)
			2 - Wiimote (Not implemented)
		"""
		if self.camMode == 0:
			# Use the arrow keys to move
			self.camcenter = viz.addChild('ball.wrl')
			self.camcenter.setPosition(0,1.4,0)
			self.pointer.setParent(self.camcenter)
			self.camcenter.disable(viz.RENDERING)
		
	#		#occulus Rift enabled
			if(self.displayMode == 2):
				self.hmd = oculus.Rift()
				navigationNode = viz.addGroup()
				viewlink = viz.link(navigationNode, viz.MainView)
				viewlink.preMultLinkable(self.hmd.getSensor())
				camlink = viz.link(self.camcenter,navigationNode)
				
				#set initial positions
				camlink.preEuler([0,0,0])
				camlink.preTrans([0,0,-3.25])
				

			#2D display
			else:
				camlink = viz.link(self.camcenter,viz.MainView)
			
				#set initial positions
				camlink.preEuler([0,30,0])
				camlink.preTrans([0,0,-5])

			
			#instantiate control class
			controlScheme = CameraKeyboardControl()
			
			#schedule the control loop to be called
			viztask.schedule(controlScheme.performKeyMovements(self.camcenter, camlink))
			viztask.schedule(controlScheme.cameraFocus(self.camcenter, camlink))		
			
			#backup control functions:
			vizact.whilekeydown(viz.KEY_RIGHT,self.camcenter.setEuler,[vizact.elapsed(-90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_LEFT,self.camcenter.setEuler,[vizact.elapsed(90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_UP,self.camcenter.setEuler,[0,vizact.elapsed(90),0],viz.REL_LOCAL)
			vizact.whilekeydown(viz.KEY_DOWN,self.camcenter.setEuler,[0,vizact.elapsed(-90),0],viz.REL_LOCAL)
			vizact.whilekeydown( 't' , camlink.preTrans,[0,0,vizact.elapsed(-4)])
			vizact.whilekeydown( 'g' ,  camlink.preTrans,[0,0,vizact.elapsed(4)])
		
		
			default = self.camcenter.getPosition()


		elif self.camMode == 1:
			# Use the SpaceMouse to move camera
			MOVE_SCALE = 0.5
			ROTATE_SCALE = 5.0
			
			def UpdateMovement():
				elapsed = viz.getFrameElapsed()
				trans = device.getRawTranslation()
				rx,ry,rz = device.getRawRotation()
				viz.MainView.setAxisAngle([0,1,0,ry*elapsed*ROTATE_SCALE], viz.HEAD_ORI, viz.REL_LOCAL)
				viz.MainView.move(viz.Vector(trans)*elapsed*MOVE_SCALE)
			
			vizact.onupdate(0, UpdateMovement)

	#	elif mode == 2:
	#		# wiimote
	#		pass

		else:
			raise ValueError('Invaid control mode selection')
Exemplo n.º 14
0
def pointerInput(mode, pointer, arena):
	viz.phys.enable()
	"""
	Initialize the pointer tool
	
	Mode selection:
		0 - Keyboard driven
		1 - Spacemouse (WARNING: potential conflict with camera mode 1)
	"""
	
	proxy = vizproximity.Manager()
	proxy.setDebug(viz.TOGGLE)
	
#	theSensor = vizproximity.addBoundingBoxSensor(arena, scale = [0.95, 0.95, 0.95])
	theTarget = vizproximity.Target(pointer)
	
#	proxy.addSensor(theSensor)
	proxy.addTarget(theTarget)
		
	vizact.onkeydown('l',pointer.setPosition,[0,1,0])
	vizact.onkeydown('l',pointer.setVelocity,[0,0,0])	
	vizact.onkeydown('l',pointer.setAngularVelocity,[0,0,0])
	
	if mode == 0:
		# Keyboard driven pointer, in case you don't have a space mouse
		# wx/da/ez control
		
		#For keyboard controls the glove is only linked via orientation
		#linking via position was causing issues with the camera focusing feature
		#fixedRotation = viz.link(viz.MainView,pointer)
		#fixedRotation.setMask(viz.LINK_ORI)
		
		speed = 3.0
		vizact.whilekeydown('w',pointer.setPosition,[0,vizact.elapsed(speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('x',pointer.setPosition,[0,vizact.elapsed(-speed),0],viz.REL_LOCAL)
		vizact.whilekeydown('d',pointer.setPosition,[vizact.elapsed(speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('a',pointer.setPosition,[vizact.elapsed(-speed),0,0],viz.REL_LOCAL)
		vizact.whilekeydown('e',pointer.setPosition,[0,0,vizact.elapsed(speed)],viz.REL_LOCAL)
		vizact.whilekeydown('z',pointer.setPosition,[0,0,vizact.elapsed(-speed)],viz.REL_LOCAL)
		
	elif mode == 1:
		# Set up pointer control with the Spacemouse
		connexion = viz.add('3dconnexion.dle')
		device = connexion.addDevice()		

		def buttonPress(e):
			pointer.setPosition([0,1,0])
			pointer.setVelocity([0,0,0])
			pointer.setAngularVelocity([0,0,0])
			
		viz.callback(viz.SENSOR_DOWN_EVENT,buttonPress)
		
		#call this every loop
		#all of this should likely go in controls, we need to fix controls!! -ADE
		def getCoords(source, destination, log = False):
			"""
			source should be a 3D connection device, and 
			the destination should be a 3d node type
			"""
			while True:
				yield viztask.waitTime( .01 ) 
				position	= source.getRawTranslation()
				orientation	= source.getRawRotation()
				
				#sets the velocity of the glove (destination) to zero 
				destination.setVelocity([0,0,0], viz.ABS_GLOBAL)
				destination.setAngularVelocity([0,0,0] ,viz.ABS_GLOBAL)
				
				#if selected do log scale on orientation
				if log:
					config.SMEulerScale= [0.5, 0.5 , 0.5]
					orientation = logScale(orientation)

				#rescale position
				position	= list(numpy.multiply(position,config.SMPositionScale))
				orientation	= list(numpy.multiply(orientation,config.SMEulerScale))
				
				#invert signs of x and z 
				x,y,z = position
				
				#invert signs of x and z rotations, and exchange b and a
				a,b,g		= orientation
				orientation	= [b,a,g]
				
				destination.setPosition(position, viz.REL_PARENT)
				destination.setEuler(orientation, viz.REL_PARENT)

		#schedule controller loop with viztask scheduler
		viztask.schedule(getCoords(device, pointer))
		
		return device
		
	else:
		raise ValueError('Invaid control mode selection')	
sky = viz.add('skydome.dlc')
sky.texture(env)

# add room model
SCALE = [0.03, 0.03, 0.03]
room = viz.add("../models/room3/room3.wrl")
room.setScale(SCALE)

# add ground model
ground = viz.add('tut_ground.wrl')
ground.setScale([5,1,5])

# keyboard controls -- for debugging only
TRANSLATE_INC = .2
ROTATION_INC = 2
vizact.whilekeydown(viz.KEY_UP,viz.move,0,0,TRANSLATE_INC) #Move forward while up key is pressed
vizact.whilekeydown(viz.KEY_DOWN,viz.move,0,0,-TRANSLATE_INC) #Move backward while down key is pressed
vizact.whilekeydown(viz.KEY_LEFT,viz.rotate,viz.BODY_ORI,-ROTATION_INC,0,0) #Turn left while left arrow pressed
vizact.whilekeydown(viz.KEY_RIGHT,viz.rotate,viz.BODY_ORI,ROTATION_INC,0,0) #Turn right while right arrow pressed

# HMD constants (for real world view)
HMDfov_vert = 36.
HMDwidth = 640.
HMDheight = 480.
HMDnear = 1
HMDfar = 1000
HMDaspect = HMDwidth/HMDheight

# set up real world view parameters
viz.fov( HMDfov_vert, HMDaspect )
viz.window.setSize( HMDwidth, HMDheight )