Esempio n. 1
0
	def _updateFadeOut(self, amount):
		"""Internal update function for fade out"""
		if self._mixer.getVolume() > 0:
			self._adjustVolume(amount)
		else:
			self._mixer.setVolume(0)
			viz.sendEvent(FADE_COMPLETE)
    def workflow(self):
        """Run the workflow associated with this task.

        Each task is separated into three phases: startup, running, and
        teardown. (These are inspired by the commonly implemented phases of a
        unit test.)

        Example implementations:

            def wait_setup(self):
                yield viztask.waitTime(3)  # wait 3 seconds before setting up

            def wait_setup(self):
                yield viztask.waitKeyDown(' ')  # wait until space is pressed

            def wait_setup(self):
                yield self.signal.wait()  # wait until some signal fires

        Instances of this task also emit events just before and just after
        running the task. These events can be used to attach callbacks that do
        things like start and stop a timer, or other similar things you might
        want to do during an experiment.
        """
        yield self.setup()
        viz.sendEvent(self.PRE_RUN_EVENT, self)
        yield self.run()
        viz.sendEvent(self.POST_RUN_EVENT, self)
        yield self.teardown()
Esempio n. 3
0
 def __trackResponse(self):
     readStart = 0
     while True:
         if self.going:
             resp = self.T1.readAllResponse()
             for r in resp:
                 sm = r.find('sm')
                 if sm is not None and sm.text == FLMOCommands.ServerMessages.ActualValue:
                     try:
                         q = self.T1.MotorResponses[r.find('id').text]
                         q.time = viz.tick()
                         q.value = self.T1.device_to_si * float(
                             r.find('v').text)
                         self.readTime = viz.tick() - readStart
                         readStart = viz.tick()
                         viz.sendEvent(TREADMILL_STATE_UPDATED)
                     except (ValueError):
                         print "Warning (VTreadmill: could not parse value from"
                         print "   ", treadmill.ET.tostring(r)
                         print "continuing"
                     except (KeyError):
                         print "Warning (VTreadmill: could not locate id from"
                         print "   ", treadmill.ET.tostring(r)
                         print "   id was: ", r.find('id').text
                         print "   available ids are:"
                         for k, v in self.T1.MotorResponses.iteritems():
                             print "        ", k
                         print "continuing"
                 elif sm is not None and sm.text == FLMOCommands.ServerMessages.ErrorMessage:
                     viz.logWarn(
                         "Warning (VTreadmill): Treadmill returned an error:\n   ",
                         treadmill.ET.tostring(r), "\n    ",
                         r.find('string').text)
         yield None
def objectBasketed(e):
 global rhandtar, lhandtar, rSelectedNode, lSelectedNode, rhGrabber, lhGrabber, ALL_GRABBED_EVENT
 global yMove, basketBounding
 selectedNode = e.__dict__['released']
# if e.target == rhandtar:
#  selectedNode = rSelectedNode
# elif e.target == lhandtar:
#  selectedNode = lSelectedNode
 
 if selectedNode != None:
  globals_oa.AUDIO_SUCCESS.play()
  
  yMove = 0.02
  basketBounding = globals_oa.basket.getBoundingBox()
  vizact.ontimer2(0.001, 400, dropObject, selectedNode)
  
  rhGrabber.removeItems([selectedNode])
  lhGrabber.removeItems([selectedNode])
#  if e.target == rhandtar:
#   rhGrabber.release()
#  elif e.target == lhandtar:
#   lhGrabber.release()
  currentListOfGrabables = rhGrabber.getItems()
  print "currentListOfGrabables = " + str(currentListOfGrabables)
  if currentListOfGrabables == []:
   viz.sendEvent(ALL_GRABBED_EVENT)
Esempio n. 5
0
def H2CO3formation():
	global bigCO2, bigH2O, h2co3molecule, co2Path, lowPolyMole, highPolyMole, h2co3FormationTriggered
	
	h2co3FormationTriggered = True
	
	viz.sendEvent(globals_oa.H2CO3_COMPLETION_EVENT)
	
	#none of the following calls work to get the correct 3d position, phew!
#	x,y,z = bigH2O.getPosition(viz.ABS_GLOBAL)
#	x,y,z = bigH2O.getBoundingBox().center
	#hardcoded value below, until the sunny day when Worldviz gets us a call for the correct position of a 3d node!
	co2Path.remove()
	x,y,z = globals_oa.h2OLocationUntilWeChangeAgain[0], globals_oa.h2OLocationUntilWeChangeAgain[1], globals_oa.h2OLocationUntilWeChangeAgain[2]
	print x,y,z
	moveToH2O = vizact.moveTo([x,y,z] , speed = .75)
	yield viztask.addAction(bigCO2, moveToH2O)
	#yield viztask.waitTime(.05)
	#Fade molecules from bigCO2 and bigH2O to H2CO3 animation
	h2co3molecule.setPosition(globals_oa.h2CO3LocationUntilWeChangeAgain)
	lowPolyMole.enable(viz.RENDERING)
	highPolyMole.disable(viz.RENDERING)
	h2co3molecule.visible(viz.ON)
	h2co3molecule.setAnimationTime(8.9) #starts animation at 17.8 seconds
#	h2co3molecule.setAnimationSpeed(0.1)
	h2co3molecule.setAnimationLoopMode(0)
#	viztask.waitTime(.5)
	fadeOut = vizact.fadeTo(0, time=1)
	lowPolyMole.addAction(fadeOut)
	bigH2O.addAction(fadeOut)
	yield viztask.waitTime(5)
	bigCO2.visible(viz.OFF)
	bigH2O.visible(viz.OFF)
def endScavengerHunt():
	global time_text
	
	print "SCAVENGER HUNT OVER"
	#if scavengerHuntEndSound is None:
		#scavengerHuntEndSound = loadAudioFile(AUDIO_DIRECTORY + 'bell.wav')
	#scavengerHuntEndSound.play()
	time_text.message('Scavenger hunt over')
	if globals_oa.currentZoneNumber == 0: 
		globals_oa.scavengerHuntCompleteInTestZone = True
		#making the slate and stuff on it invisible after the practice scvenger hunt
		time_text.visible(False)
		globals_oa.slate.visible(False)
		quad.visible(False)
		score_text.visible(False)
		time_text.message('')
		score_text.message('')
	elif globals_oa.currentZoneNumber == 1: 
		globals_oa.scavengerHuntCompleteInZone1 = True
		globals_oa.MOVEMENT_DATA_RECORDING_TAG = globals_oa.TAG_SCAVENGER_HUNT_END_ZONE_1
		print "sending ZONE1_OVER_EVENT"
		viz.sendEvent(ZONE1_OVER_EVENT)
	#elif globals_oa.currentZoneNumber == 2: globals_oa.scavengerHuntCompleteInZone2 = True
	elif globals_oa.currentZoneNumber == 3: 
		globals_oa.scavengerHuntCompleteInZone3 = True
		globals_oa.slate.visible(False)
		globals_oa.MOVEMENT_DATA_RECORDING_TAG = globals_oa.TAG_SCAVENGER_HUNT_END_ZONE_3
		viz.sendEvent(ZONE3_OVER_EVENT)
def moveToDash(node):
	if (node == cup1):#cup1
		move = vizact.sequence(vizact.moveTo([-.70,1.4,-2.4],speed=.5),vizact.moveTo([.69,1.4,-2.4],speed=.5), vizact.moveTo([.69,1.23,-2.76],speed=.5))
		node.addAction(move)
		yield viztask.waitActionEnd(node,move)
		viz.sendEvent(FINDING_TASK_OVER_EVENT, SCENE)
	elif (node == toothBrush or node == bristles): #toothbrush
		move = vizact.sequence(vizact.moveTo([7,10,-3],speed=5), vizact.moveTo([10,13.5,-15],speed=5))
		toothBrush.addAction(move)
		bristles.addAction(move)
		yield viztask.waitActionEnd(bristles,move)
	elif (node == toothPaste or node == cap): #toothpaste
		move = vizact.sequence(vizact.moveTo([0,1,10],speed=7),vizact.moveTo([18,1,-3],speed=7))
		toothPaste.addAction(move)
		cap.addAction(move)
		yield viztask.waitActionEnd(cap,move)
	elif (node == bottle1 or node == bottleCap1):#bottle 1
		move = vizact.moveTo([0,-17.5, -8], time=1)
		spin = vizact.spinTo(euler=[0,25,0], time = 1)
		spinMove = vizact.parallel(spin, move)
		move = vizact.sequence(spinMove, vizact.moveTo([15,-13,-6],speed=8), vizact.moveTo([15,-3,-6],speed=8), vizact.moveTo([18,-5,-17],speed=8))
		bottle1.addAction(move)
		bottleCap1.addAction(move)
		yield viztask.waitActionEnd(bottle1,move)
	elif (node == bottle2 or node == bottleCap2): #bottle 2
		move = vizact.sequence(vizact.moveTo([7,12,-3],speed=5), vizact.moveTo([8,12,-14],speed=5))
		bottle2.addAction(move)
		bottleCap2.addAction(move)
		yield viztask.waitActionEnd(bottle2,move)
	elif (node == cup2): #cup 2
		move = vizact.sequence(vizact.moveTo([0,2.5,0],speed=5),vizact.moveTo([15,2.5,0],speed=5), vizact.moveTo([15,0,0],speed=5))
		node.addAction(move)
		yield viztask.waitActionEnd(node,move)
		viz.sendEvent(FINDING_TASK_OVER_EVENT, SCENE)
Esempio n. 8
0
def doShutdownTreadmill():
    yield viztask.waitKeyDown('q')
    viz.sendEvent(STOP_TREADMILL)
    yield viztask.waitEvent(TREADMILL_STOPPED)
    print "pause ...",
    yield viztask.waitTime(1)
    print "done"
    viz.quit()
Esempio n. 9
0
def _on_key_down(key):
    """
	Call the CONTROL_MATERIAL event dependent on the pressed number key.
	"""
    try:
        number = int(key)
        viz.sendEvent(CONTROL_MATERIAL, number)
    except:
        pass
Esempio n. 10
0
 def __stop(self):
     yield viztask.waitEvent(STOP_TREADMILL)
     if self.going:
         self.stopMotors()
         yield viztask.waitTime(1)
         print "Closing socket ...",
         self.T1.stop()
         print "done"
         viz.sendEvent(TREADMILL_STOPPED)
Esempio n. 11
0
def lookingAtOpening():
 global timesLookedOpening, lookingOpeningTimer, LOOKED_OPENING_EVENT
 renderStats = viz.getRenderStats()
 if renderStats.drawableCount > 300:
  timesLookedOpening += 1
 
 if timesLookedOpening >= 20:
  viz.sendEvent(LOOKED_OPENING_EVENT)
  lookingOpeningTimer.setEnabled(0)
Esempio n. 12
0
def EnterZone3Proximity(e):
 global SWIM_ZONE_TO_ZONE_COMPLETE_EVENT
 
# print "entered......................"
 
 #turning off swimming
 transport_vhil.onKeyDown('g')
 
 #raise the custom completion event
 viz.sendEvent(SWIM_ZONE_TO_ZONE_COMPLETE_EVENT)
Esempio n. 13
0
def CheckMouse(): 
    global _mouseState 
    pos = viz.mouse.getPosition(viz.WINDOW_NORMALIZED,True) 
    state = (0 <= pos[0] <= .1) and (0 <= pos[1] <= .1) 
    if state != _mouseState: 
        _mouseState = state 
        if state: 
            viz.sendEvent(MOUSE_ENTER_SPECIAL_EVENT,pos) 
        else: 
            viz.sendEvent(MOUSE_LEAVE_SPECIAL_EVENT,pos) 
Esempio n. 14
0
def CheckView():
    global _viewState
    state = viz.MainView.getEuler()[1] < -45
    if state != _viewState:
        _viewState = state
        if state:
            print 'LOOK UP'
            viz.sendEvent(VIEW_LOOKUP_ENTER_EVENT)
        else:
            print 'LOOK DOWN'
            viz.sendEvent(VIEW_LOOKUP_EXIT_EVENT)
Esempio n. 15
0
def testForZone1SpeciesCountCompletion():
	global ZONE1_OVER_EVENT

	allFlagsVisible = True
	
	for snailAndFlagItem in globals_oa.snailAndFlagItemsInZone1:
		if snailAndFlagItem.flagItemFromZoneModel.getVisible() == False:
			print "at least one snail is yet to be found!"
			return
		
	print "sending ZONE1_OVER_EVENT"
	viz.sendEvent(ZONE1_OVER_EVENT)
Esempio n. 16
0
def playPhoneAndRadio():
	
	global main_screen, radio, selector, phoneEvent
	yield screen.playsound('resources/audio/vibrate.wav', viz.STOP)
	yield selector.disable()
	yield selector.disable()
	yield screen.endAction( pool = 0)
	yield vizact.removeEvent(phoneEvent)
	voicemail = screen.playsound('resources/audio/voicemail_mono.wav', viz.PLAY)
	yield viztask.waitTime(voicemail.getDuration())
	newsReport = radio.playsound('resources/audio/RadioShowScene_louder.wav')
	yield viztask.waitTime(newsReport.getDuration())
	viz.sendEvent(INTRO_OVER_EVENT)
Esempio n. 17
0
def CheckNearMan():
	global state
	pos = viz.MainView.getPosition()
	dx = pos[0] - MAN_POSITION[0]
	dz = pos[2] - MAN_POSITION[2]
	distance = math.sqrt(dx * dx + dz * dz)
	closeToMan = distance < 3 # Whether we are close to the man or not
	if (state != closeToMan):
		state = closeToMan
		if (closeToMan):
			viz.sendEvent(APPROACH_MAN_EVENT)
		else:
			viz.sendEvent(LEAVE_MAN_EVENT)
Esempio n. 18
0
def CheckKey():
	if viz.key.isDown('w',immediate=False):
		viz.sendEvent(W_KEY_PRESSED_EVENT)
	elif viz.key.isDown('a',immediate=False):
		viz.sendEvent(A_KEY_PRESSED_EVENT)
	elif viz.key.isDown('s',immediate=False):
		viz.sendEvent(S_KEY_PRESSED_EVENT)
	elif viz.key.isDown('d',immediate=False):
		viz.sendEvent(D_KEY_PRESSED_EVENT)
Esempio n. 19
0
    def workflow(self):
        '''Run the workflow associated with this task.

        Each task is separated into three phases: startup, running, and
        teardown. (These are inspired by the commonly implemented phases of a
        unit test.)

        Instances of this task also emit events just before and just after
        running the task. These events can be used to attach callbacks that do
        things like start and stop a timer, or other similar things you might
        want to do during an experiment.
        '''
        yield self.setup()
        viz.sendEvent(self.PRE_RUN_EVENT, self)
        yield self.run()
        viz.sendEvent(self.POST_RUN_EVENT, self)
        yield self.teardown()
Esempio n. 20
0
    def workflow(self):
        '''Run the workflow associated with this task.

        Each task is separated into three phases: startup, running, and
        teardown. (These are inspired by the commonly implemented phases of a
        unit test.)

        Instances of this task also emit events just before and just after
        running the task. These events can be used to attach callbacks that do
        things like start and stop a timer, or other similar things you might
        want to do during an experiment.
        '''
        yield self.setup()
        viz.sendEvent(self.PRE_RUN_EVENT, self)
        yield self.run()
        viz.sendEvent(self.POST_RUN_EVENT, self)
        yield self.teardown()
Esempio n. 21
0
def videoScene():
 global player
# viz.MainScene.disable(viz.FOG, op=viz.OP_ROOT)
 
# Change parameters to False, True for PPT 1
# vhilGo(True, False, keyboardcontrol=False)
 player = spherical_player_Vive.Player(globals_oa.SPHERICAL_VIDEO, PPT1=False, radius=4, playPauseKey=' ')
# player.setVolume(0.25)

 screenPosition = player.screen.getPosition()
 player.screen.setPosition([screenPosition[0], 2, screenPosition[1]-1])  #change middle number to move sphere up or down on y axis
 player.toggleLooping()
 player.play()
 globals_oa.SPHERICAL_VIDEO_SCORE.play()
 globals_oa.SPHERICAL_VIDEO_NARRATION.play()
 yield globals_oa.fader.fadeInTask()

 
#	yield viztask.waitAny([viztask.waitTime(2), skipKey])
#	globals_oa.AUDIO_SPHERICAL_1.play()
#	result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.AUDIO_SPHERICAL_1), skipKey])
#	if result.condition is skipKey:
#		globals_oa.AUDIO_SPHERICAL_1.stop()
#
#	yield viztask.waitTime(1)
#	globals_oa.AUDIO_SPHERICAL_2.play()
#	result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.AUDIO_SPHERICAL_2), skipKey])
#	if result.condition is skipKey:
#		globals_oa.AUDIO_SPHERICAL_2.stop()

 # Waits until the video is done playing
#	result = yield viztask.waitAny([viztask.waitTime(player.getVideoDuration() - globals_oa.AUDIO_SPHERICAL_1.getDuration() - globals_oa.AUDIO_SPHERICAL_2.getDuration() - 3.5), skipKey])
#	if result.condition is skipKey:
#			player.pause()

 yield viztask.waitAny([viztask.waitTime(player.getVideoDuration()), skipKey])
# yield viztask.waitTime(player.getVideoDuration())
# yield globals_oa.fader.fadeOutTask()
 
# player2 = player.setMedia('D:/localAssets/OA/tribecaFinalAssets/TCR_transition_video.mp4')
 player.screen.visible(viz.OFF)
 
 viz.sendEvent(globals_oa.VIDEO_END_EVENT)
# globals_oa.AUDIO_ZONE3_AMBIENT.pause()
 player.pause()
Esempio n. 22
0
 def enable(self, value):
     """ Set visibility of all debug objects and enable 
     or disable key callbacks (except the main debug toggle) """
     if value == -1:
         self._enable = not self._enable
     else:
         self._enable = value
     for obj in self._obj:
         obj.visible(self._enable)
     for c in self._callbacks:
         c.setEnabled(self._enable)
     if len(self._points) > 0:
         for point in self._points:
             point.visible(self._enable)
     if self._enable:
         viz.sendEvent(DEBUGGER_SHOW_EVENT)
     elif not self._enable:
         viz.sendEvent(DEBUGGER_HIDE_EVENT)
Esempio n. 23
0
	def __update(self):
		msg = viz.addText("", parent=viz.SCREEN)
		t0 = 0 #for testing
		self.device.softReset()
		yield viztask.waitTime(1)
		print "Zeroing treadmill ... ",
		self.doZero()
		print "done"
		print "Started treadmill forceplates read"
		while self.going:
			results = self.device.getFeedback( self.feedbackArguments )
			for j in range(self.numChannels):
				self.latestAinValues[j] = self.device.binaryToCalibratedAnalogVoltage(self.gainIndex, results[2+j])
			self.lastForceMoments = list(self.latestForceMoments)
			self.latestForceMoments = self.M.dot(self.latestAinValues+self.zero)
			self.lastLeftOn = self.latestLeftOn
			self.lastRightOn = self.latestRightOn
			self.lastLeftCOP = list(self.latestLeftCOP)
			self.lastRightCOP = list(self.latestRightCOP)
			self.lastTime = self.latestTime
			self.latestTime = viz.tick()
			try:
				self.latestLeftOn = (self.latestForceMoments[2] < MIN_WEIGHT_NEWTONS)
				self.latestLeftCOP[0] = -1.0*self.latestForceMoments[4]/self.latestForceMoments[2]
				self.latestLeftCOP[1] = self.latestForceMoments[3]/self.latestForceMoments[2]
				self.latestRightOn = (self.latestForceMoments[8] < MIN_WEIGHT_NEWTONS)
				self.latestRightCOP[0] = -1.0*self.latestForceMoments[10]/self.latestForceMoments[8]
				self.latestRightCOP[1] = self.latestForceMoments[9]/self.latestForceMoments[8]
			except(ZeroDivisionError):
				print "div zero caught in ForcePlate ... ignoring"
				pass
			if self.recording:
				#self.data.append([viz.tick(), [x for x in self.latestAinValues]])
				self.data.append([viz.tick(), [x for x in self.latestForceMoments]])
				
			if self.lastLeftOn and not self.latestLeftOn:
				viz.sendEvent(LEFT_OFF_TREADMILL)
			if not self.lastLeftOn and self.latestLeftOn:
				viz.sendEvent(LEFT_ON_TREADMILL)
			if self.lastRightOn and not self.latestRightOn:
				viz.sendEvent(RIGHT_OFF_TREADMILL)
			if not self.lastRightOn and self.latestRightOn:
				viz.sendEvent(RIGHT_ON_TREADMILL)
				
			#testing
			t1 = t0
			t0 = viz.tick()
			#msg.message("%3.3fs"%(t0-t1))
			#msg.message("%6.3f %6.3f"%(self.latestLeftCOP[0], self.latestLeftCOP[1]))
			#if self.lastLeftOn:
			#	msg.message("Left on")
			#elif self.lastRightOn:
			#	msg.message("Right on")
			yield None
Esempio n. 24
0
	def __ZeroSpacing(self, samples=60):
		while True:
			yield viztask.waitEvent(REQUEST_FEET_ALIGNMENT_TREADMILL)
			print "Starting zero ... ",
			yield None
			self.left = []
			self.right = []
			for i in range(samples):
				self.left.append(self.forceplates.latestLeftCOP[1])
				self.right.append(self.forceplates.latestRightCOP[1])
				yield None
			print "done"
			self.left = np.array(self.left)
			self.right = np.array(self.right)
			global CORRECT_LEFT
			CORRECT_LEFT = np.mean(self.right) - np.mean(self.left)
			print "Adjusting left ", CORRECT_LEFT, " meters to match right"
			print "Variability was ", np.std(self.left), " on the left"
			print "Variability was ", np.std(self.right), " on the right"
			viz.sendEvent(DONE_FEET_ALIGNMENT_TREADMILL)
Esempio n. 25
0
def selectObject(e):
	global rhandtar, lhandtar, rhtool, lhtool, objectName, yMove
	selectedNode = e.__dict__['released']
#	if e.target == rhandtar:
#		selectedNode = rSelectedNode
#	elif e.target == lhandtar:
#		selectedNode = lSelectedNode
	
#	if globals_oa.tempPromptScreen.getVisible():
#		return
	if selectedNode != None:
		#Do not remove onDeleseltCallback from node, otherwise crosshair will not change back to normal
		
		#foundSound = loadAudioFile(AUDIO_DIRECTORY + 'ding.wav')
		#foundSound.play()
		globals_oa.AUDIO_SUCCESS.play()
		#if objectName is not None: datacollection.recordScavengerHuntObjectFound(globals_oa.currentZoneNumber, objectName, 'bucketed')
		
		yMove = 0.002
		vizact.ontimer2(0.001, 400, dropSlowly, selectedNode)

#		selectedNode.visible(False)
		rhtool.removeItems([selectedNode])
		lhtool.removeItems([selectedNode])
		updateScore(selectedNode)
		
#		if e.target == rhandtar:
#			rhtool.release()
#		elif e.target == lhandtar:
#			lhtool.release()
		#selectedNode.remove()
		print "HOORAY YOU FOUND SOMETHING\n"
#		if not globals_oa.isDemo:
#			fileOutputAtSpeciesFound()

		global speciesIndex
		if numFound == numObjectsToFind[speciesIndex]:
			disableGrabber()
			print "TASK COMPLETE"
			viz.sendEvent(ALL_FOUND_EVENT)
Esempio n. 26
0
def _on_material_trigger(e):
    """
	Function for the CONTROL_MATERIAL_TRIGGER event.
	This function triggers the CONTROL_MATERIAL event depending on the touch position on the vive controller.
	"""
    trackpad = vizconnect.getRawInput('r_hand_input').getTrackpad()
    # Calculate distance from the center of the touchpad to disable the event there.
    # Controls in that region would be unprecise.
    magnitude = math.sqrt(trackpad[0]**2 + trackpad[1]**2)
    if magnitude <= .2:
        return
    # Calculate the angle between the x-axis and the trackpad point. (counter clockwise)
    # Results reach from 0 to 2 pi radiants.
    # trackpad/magnitude is used to get a vector with length 1
    if trackpad[1] >= 0:
        angle = math.acos(trackpad[0] / magnitude)
    else:
        angle = 2 * math.pi - math.acos(trackpad[0] / magnitude)
    # Divide the trackpad in equal sized sectors
    num_materials = float(_material_range[1] - _material_range[0] + 1)
    number = int(angle * num_materials / (2 * math.pi))
    # Trigger the event
    viz.sendEvent(CONTROL_MATERIAL, number + _material_range[0])
Esempio n. 27
0
	def check_pulse(self):
		state = self.port.read()
		triggertime = viz.tick()
		if state:
			if state == TRIGGER_DOWN:
				viz.sendEvent(TRIGGER_EVENT)
				self.event_count += 1
				self.received_triggers.append(triggertime)
			elif state == RIGHT_BUTTON_DOWN:
				viz.sendEvent(RIGHT_BUTTON_EVENT,triggertime)
				self.events.append((RIGHT_BUTTON_DOWN,triggertime))
			elif state == LEFT_BUTTON_DOWN:
				viz.sendEvent(LEFT_BUTTON_EVENT,triggertime)
				self.events.append((LEFT_BUTTON_DOWN,triggertime))
Esempio n. 28
0
 def check_pulse(self):
     state = self.port.read()
     triggertime = viz.tick()
     if state:
         if state == TRIGGER_DOWN:
             viz.sendEvent(TRIGGER_EVENT)
             self.event_count += 1
             self.received_triggers.append(triggertime)
         elif state == RIGHT_BUTTON_DOWN:
             viz.sendEvent(RIGHT_BUTTON_EVENT, triggertime)
             self.events.append((RIGHT_BUTTON_DOWN, triggertime))
         elif state == LEFT_BUTTON_DOWN:
             viz.sendEvent(LEFT_BUTTON_EVENT, triggertime)
             self.events.append((LEFT_BUTTON_DOWN, triggertime))
    def on_button_press(self, sensor):
        """
        Callback function to handle button presses by external control devices.

        Args:
            sensor: reports button press by a connected devices

        """

        try:
            if sensor.button == 0:
                viz.sendEvent(self.BUTTON_A_EVENT)

            elif sensor.button == 18:
                viz.sendEvent(self.BUTTON_B_EVENT)
        except:
            pass

        if sensor == 'A':
            viz.sendEvent(self.BUTTON_A_EVENT)

        elif sensor == 'B':
            viz.sendEvent(self.BUTTON_B_EVENT)
Esempio n. 30
0
def ChangeColor() :
	viz.sendEvent(COLOR_EVENT)
Esempio n. 31
0
	def sendright(self):
		triggertime=viz.tick()
		viz.sendEvent(RIGHT_BUTTON_EVENT,triggertime)
		self.events.append((RIGHT_BUTTON_DOWN,triggertime))
Esempio n. 32
0
def waterRise():
    waterPlane.setPosition([0, 0.005, 0], viz.REL_LOCAL)
    viewHeight = viz.MainView.getPosition()[1]
    waterHeight = waterPlane.getPosition()[1]
    if waterHeight > (viewHeight - 0.6):
        viz.sendEvent(WATER_RISE_EVENT)
Esempio n. 33
0
 def sendright(self):
     triggertime = viz.tick()
     viz.sendEvent(RIGHT_BUTTON_EVENT, triggertime)
     self.events.append((RIGHT_BUTTON_DOWN, triggertime))
Esempio n. 34
0
class _Controls(viz.EventClass):
    """
	This class is only used to register the forwarding callbacks.
	Otherwise the global events had to be used, which could result in problems with other scripts.
	"""
    def __init__(self):
        viz.EventClass.__init__(self)


_c = _Controls()
_right_hand_number = 0
_left_hand_number = 1
# Register the forwarding callbacks
_c.callback(viz.getEventID("CONTROL_NEW_FILE"),
            lambda e: viz.sendEvent(CONTROL_NEW_FILE))
_c.callback(viz.getEventID("CONTROL_CLIP"),
            lambda e: viz.sendEvent(CONTROL_CLIP))
_c.callback(viz.getEventID("CONTROL_TOGGLE_ENVIRONMENT"),
            lambda e: viz.sendEvent(CONTROL_TOGGLE_ENVIRONMENT))
_c.callback(viz.getEventID("CONTROL_CLOUD_INCREASE"),
            lambda e: viz.sendEvent(CONTROL_CLOUD_INCREASE))
_c.callback(viz.getEventID("CONTROL_CLOUD_DECREASE"),
            lambda e: viz.sendEvent(CONTROL_CLOUD_DECREASE))
_c.callback(viz.getEventID("CONTROL_CYCLE_VIEW_MODE"),
            lambda e: viz.sendEvent(CONTROL_CYCLE_VIEW_MODE))
_c.callback(viz.getEventID("CONTROL_TOGGLE_STRESSINDICATOR"),
            lambda e: viz.sendEvent(CONTROL_TOGGLE_STRESSINDICATOR))
_c.callback(viz.getEventID("CONTROL_RIGHT_HAND_GRAB"),
            lambda e: viz.sendEvent(CONTROL_HAND_GRAB, _right_hand_number))
_c.callback(viz.getEventID("CONTROL_LEFT_HAND_GRAB"),
Esempio n. 35
0
	def sendit(self):
		# start a timer that sends fake triggers
		triggertime = viz.tick()
		sendit = viz.sendEvent(TRIGGER_EVENT,triggertime)
		self.received_triggers.append(triggertime)
Esempio n. 36
0
def endHunt():
	global ZONE1_OVER_EVENT
	print "sending ZONE1_OVER_EVENT"
	viz.sendEvent(ZONE1_OVER_EVENT)
Esempio n. 37
0
 def sendleft(self):
     triggertime = viz.tick()
     viz.sendEvent(LEFT_BUTTON_EVENT, triggertime)
     self.events.append((LEFT_BUTTON_DOWN, triggertime))
Esempio n. 38
0
def footprintSteppedOnEvent(e):
	print "standing on footprint now!"
	viz.sendEvent(globals_oa.FOOTPRINT_EVENT)
Esempio n. 39
0
	def sendleft(self):
		triggertime=viz.tick()
		viz.sendEvent(LEFT_BUTTON_EVENT,triggertime)
		self.events.append((LEFT_BUTTON_DOWN,triggertime))
Esempio n. 40
0
 def sendit(self):
     # start a timer that sends fake triggers
     triggertime = viz.tick()
     sendit = viz.sendEvent(TRIGGER_EVENT, triggertime)
     self.received_triggers.append(triggertime)
Esempio n. 41
0
def goBoat():
	global skipKey, bigCO2, bigH2O, boatProximityManager, h2co3molecule, footprints, rightHandTarget, leftHandTarget, h2co3FormationTriggered
#####	** participant is standing on the back platform of the boat**
	#load the environment if not already loaded
	
#	print "waiting for city scene to end"
#	yield viztask.waitEvent(globals_oa.CITY_SCENE_END_EVENT)
#	print "received city end event"

	loadStuffAtStartAndHideThemALL()
	print "starting molecule scene"
#	globals_oa.user.setPosition(globals_oa.boatSceneUserStartPos)

	#turning the user around
	globals_oa.user.setAxisAngle([0.0, 1.0, 0.0, 180.0])
	
	#adding a manager for handling boat proximity events
	boatProximityManager = vizproximity.Manager()
#	boatProximityManager.setDebug(viz.ON)
	boatProximityManager.setDebugColor(viz.PURPLE)
	boatProximityManager.setDebugActiveColor(viz.GREEN)

	leftHandTarget = None
	rightHandTarget = None

	if globals_oa.lhModel != None: leftHandTarget = vizproximity.Target(globals_oa.leftHand)
	else: print "lhModel not set up"
	
	if globals_oa.rhModel != None: rightHandTarget = vizproximity.Target(globals_oa.rightHand)
	else: print "rhModel not set up"

	if globals_oa.fader is None: globals_oa.fader = View_Fader.addFader(fadeTime=5)
	
	globals_oa.BOAT_SCENE_AMBIENT.play()
	viz.fog(0)
	globals_oa.fader.fadeIn()
	globals_oa.fadingSphere.alpha(0)

	#unhide boat and stuff
	showStuff()
#	globals_oa.boat.enable(viz.RENDERING)

#####	You’re now on a boat in the middle of the ocean. Look around and observe the CO2 molecules surrounding you.
#	globals_oa.BOAT_SCENE1.play()
#	print "playing BOAT_SCENE1 now"
#	yield viztask.waitAny([viztask.waitTime(29), skipKey])
	
	
#####	Look down at the floor and move so that you’re standing on top of the footprints.

#####*wait until the participant is in the correct position to start*
#	TODO: add a position sensor for the viewpoint of the user to step in
#	boatProximityManager.clearTargets()
#	boatProximityManager.addTarget(vizproximity.Target(viz.MainView))
#	boatProximityManager.clearSensors()
#	footprintsSensor = vizproximity.Sensor(vizproximity.RectangleArea([0.6, 0.6], center = globals_oa.footprintPos), None)
#	boatProximityManager.addSensor(footprintsSensor)
#	
#	boatProximityManager.onEnter(footprintsSensor, footprintSteppedOnEvent)
#
#	print "waiting for the footprint event ..."
#	yield viztask.waitAny([viztask.waitEvent(globals_oa.FOOTPRINT_EVENT), skipKey])

#####Look at water behind the boat. The molecule you see floating on the ocean’s surface is a water molecule, also known as H2O. 
#####Now, remember that CO2 molecule from the car? It’s floating towards you right now.
	
	yield viztask.waitTime(12)   #adds a little time before narration starts, not sure why the number has to be so large...
	globals_oa.BOAT_SCENE2.play()
	print "playing BOAT_SCENE2 now, which is atually the first boat scene"
	yield viztask.waitAny([viztask.waitTime(16), skipKey])
#	yield viztask.waitAny([viztask.waitTime(globals_oa.BOAT_SCENE2.getDuration()), skipKey])

#####**molecule drops down at the back of the boat**
	print "showing the falling molecule and setting its animation time to 0.0"
	yield flyingCO2()
	
#####To view the chemical reaction that occurs when CO2 is absorbed into the ocean, push the molecule over the side of the boat.
	globals_oa.BOAT_SCENE3.play()
	print "playing BOAT_SCENE3 now"
	yield viztask.waitAny([viztask.waitTime(15), skipKey])

#TODO: add a CO2 to the list of sensors in the molecule scene proximity manager
	boatProximityManager.clearTargets()
	if leftHandTarget is not None: 	boatProximityManager.addTarget(leftHandTarget)
	if rightHandTarget is not None: boatProximityManager.addTarget(rightHandTarget)

	boatProximityManager.clearSensors()
	co2Sensor = vizproximity.addBoundingBoxSensor(bigCO2)
	boatProximityManager.addSensor(co2Sensor)
	
	boatProximityManager.onEnter(co2Sensor, h2co3FormationTriggerEvent)
	
	print "waiting for the H2CO3 reaction-animation completion event ..."

	moleculePushFailAudio = globals_oa.BOAT_SCENE_TOUCH
	failTimer = vizact.ontimer(5 + moleculePushFailAudio.getDuration(), moleculePushFailAudio.play)
	
	yield viztask.waitAny([viztask.waitEvent(globals_oa.H2CO3_COMPLETION_EVENT), skipKey])
#	yield skipKey
#	yield viztask.waitAny([viztask.waitTime(4), skipKey])
	failTimer.remove()
	if not h2co3FormationTriggered: viztask.schedule(H2CO3formation())

#####Observe the chemical reaction. When carbon dioxide, or CO2, is absorbed into the ocean it reacts with seawater to form carbonic acid, or H2CO3. 
#####This process is called ocean acidification. If enough carbonic acid is created, the seawater becomes corrosive.  

#####The ocean covers over 70% of the Earth’s surface. Since the Industrial Revolution the ocean has absorbed 
#####roughly ¼ of the carbon dioxide produced by burning fossil fuels. 

#####We may not be able to see these reactions in our daily lives, but we can take a look at how these reactions affect marine life.
#####You will now travel to a special site where scientists have made a breakthrough discovery about carbon dioxide emissions.
	globals_oa.BOAT_SCENE4.play()
	print "playing BOAT_SCENE4 now"
	yield viztask.waitAny([viztask.waitTime(22), skipKey])
	#hide H2CO3
	h2co3molecule.visible(viz.OFF)
	
	yield showHiddenMolecules()
	yield viztask.waitAny([viztask.waitTime(21), skipKey])
#	print "waiting for a final skip key to fade out now - NOT PART OF THE NARRATION"
#	yield skipKey

	globals_oa.BOAT_SCENE_AMBIENT.stop()

	globals_oa.fader.fadeOut()

	#Cleanup
	hideStuff()

	#turning the user around
	globals_oa.user.setAxisAngle([0.0, 1.0, 0.0, 0.0])

	viz.sendEvent(globals_oa.BOAT_SCENE_END_EVENT)
Esempio n. 42
0
def cityScene():
 global city, skyDome2, CRYSTAL_EVENT, moleculeList, rightHandTarget, leftHandTarget
 global mole1, mole2, mole3
 global mole4, mole5, mole6, mole7, mole8, mole9, mole10, mole11
 print "city scene starting"
 globals_oa.CITY_SCENE_AMBIENT.play()
 city.enable(viz.RENDERING)
 viz.fog(0)
 arrow = city.getChild('greenArrow.OSGB')
 arrow.disable(viz.RENDERING)
 tube = city.getChild('yellowTube.OSGB')
 tube.disable(viz.RENDERING)

 yield globals_oa.fader.fadeInTask()
# yield viztask.waitTime(3)
 yield viztask.waitAny([viztask.waitTime(3), skipKey])
# carAudio1 = globals_oa.CAR_SCENE1
# carAudio1.play()
## yield viztask.waitMediaEnd(carAudio1)
# yield viztask.waitAny([viztask.waitTime(10), skipKey])
 carAudio2 = globals_oa.CAR_SCENE2
 carAudio2.play()
 arrow.enable(viz.RENDERING)
 fadeIn = vizact.fadeTo(1, time=1)
 fadeOut = vizact.fadeTo(0, time=1)
 sequence = vizact.sequence(fadeIn, fadeOut, viz.FOREVER)
 arrow.add(sequence)
# yield viztask.waitMediaEnd(carAudio2) 
 yield viztask.waitAny([viztask.waitTime(7), skipKey])
 carAudio3 = globals_oa.CAR_SCENE3
 carAudio3.play()
 arrow.disable(viz.RENDERING)
 manager = vizproximity.Manager()
 manager.setDebug(False)
 rightHandTarget = vizproximity.Target(globals_oa.rightHand)
 leftHandTarget = vizproximity.Target(globals_oa.leftHand)
 car1 = city.getChild('BlueCar.OSGB')
 exhaust = city.getChild('p_silencer-OFFSET')
 car1Sensor = vizproximity.Sensor(vizproximity.Box([0.5,0.7,0.4], center=[1.4,4.2,0]), source=exhaust)
 manager.addTarget(rightHandTarget)
 manager.addTarget(leftHandTarget)
 manager.addSensor(car1Sensor)
 tube.enable(viz.RENDERING)
 tube.add(sequence)
# car1Sensor = vizproximity.Sensor(vizproximity.Box([3.3,1.6,1.8], center=[5,0.4,-10.5]), source=car1)
 
 if carAudio3.audioObj.getState() == viz.MEDIA_RUNNING:
#  yield viztask.waitMediaEnd(carAudio3)
  yield viztask.waitAny([viztask.waitTime(4), skipKey])
# manager.addTarget(rightHandTarget)
# manager.addTarget(leftHandTarget)
# manager.addSensor(car1Sensor)
# CAR_TOUCHED = False
 failAudio = globals_oa.CAR_FAIL_AUDIO
 failAudio.stop()
 failTimer = vizact.ontimer(5 + failAudio.getDuration(), playWrapper, failAudio)
 #yield vizproximity.waitEnter(car1Sensor)

 
 def vibrateRightHand():
  globals_oa.rhViveTracker.setVibration(0.004)
 def vibrateLeftHand():
  globals_oa.lhViveTracker.setVibration(0.004)
 def onEnter(e): 
  global rightHandTarget, leftHandTarget
  print 'working'
  if e.target == rightHandTarget:
    vizact.ontimer2(.004, 100, vibrateRightHand)
  if e.target == leftHandTarget:
    vizact.ontimer2(.004, 100, vibrateLeftHand)
 manager.onEnter(car1Sensor, onEnter)
 
 def startCar1():
  global mole1, mole2, mole3, moleculeList
  mole1 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1)
  moleculeList.append(mole1)
  mole1.setPosition([-1.2, 0.35, -0.08])
  mole1.setScale([3,3,3])
  mole1.setAnimationSpeed(3)
  mole1.setEuler(-90,0,0)
  mole2 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole2)
  mole2.setPosition([-1.1,0.3,0])
  mole2.setScale([3,3,3])
  mole2.setAnimationSpeed(2.1)
  mole2.setEuler(-90,0,0)
  mole3 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole3)
  mole3.setPosition([-1.05,0.29,-0.05])
  mole3.setScale([3,3,3])
  mole3.setAnimationSpeed(5)
  mole3.setEuler(-90,0,0)
 def floatersGo():
  global mole4, mole5, mole6, mole7, mole8, mole9, mole10, mole11, moleculeList
  mole4 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1)
  moleculeList.append(mole4)
  mole4.setPosition([-.2,2.9,0])
  mole4.setEuler([0,-90,0])
  mole4.setScale([3,3,3])
  mole4.setAnimationSpeed(2)
  mole5 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole5)
  mole5.setPosition([-.2,2.9,0])
  mole5.setEuler([90,-90,0])
  mole5.setScale([3,3,3])
  mole5.setAnimationSpeed(2)
  mole6 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1)
  moleculeList.append(mole6)
  mole6.setPosition([-.2,2.9,0])
  mole6.setEuler([180,-90,0])
  mole6.setScale([3,3,3])
  mole6.setAnimationSpeed(2)
  mole7 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole7)
  mole7.setPosition([-.2,2.9,0])
  mole7.setEuler([-90,-90,0])
  mole7.setScale([3,3,3])
  mole7.setAnimationSpeed(2)
  mole8 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole8)
  mole8.setPosition([-.2,2.9,0])
  mole8.setEuler([-45,-90,0])
  mole8.setScale([3,3,3])
  mole8.setAnimationSpeed(2)
  mole9 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole9)
  mole9.setPosition([-.2,2.9,0])
  mole9.setEuler([45,-90,0])
  mole9.setScale([3,3,3])
  mole9.setAnimationSpeed(2)
  mole10 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole10)
  mole10.setPosition([-.2,2.9,0])
  mole10.setEuler([-135,-90,0])
  mole10.setScale([3,3,3])
  mole10.setAnimationSpeed(2)
  mole11 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2)
  moleculeList.append(mole11)
  mole11.setPosition([-.2,2.9,0])
  mole11.setEuler([135,-90,0])
  mole11.setScale([3,3,3])
  mole11.setAnimationSpeed(2)
 def goSpecialMole():
  global specialMole
  yield viztask.waitTime(1)
  specialMole = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE3)
  specialMole.setPosition([-1.33023,0.35456,-0.04151])
  specialMole.setScale([4,4,4])
  lowPolyMole = specialMole.getChild('singleCO2_noAnimation.OSGB')
  lowPolyMole.disable(viz.RENDERING)
  path = viz.addAnimationPath()
  path.addControlPoint(0, pos=[-1.33023,0.35456,-0.04151], euler=(90,0,0), scale= ([4,4,4]))
  path.addControlPoint(1, pos=[-1,0.4, 0], euler=(45,0,0), scale = ([4,4,4]))
  path.addControlPoint(2, pos=[-0.8,0.9,0.1], euler=(0,0,0), scale = ([4,4,4]))
  path.addControlPoint(3, pos=[-0.4,1.3,0.2], euler=(90,0,0), scale = ([4,4,4]))
  pathLink = viz.link(path, specialMole)
  path.play()
 def flyOut():
  global specialMole, skipKey
  yield viztask.waitTime(1)
  path = viz.addAnimationPath()
  path.addControlPoint(0, pos=[-0.4,1.3,0.2], euler=(90,0,0), scale= ([4,4,4]))
  path.addControlPoint(1, pos=[-0.4,1.5,0.6], euler=(55,0,0), scale= ([4,4,4]))
  path.addControlPoint(2, pos=[-0.4,3.3,0.1], euler=(100,0,0), scale= ([4,4,4]))
  path.addControlPoint(3, pos=[-0.4,4.8,0.8], euler=(75,0,0), scale= ([4,4,4]))
  path.addControlPoint(50, pos=[-0.4,70,0.4], euler=(90,0,0), scale = ([4,4,4]))
  pathLink = viz.link(path, specialMole)
  path.play()
# yield viztask.waitKeyDown('/')
 yield vizproximity.waitEnter(car1Sensor)
 failTimer.remove()
 tube.disable(viz.RENDERING)
 globals_oa.CAR_START.play()
 things = vizact.ontimer2(1,10, startCar1)
 yield things
 yield vizact.waittime(1.5)
 things2 = vizact.ontimer2(1,10, floatersGo)
 globals_oa.CAR_SCENE4.play()
 yield things2
 yield vizact.waittime(1.5)
# yield viztask.waitMediaEnd(globals_oa.CAR_SCENE4)
 yield viztask.waitAny([viztask.waitTime(15), skipKey])
 yield goSpecialMole()
 viztask.waitTime(3)
 globals_oa.CAR_SCENE5.play()
# yield viztask.waitMediaEnd(globals_oa.CAR_SCENE5)
 yield viztask.waitAny([viztask.waitTime(6), skipKey]) 
 yield flyOut()
 yield viztask.waitTime(6)
# childList = range(1,160)
# for child in childList:
#  object = viz.VizChild(child)
#  object.remove()
 for mole in moleculeList:
  mole.remove()

 yield globals_oa.fader.fadeOutTask()
 globals_oa.CITY_SCENE_AMBIENT.stop()
 city.remove()

 
 print "sending city end event"
 viz.sendEvent(globals_oa.CITY_SCENE_END_EVENT)