Exemplo n.º 1
0
	def load(self, dataset):
		"""
		Load datasets and initialize everything necessary to commence
		the puzzle game.
		"""
		
		# Dataset
		model.ds = bp3d.DatasetInterface()

		# Proximity management
		model.proxManager = vizproximity.Manager()
		target = vizproximity.Target(model.pointer)
		model.proxManager.addTarget(target)

		model.proxManager.onEnter(None, self.EnterProximity)
		model.proxManager.onExit(None, self.ExitProximity)

		#Setup Key Bindings
		self.bindKeys()

		self.score = PuzzleScore(self.modeName)
		
#		viztask.schedule(soundTask(glove))

		self._meshesToLoad = model.ds.getOntologySet(dataset)
		self._filesToPreSnap = model.ds.getPreSnapSet()
		
		yield self.loadControl(self._meshesToLoad)
		yield self.prepareMeshes()
		yield self.preSnap()
		yield self.setKeystone(1)
		
		viztask.schedule(self.updateClosestBone())
Exemplo n.º 2
0
	def load(self, dataset = 'right arm'):
		"""
		Load datasets and initialize everything necessary to commence
		the puzzle game. Customized for test mode.
		"""
		
		# Dataset
		model.ds = model.DatasetInterface()
		
		self._quizPanel = view.TestSnapPanel()
		self._quizPanel.toggle()

		# Proximity management
		model.proxManager = vizproximity.Manager()
		target = vizproximity.Target(model.pointer)
		model.proxManager.addTarget(target)

		model.proxManager.onEnter(None, self.EnterProximity)
		model.proxManager.onExit(None, self.ExitProximity)
	
		#Setup Key Bindings
		self.bindKeys()
		
		# start the clock
		time.clock()

		self.score = PuzzleScore(self.modeName)
		
#		viztask.schedule(soundTask(glove))
		self._meshesToLoad = model.ds.getOntologySet(dataset)
		self.loadMeshes(self._meshesToLoad)

		# Hide all of the meshes
		for m in self._meshes:
			m.disable()
		
		# Randomly select keystone(s)
		rand = random.sample(self._meshes, 3)
		print rand
		self._keystones += rand
		rand[0].enable()
		rand[0].setPosition([0.0,1.5,0.0])
		rand[0].setEuler([0.0,90.0,180.0])
		rand[0].group.grounded = True
		for m in rand[1:]:
			m.enable()
			self.snap(m, rand[0], add = False)
			print 'snapping ', m.name
		
		# Randomly enable some adjacent meshes
		keystone = random.sample(self._keystones, 1)[0]
		self._keystoneAdjacent.update({keystone:[]})
		for m in self.getAdjacent(keystone, self.getDisabled())[:4]:
			print m
			m.enable(animate = False)
		self.pickSnapPair()
Exemplo n.º 3
0
    def __init__(self, path, step, radius, bemobil, trackers):
        """
        Fade a visible grid in and out when subjects move close to a boundary wall and back up subsequently.

        To toggle the visibility of the path proximity sensor, use the 'd' button.

        Args:
            path: path along defined points defining the proximity sensor shape. Should be the bounding room shape.
            step: distance between each line building the grid
            radius: distance to the wall at which the proximity sensor should be triggered
            bemobil: if true, then path area will be fixed to [(3, 6.5), (-3, 6.5), (-3, -6.5), (3, -6.5), (3, 6.5)].
            trackers: tracker objects to make as proximity targets. Can take multiple trackers and adds them
                to the proximity manager.
        """

        self.grids = []

        if bemobil:
            self.path = [(3, 6.5), (-3, 6.5), (-3, -6.5), (3, -6.5), (3, 6.5)]
        else:
            path = [(1, 1), (1, 1), (1, 1), (1, 1), (1, 1)]
            # todo create path through parameters provided to the Chaperone constructor (__init__).

        self.grid1 = self.add_grid([13, 3], [0, 0, 0], [3, 1.5, 0], step)
        self.grids.append(self.grid1)

        self.grid2 = self.add_grid([6, 3], [90, 0, 0], [0, 1.5, 6.5], step)
        self.grids.append(self.grid2)

        self.grid3 = self.add_grid([13, 3], [0, 0, 0], [-3, 1.5, 0], step)
        self.grids.append(self.grid3)

        self.grid4 = self.add_grid([6, 3], [90, 0, 0], [0, 1.5, -6.5], step)
        self.grids.append(self.grid4)

        for grid in self.grids:
            grid.addAction(vizact.fadeTo(0, time=3))
            grid.color(viz.GREEN)

        self.path_sensor = self.add_path_sensor(self.path, radius)

        self.path_manager = vizproximity.Manager()
        self.path_manager.addSensor(self.path_sensor)

        if trackers:
            for tracker in trackers:
                self.path_manager.addTarget(tracker)
        else:
            self.path_manager.addTarget(viz.MainView)

        self.path_manager.setDebug(viz.ON)
        vizact.onkeydown('d', self.path_manager.setDebug, viz.TOGGLE)

        self.path_manager.onEnter(self.path_sensor, self.enter_grid,
                                  self.grids)
        self.path_manager.onExit(self.path_sensor, self.exit_grid, self.grids)
Exemplo n.º 4
0
    def create_proximity_manager():
        """
        Create a proximity manager and returns it.

        Returns: proximity manager

        """

        manager = vizproximity.Manager()
        manager.setDebug(viz.OFF)
        #vizact.onkeydown('v', manager.setDebug, viz.TOGGLE)

        return manager
Exemplo n.º 5
0
    def __init__(self, path, step, radius, bemobil, tracker):
        """
        Builds a rectangular room shape that subjects are not allowed to leave.

        Args:
            path: path along defined points defining the proximity sensor shape. Should be the bounding room shape.
            step: distance between each line building the grid
            radius: distance to the wall at which the proximity sensor should be triggered
            bemobil: if true, then path area will be fixed to [(3, 6.5), (-3, 6.5), (-3, -6.5), (3, -6.5), (3, 6.5)].
            tracker: tracker object to make as proximity target.
        """

        self.grids = []

        if bemobil:
            self.path = [(3, 6.5), (-3, 6.5), (-3, -6.5), (3, -6.5), (3, 6.5)]

        self.grid1 = self.add_grid([13, 3], [0, 0, 0], [3, 1.5, 0], step)
        self.grids.append(self.grid1)

        self.grid2 = self.add_grid([6, 3], [90, 0, 0], [0, 1.5, 6.5], step)
        self.grids.append(self.grid2)

        self.grid3 = self.add_grid([13, 3], [0, 0, 0], [-3, 1.5, 0], step)
        self.grids.append(self.grid3)

        self.grid4 = self.add_grid([6, 3], [90, 0, 0], [0, 1.5, -6.5], step)
        self.grids.append(self.grid4)

        for grid in self.grids:
            grid.addAction(vizact.fadeTo(0, time=3))
            grid.color(viz.GREEN)

        self.path_sensor = self.create_path_sensor(self.path, radius)

        self.path_manager = vizproximity.Manager()
        self.path_manager.addSensor(self.path_sensor)

        if tracker:
            self.path_manager.addTarget(tracker)
        else:
            self.path_manager.addTarget(viz.MainView)

        self.path_manager.setDebug(viz.OFF)
        #vizact.onkeydown('d', self.path_manager.setDebug, viz.TOGGLE)

        self.path_manager.onEnter(self.path_sensor, self.enter_grid,
                                  self.grids)
        self.path_manager.onExit(self.path_sensor, self.exit_grid, self.grids)
Exemplo n.º 6
0
	def load(self, dataset = 'right arm'):
		"""
		Load datasets and initialize everything necessary to commence
		the puzzle game. Customized for test mode.
		"""
		
		# Dataset
		model.ds = bp3d.DatasetInterface()
		

		# Proximity management
		model.proxManager = vizproximity.Manager()
		target = vizproximity.Target(model.pointer)
		model.proxManager.addTarget(target)

		model.proxManager.onEnter(None, self.EnterProximity)
		model.proxManager.onExit(None, self.ExitProximity)
		
		#create list of meshes to load
		self._meshesToLoad = model.ds.getOntologySet(dataset)
		self._filesToPreSnap = model.ds.getPreSnapSet()
		
		#create and add quiz panel
		self._quizPanel = puzzleView.TestSnapPanel()
		self._quizPanel.toggle()
		
		#load and prep meshes
		viz.MainWindow.setScene(viz.Scene2) #change to loading screen scene
		yield self.loadControl(self._meshesToLoad)
		yield self.prepareMeshes()
		yield self.preSnap()
		yield self.addToBoundingBox(self._meshes)
		yield self.disperseRandom(self._boundingBoxes.values())
		yield self.setKeystone(3)
		yield self.testPrep()
		yield self.hideMeshes()
		yield rotateAbout(self._boundingBoxes.values(), [0,0,0], [0,90,0])
		viz.MainWindow.setScene(viz.Scene1) #change back to game scene
		
		# Setup Key Bindings
		self.bindKeys()
		
		#Schedule closest bone calculation
		viztask.schedule(self.updateClosestBone)
Exemplo n.º 7
0
	def load(self, dataset):
		"""
		Load datasets and initialize everything necessary to commence
		the puzzle game.
		"""
		
		# Dataset
		model.ds = bp3d.DatasetInterface()

		# Proximity management
		model.proxManager = vizproximity.Manager()
		target = vizproximity.Target(model.pointer)
		model.proxManager.addTarget(target)

		model.proxManager.onEnter(None, self.EnterProximity)
		model.proxManager.onExit(None, self.ExitProximity)

		#Setup Key Bindings
		self.bindKeys()
		

		self.score = PuzzleScore(self.modeName)
		
#		viztask.schedule(soundTask(glove))

		self._meshesToLoad = model.ds.getOntologySet(dataset)
		self._filesToPreSnap = model.ds.getPreSnapSet()
		
		viz.MainWindow.setScene(viz.Scene2) #change to loading screen scene
		yield self.loadControl(self._meshesToLoad)
		yield self.addToBoundingBox(self._meshes)
		yield self.prepareMeshes()
		yield self.disperseRandom(self._boundingBoxes.values())
		yield self.preSnap()
		yield self.setKeystone(3)
		yield rotateAbout(self._boundingBoxes.values() + self._meshes, [0,0,0], [0,90,0])
		viz.MainWindow.setScene(viz.Scene1) #change back to game scene
#		yield self.enableSlice()

		viztask.schedule(self.updateClosestBone())
Exemplo n.º 8
0
    def setup(self):
        # set up a folder to store data for a subject.
        dirname = self.find_output(threshold_min=GAP_MINUTES)
        self.output = os.path.join(BASE_PATH, dirname)
        logging.info('storing output in %s', self.output)

        # configure the phasespace.
        mocap = vrlab.Phasespace('192.168.1.230', freq=120)
        self.suit = mocap.track_points(range(len(suit.MARKER_LABELS)))
        self.leds = []
        for i in range(50):
            sphere = vizshape.addSphere(0.02, color=viz.RED)
            self.suit.link_marker(i, sphere)
            self.leds.append(sphere)
        mocap.start_thread()

        # set up a proximity manager to detect touch events.
        self.prox = vizproximity.Manager()
        #self.prox.setDebug(viz.ON)

        # add an environment and navigation to help with visualization.
        self.environment = viz.addChild('dojo.osgb')
        viz.cam.setHandler(None)
Exemplo n.º 9
0
	def load(self, dataset = 'right arm'):
		"""
		Load datasets and initialize everything necessary to commence
		the puzzle game.
		"""
		
		# Dataset
		model.ds = model.DatasetInterface()

		# Proximity management
		model.proxManager = vizproximity.Manager()
		target = vizproximity.Target(model.pointer)
		model.proxManager.addTarget(target)

		model.proxManager.onEnter(None, self.EnterProximity)
		model.proxManager.onExit(None, self.ExitProximity)
	
		#Setup Key Bindings
		self.bindKeys()
		
		# start the clock
		time.clock()

		self.score = PuzzleScore(self.modeName)
		
#		viztask.schedule(soundTask(glove))

		self._meshesToLoad = model.ds.getOntologySet(dataset)
		self.loadMeshes(self._meshesToLoad)

		# Set Keystone
		for m in [self._meshes[i] for i in range(0,1)]:
			m.setPosition([0.0,1.5,0.0])
			m.setEuler([0.0,90.0,180.0])
			m.group.grounded = True
			self._keystones.append(m)
Exemplo n.º 10
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.º 11
0
p2 = vizshape.addCube(size=1)
p2.color(0, 1, 0)
p2.setPosition(9, 0, 8)
p2p = p2.collideBox()
sensor2 = vizproximity.addBoundingBoxSensor(p2)
target2 = vizproximity.Target(sphere2)

p3 = vizshape.addCube(size=1)
p3.color(0, 0, 1)
p3.setPosition(9, 0, 6)
p3p = p3.collideBox()
sensor3 = vizproximity.addBoundingBoxSensor(p3)
target3 = vizproximity.Target(sphere3)

#Create proximity manager
manager = vizproximity.Manager()
manager1 = vizproximity.Manager()
manager2 = vizproximity.Manager()

manager.addSensor(sensor1)
manager1.addSensor(sensor2)
manager2.addSensor(sensor3)
manager.addTarget(target1)
manager1.addTarget(target2)
manager2.addTarget(target3)

#Toggle debug shapes with keypress
vizact.onkeydown('d', manager.setDebug, viz.TOGGLE)

sensors = [sensor1, sensor2, sensor3]
targets = [target1, target2, target3]
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
        yield viztask.waitDraw()


# Define a function to recording the head orientation during the trial
def recording(record, scene, condition, stimuli, trialNo):
    while True:
        data = str(scene) + ',' + str(condition) + ',' + str(
            stimuli) + ',' + str(trialNo) + ',' + str(viz.tick()) + ',' + str(
                view.getPosition()).strip('[]') + ',' + str(
                    view.getEuler()).strip('[]') + '\n'
        record.write(data)
        yield viztask.waitTime(1 / 75)


# Set up a calibration at the beginning of each trial
manager_cali = vizproximity.Manager()
# First create a transparent ball
eyepatch = viz.addTexQuad(parent=viz.HEAD, color=viz.CYAN, size=1)
eyepatch.setPosition([0, 0, 5], viz.ABS_PARENT)
eyepatch.alpha(0.5)
eyepatch.visible(viz.OFF)
# Set up sensor
sensor = vizproximity.Sensor(vizproximity.Box(size=[0.4, 0.4, 2]),
                             source=Cross)
# Set up target
target_cali = vizproximity.Target(eyepatch)
# Add sensor and target
manager_cali.addSensor(sensor)
manager_cali.addTarget(target_cali)

# Set up the information panel
Exemplo n.º 14
0
    def __init__(self, canvas):

        sf = 0.5
        model.pointer.setEuler(0, 0, 0)
        model.pointer.setPosition(0, 0, 0)
        self.gloveStart = model.pointer.getPosition()
        self.iterations = 0
        self.canvas = canvas
        self.origPosVec = config.positionVector
        self.origOrienVec = config.orientationVector

        #creating directions panel
        #		viz.mouse.setVisible(False)
        #		directions = vizinfo.InfoPanel('', fontSize = 10, parent = canvas, align = viz.ALIGN_LEFT_TOP, title = 'Tutorial', icon = False)
        #		if config.pointerMode ==0:
        #			directions.addItem(viz.addText('Keyboard Controls:'))
        #			directions.addLabelItem(viz.addText('W'))
        #
        #		if config.pointerMode ==1:
        #			directions.addItem(viz.addText('Spacemouse Controls:'))
        #			directions.addItem(viz.addTexQuad(size = 300, parent = canvas, texture = viz.addTexture('.\\mouse key.png')))

        #creating tutorial objects
        self.dog = viz.addChild('.\\dataset\\dog\\dog.obj')
        self.dogOutline = viz.addChild('.\\dataset\\dog\\dog.obj')
        self.dogStart = self.dog.getPosition()
        self.dog.setScale([sf, sf, sf])
        self.dogOutline.setScale([sf, sf, sf])
        self.startColor = model.pointer.getColor()

        #creating dog outline
        self.dogOutline.alpha(0.8)
        self.dogOutline.color(0, 5, 0)
        self.dogOutline.texture(None)

        #creating proximity manager
        self.manager = vizproximity.Manager()
        '''creating dog grab and snap sensors around sphere palced in the center of the dog'''
        self.dogCenter = vizshape.addSphere(0.1, pos=(self.dogStart))
        self.dogSnapSensor = vizproximity.Sensor(vizproximity.Sphere(
            0.35, center=[0, 1, 0]),
                                                 source=self.dogCenter)
        self.outlineCenter = vizshape.addSphere(0.1, pos=(self.dogStart))

        self.dogCenter.setPosition([0, -.35, 0])
        self.outlineCenter.setPosition([0, -.35, 0])

        self.centerStart = self.dogCenter.getPosition()
        self.dogGrab = viz.grab(self.dogCenter, self.dog)
        self.outlineGrab = viz.grab(self.outlineCenter, self.dogOutline)

        self.dogCenter.color(5, 0, 0)
        self.outlineCenter.color(0, 5, 0)
        self.dogCenter.visible(viz.OFF)
        self.outlineCenter.visible(viz.OFF)

        self.dogSnapSensor = vizproximity.Sensor(vizproximity.Sphere(
            0.35, center=[0, 1, 0]),
                                                 source=self.dogCenter)
        self.manager.addSensor(self.dogSnapSensor)
        self.dogGrabSensor = vizproximity.Sensor(vizproximity.Sphere(
            0.85, center=[0, 1, 0]),
                                                 source=self.dogCenter)
        self.manager.addSensor(self.dogGrabSensor)
        '''creating glove target and a dog target. the dog target is a sphere placed at the center of the dog outline'''
        self.gloveTarget = vizproximity.Target(model.pointer)
        self.manager.addTarget(self.gloveTarget)
        self.dogTargetMold = vizshape.addSphere(0.2,
                                                parent=self.dogOutline,
                                                pos=(self.dogStart))
        self.dogTargetMold.setPosition([0, 1.2, 0])
        self.dogTargetMold.visible(viz.OFF)
        self.dogTarget = vizproximity.Target(self.dogTargetMold)
        self.manager.addTarget(self.dogTarget)

        #manager proximity events
        self.manager.onEnter(self.dogGrabSensor, EnterProximity,
                             self.gloveTarget, model.pointer)
        self.manager.onExit(self.dogGrabSensor, ExitProximity, model.pointer,
                            self.startColor)
        self.manager.onEnter(self.dogSnapSensor, snapCheckEnter,
                             self.dogTarget)
        self.manager.onExit(self.dogSnapSensor, snapCheckExit,
                            self.dogTargetMold)

        #reset command
        self.keybindings = []
        self.keybindings.append(
            vizact.onkeydown('l', resetGlove, self.manager, self.gloveStart,
                             self.dogCenter, self.outlineCenter))
        self.keybindings.append(vizact.onkeydown('p', self.debugger))

        #task schedule
        self.interface = viztask.schedule(self.interfaceTasks())
        self.gameMechanics = viztask.schedule(self.mechanics())
Exemplo n.º 15
0
                      left='æ',
                      right='¨',
                      moveMode=viz.REL_LOCAL,
                      moveScale=1.1,
                      turnScale=0.45)

#turn on collisions
viz.collision(viz.ON)

#######################
## PROXIMITY MANAGER ##
#######################

##Create proximity manager
global manager
manager = vizproximity.Manager()

#Add main viewpoint as proximity target'
global target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)

##################
##MATH FUNCTIONS##
##################


def pol2cart(rho, phi):
    x = rho * numpy.cos(phi)
    y = rho * numpy.sin(phi)
    return (x, y)
Exemplo n.º 16
0
    vizproximity.RectangleArea([2.25, 1.5], center=[4, 6.75]), None)
sensor9 = vizproximity.Sensor(
    vizproximity.RectangleArea([3, 1], center=[4, 4.75]), None)
sensor10 = vizproximity.Sensor(
    vizproximity.RectangleArea([2.5, 2.25], center=[4, 2.5]), None)
sensor11 = vizproximity.Sensor(
    vizproximity.RectangleArea([4.25, 1], center=[4, 0.375]), None)

sensorList = [
    sensor1, sensor2, sensor3, sensor4, sensor5, sensor6, sensor7, sensor8,
    sensor9, sensor10, sensor11
]
#------------------------------------------------

#-----------Manager creation & set up------------
manager = vizproximity.Manager()
avatarManager = vizproximity.Manager()
#Toggle debug shapes with keypress
vizact.onkeydown('p', manager.setDebug, viz.TOGGLE)
vizact.onkeydown('p', avatarManager.setDebug, viz.TOGGLE)
manager.addTarget(target)

#-----------Avatar's position creation & organization-----
positions = []
positions.append([-3, 0, 0.375])
positions.append([-3, 0, 2.5])
positions.append([-3, 0, 4.75])
positions.append([-3, 0, 6.75])
positions.append([-2, 0, 7.5])
positions.append([3, 0, 6.75])
positions.append([2, 0, 7.5])
Exemplo n.º 17
0
INSTRUCTIONS = """
{} bombs are to be defused in the city. You have {} seconds to get to each of them.
Use the mouse to move around. The locations of the bombs include
a the school, school bus, trash can, by the bench etc be very observant while looking
for the bomb so you do not run out of time and blow up the city.
Press spacebar to begin the bomb defusal game!""".format(
    TRIAL_COUNT, TRIAL_DURATION)

RESULTS = """You found {} of {} bombs."""

TRIAL_SUCCESS = 'Bomb found!'
TRIAL_FAIL = 'Failed, Please evacuate !!'

# Add main viewpoint as proximity target
manager = vizproximity.Manager(viz.MainView)
manager.addTarget(vizproximity.Target(viz.MainView))

# Create sensors attached to static matrix
#Bomb in car
sensor = vizproximity.Sensor(vizproximity.Sphere(15.0),
                             source=viz.Matrix.translate(-85, 0.3, 30))

#Bomb in small building
sensor2 = vizproximity.Sensor(vizproximity.Sphere(15.0),
                              source=viz.Matrix.translate(-15, 0, -25))

#Bomb in school
sensor3 = vizproximity.Sensor(vizproximity.Sphere(15.0),
                              source=viz.Matrix.translate(70, 0, -20))