def CycleAlertsTask (self): self._cycler = None #the next item in the list to display (starts with last) fade_out = vizact.fadeTo(0, 1, time=0.5, interpolate=vizact.easeOutStrong) fade_in = vizact.fadeTo(1, 0, time=0.5, interpolate=vizact.easeOutStrong) #set all alerts on map to 100% opaque so that they don't stay semi-transparent for i in [a for m, a in self._alerts.iteritems() if m != 'info']: a.alpha(1) while True: data = yield viztask.waitDirector(self.GetNextMessage) nextKey = data.returnValue if nextKey == 'info': #not verified anymore because info not in _messages self._infoPanel.setText(self._messages[nextKey]) else: self.DisplayAlert(self._messages[nextKey]) if nextKey != 'info': alertObj = self._alerts[nextKey] yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) yield viztask.addAction(alertObj, fade_out) yield viztask.addAction(alertObj, fade_in) else: yield viztask.waitTime(5)
def StartSeparation (self, start): self.oil.addAction(vizact.fadeTo(start, time=.5)) self.water.addAction(vizact.fadeTo(start, time=.5)) if start == 1: pitcher = self.components['pitcher'+self.LR] oilSurf = pitcher.getChild('oilSurface') oilSurf.addAction(vizact.moveTo([0,.5,0], time=10))
def rotate(object_to_rotate, duration, markerstream): """ Rotates a 3d object by a randomly chosen angle between 1 and 360 degree. Args: object_to_rotate: any 3d node object duration: duration of the rotation in seconds markerstream: LSL markerstream to push rotate value Returns: """ rotate_val = random.randint(1, 360) markerstream.push_sample(['ground_rotate']) markerstream.push_sample(['ground_rotate_angle,' + str(rotate_val)]) spinto = vizact.spinTo(euler=(rotate_val, 0, 0), time=0, mode=viz.REL_GLOBAL) fadeout = vizact.fadeTo(0, time=duration) fadein = vizact.fadeTo(1, time=duration) fadeinout = vizact.sequence(fadeout, spinto, fadein) object_to_rotate.addAction(fadeinout) markerstream.push_sample( ['object_fadeInOut, duration:' + str(duration)])
def fadeAndAppear(): ball = viz.add('soccerball.ive') ball.setPosition(2,2,0) yield viztask.addAction( ball, vizact.fadeTo(0,time=2) ) print 'done fading' yield viztask.addAction( ball, vizact.fadeTo(1,time=2) ) print 'done appearing'
def SackAnim (self, sid): #sid is the sack id: {1R, 2R, 1L, or 2L} self._usedSackCounter += 1 sack = self.components['sack'+sid] self.sack_path = self.sackItem.getChild('path'+sid).copy() self.sack_path.setParent(self.factory) #prevent from appearing in MainWindow sack.setParent(self.sack_path, node='path'+sid) self.sack_path.setAnimationSpeed(1) sack.addAction(vizact.waittime(3)) #wait for sack animation endAnimSignal = vizact.signal() trig = endAnimSignal.trigger hide = vizact.method.visible(0) sack.addAction(vizact.parallel(hide, trig)) self.sackPour.addAction(endAnimSignal.wait) # wait for animation before pouring starts self.sackPour.addAction(vizact.method.alpha(1, node='sack_bent')) self.sackPour.addAction(vizact.spinTo(euler=[0,-45,0], time=.75, interpolate=vizact.easeInStrong)) self.sackPour.addAction(vizact.fadeTo(1, begin=0, time=.5, node='olive_flow')) loadSignal = vizact.signal() self.sackPour.addAction(loadSignal.trigger) self.sackPour.addAction(vizact.waittime(5)) self.sackPour.addAction(vizact.fadeTo(0, time=.5)) self.sackPour.addAction(vizact.method.setEuler([0,0,0])) # put it back standing self.mixedPulp.addAction(loadSignal.wait) # wait for olive pouring before pulp appears self.mixedPulp.addAction(vizact.method.visible(1)) #self.mixedPulp.addAction(vizact.fadeTo(1, begin=0, time=1, node='olives')) move = vizact.moveTo([0, 0, 0], time=5) resize = vizact.sizeTo([1, 1, 1], time=5, interpolate=vizact.easeIn) self.mixedPulp.addAction(vizact.parallel(move, resize)) self.sack_path.addAction(loadSignal.wait) self.sack_path.addAction(vizact.method.setAnimationSpeed(-100)) #put sack back
def fadeAndAppear(): global screen, fadeInAndOut, selector, phoneEvent yield viztask.waitTime(3) yield screen.playsound('resources/audio/vibrate.wav', viz.LOOP) selector.enable() fadeInAndOut = vizact.sequence([vizact.fadeTo(0, time=0.5), vizact.fadeTo(1,time=0.5)], viz.PERPETUAL) phoneEvent = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, selectPhone) screen.addAction( fadeInAndOut )
def CoalAction(self, act): #act=1->load, 2->light, 3->waste coalFurnace = self.components['coalfurnace'] if act == 1: #fade in the coals coalFurnace.addAction(vizact.method.visible(1)) coalFurnace.addAction(vizact.fadeTo(1, begin=0, time=1)) elif act == 2: #turn coals red and light fire self.PlayAudio('boiler_light', coalFurnace, viz.PLAY) fireSignal = vizact.signal() coalFurnace.addAction(vizact.fadeTo(viz.RED, time=1)) coalFurnace.addAction(fireSignal.trigger) cPos = coalFurnace.getPosition() coalFurnace.addAction(vizact.moveTo([cPos[0],cPos[1],cPos[2]+.1],time=.5)) self.fire.addAction(fireSignal.wait) self.fire.addAction(vizact.method.visible(1)) self.fire.addAction(vizact.fadeTo(0.75, time=1)) self.fire.addAction(vizact.waittime(4)) self.fire.addAction(vizact.call(self.PlayAudio, 'boiler_furnace')) elif act == 3: #fade out the coals and fire self.AdjustAudio(.5) coalFurnace.addAction(vizact.fadeTo(0.25, time=.5)) self.fire.addAction(vizact.fadeTo(0.25, time=.5)) elif act == 4: #light up the coals and fire again self.AdjustAudio(1) coalFurnace.addAction(vizact.fadeTo(1, time=.5)) self.fire.addAction(vizact.fadeTo(.75, time=.5)) elif act == 5: #fade out the coals and fire completely self.AdjustAudio(0) self.AdjustAudio(1) coalFurnace.addAction(vizact.fadeTo(0, time=.5)) coalFurnace.addAction(vizact.method.setPosition([0,0,0])) coalFurnace.addAction(vizact.method.color(viz.GRAY)) coalFurnace.addAction(vizact.method.visible(0)) self.fire.addAction(vizact.fadeTo(0, time=.5)) self.fire.addAction(vizact.method.visible(0))
def setLooking(self, looking): if looking != self._looking: self._looking = looking if looking: #self.runAction(vizact.sizeTo([1.5]*3, time=0.3, interpolate=vizact.easeOutStrong)) self._render.runAction( vizact.fadeTo(viz.RED, time=0.3, interpolate=vizact.easeOutStrong)) else: #self.runAction(vizact.sizeTo([1.0]*3, time=0.3, interpolate=vizact.easeOutStrong)) self._render.runAction( vizact.fadeTo(viz.WHITE, time=0.3, interpolate=vizact.easeOutStrong))
def logo_start(): sound = viz.addAudio('sound/Omega-FlyHyperspace.wav') sound.play() fadeout = vizact.fadeTo(0, time=2) fadein = vizact.fadeTo(1, time=4) yield viztask.waitTime(2) text3D_G.addAction(fadeout) text3D_L.addAction(fadeout) text3D_GL.addAction(fadeout) text3D_nagnao.addAction(fadeout) quad.addAction(fadein) yield viztask.waitTime(0.1) yield quad.addAction(fadeout)
def EnablePlayer1ForMultiInput (self, secInput): if self._player == 1 and len(self.PLAYERS) == 1 and self._collabAction == '': self._collabAction = ', '+secInput #add second action for 1P conditions self._collabIcon.texture(self._collabTextures[0]) self._collabIcon.addAction(vizact.fadeTo(0, begin=1, time=5, interpolate=vizact.easeInCircular)) self._collabTimer = vizact.ontimer2(5, 1, self.DisablePlayer1ForMultiInput) print "PLAYER1: Preparing to execute multi-input action!"
def TrialCountDownTask(): """Task that count downs to time limit for trial""" # Action for text fading out text_fade = vizact.parallel( vizact.fadeTo(0, time=0.8, interpolate=vizact.easeOut), vizact.sizeTo([1.5, 1.5, 1.0], time=0.8, interpolate=vizact.easeOut)) # Reset time text time_text.clearActions() time_text.alpha(1.0) time_text.color(viz.WHITE) time_text.setScale([1, 1, 1]) time_text.message(str(int(TRIAL_DURATION))) # Countdown from time limit start_time = viz.getFrameTime() last_remain = int(TRIAL_DURATION) while (viz.getFrameTime() - start_time) < TRIAL_DURATION: # Compute remaining whole seconds remain = int( math.ceil(TRIAL_DURATION - (viz.getFrameTime() - start_time))) # Update text if time remaining changed if remain != last_remain: if remain <= 5: time_text.alpha(1.0) time_text.color(viz.RED) time_text.setScale([1] * 3) time_text.runAction(text_fade) viz.playSound('sounds/beep.wav') time_text.message(str(remain)) last_remain = remain # Wait tenth of second yield viztask.waitTime(0.1)
def trialCountDownTask(): """Task that count downs to time limit for trial""" # Action for text fading out text_fade = vizact.parallel( vizact.fadeTo(0,time=0.8,interpolate=vizact.easeOut) ,vizact.sizeTo([.1,.1,.1],time=0.8,interpolate=vizact.easeOut) ) # Reset time text time_text.clearActions() time_text.alpha(1.0) time_text.color(viz.BLACK) time_text.setScale([.05,.05,.05]) time_text.message('REMAINING: ' + str(int(globals_oa.TIME_TO_FIND_IN_SCAVENGER_HUNT)/60)+ ':' + str(int(globals_oa.TIME_TO_FIND_IN_SCAVENGER_HUNT)%60).zfill(2)) # Countdown from time limit start_time = viz.getFrameTime() last_remain = int(globals_oa.TIME_TO_FIND_IN_SCAVENGER_HUNT) while (viz.getFrameTime() - start_time) < globals_oa.TIME_TO_FIND_IN_SCAVENGER_HUNT: # Compute remaining whole seconds remain = int(math.ceil(globals_oa.TIME_TO_FIND_IN_SCAVENGER_HUNT - (viz.getFrameTime() - start_time))) # Update text if time remaining changed if remain != last_remain: if remain <= 5: time_text.alpha(1.0) time_text.color(viz.RED) time_text.setScale([.05]*3) time_text.runAction(text_fade) time_text.message(str(remain/60)+ ':'+str(remain%60).zfill(2)) last_remain = remain # Wait tenth of second yield viztask.waitTime(0.1) print 'OUT OF TIME'
def showVRText(msg, color=[1.0, 1.0, 1.0], distance=2.0, scale=0.05, duration=2.0): """ Display head-locked message in VR, e.g. for instructions. Args: msg (str): Message text color: RBG 3-tuple of color values distance (float): Z rendering distance from MainView scale (float): Text node scaling factor duration (float): Message display duration (seconds) """ # Create 3D text object text = viz.addText3D(msg, scale=[scale, scale, scale], color=color) text.resolution(1.0) text.setThickness(0.1) text.alignment(viz.ALIGN_CENTER) # Lock text to user viewpoint at fixed distance text_link = viz.link(viz.MainView, text, enabled=True) text_link.preTrans([0.0, 0.0, distance]) # Fade text away after <duration> seconds fadeout = vizact.fadeTo(0, time=0.7) yield viztask.waitTime(duration) text.addAction(fadeout) yield viztask.waitActionEnd(text, fadeout) text.remove()
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 fadeAllZone1(): globals_oa.terrainZone1.alpha(0) globals_oa.terrainZone1.visible(viz.ON) worldvizcode.stopEffects() viz.fog(0) fadeInZone1 = vizact.fadeTo(1, time=2) yield globals_oa.terrainZone1.addAction(fadeInZone1)
def ResetMill (self): hatch = self.components['hatch'+self.LR] hatch.addAction(vizact.moveTo([0,0,0], time=1, interpolate=vizact.easeInOut)) self.tankPulp.setPosition(0,0,0) self.components['paste'+self.LR].alpha(0) self.components['paste'+self.LR].visible(0) tank = self.components['tank'+self.LR] tank.setPosition(0,0,0) tank.setEuler(0,0,0) tank.alpha(0) tank.addAction(vizact.method.visible(1)) tank.addAction(vizact.fadeTo(1, begin=0, time=.5)) self.tankPulp.setPosition(0,0,0) self.cart.getChild('pourPulp').remove() self.cart.getChild('pulp').remove() self.cart.addAction(vizact.fadeTo(0, time=.5)) self.cart.addAction(vizact.method.remove())
def FallAction(): """Flashes screen red and animates blur effect""" flash_quad.visible(True) flash_quad.color(viz.RED) fade_out = vizact.fadeTo(viz.BLACK,time=2.5) flash_quad.runAction(vizact.sequence(fade_out,vizact.method.visible(False))) flash_quad.runAction(vizact.call(blurEffect.setDistance,vizact.mix(50,0,time=2.5)),pool=1)
def TrialCountDownTask(): """Task that count downs to time limit for trial""" global revealSelf global manChase # Action for text fading out text_fade = vizact.parallel( vizact.fadeTo(0,time=0.8,interpolate=vizact.easeOut) ,vizact.sizeTo([1.5,1.5,1.0],time=0.8,interpolate=vizact.easeOut) ) # Reset time text time_text.clearActions() time_text.alpha(1.0) time_text.color(viz.WHITE) time_text.setScale([1,1,1]) time_text.message(str(int(TRIAL_DURATION))) # Countdown from time limit start_time = viz.getFrameTime() last_remain = int(TRIAL_DURATION) male2.clearActions() male2.setPosition(2.5,0,7.5) while (viz.getFrameTime() - start_time) < TRIAL_DURATION: if revealSelf: pigeon.clearActions() pos = viz.MainView.getPosition() pigeon.addAction( vizact.walkTo([pos[0], 0, pos[2]]) ) if manChase: male.clearActions() male2.state(2) pos = pigeon.getPosition() male2.addAction( vizact.walkTo([pos[0] - .5, 0, pos[2] - .5])) if male2.getPosition()[2] == (pigeon.getPosition()[2] - .5): #allow for other actions to take place (chase takes precedence) manChase = False male2.state(9) # Compute remaining whole seconds remain = int(math.ceil(TRIAL_DURATION - (viz.getFrameTime() - start_time))) # Update text if time remaining changed if remain != last_remain: if remain <= 5: time_text.alpha(1.0) time_text.color(viz.RED) time_text.setScale([1]*3) time_text.runAction(text_fade) viz.playSound('sounds/beep.wav') time_text.message(str(remain)) last_remain = remain # Wait tenth of second yield viztask.waitTime(0.1)
def FlashScreen(): """Flash screen and fade out""" flash_quad.visible(True) flash_quad.color(viz.WHITE) fade_out = vizact.fadeTo(viz.BLACK, time=FLASH_TIME, interpolate=vizact.easeOutStrong) flash_quad.runAction( vizact.sequence(fade_out, vizact.method.visible(False)))
def FillMat (self): self.paste1.setPosition(0,0,0) self.paste2.setPosition(0,-.02,0) self.paste1.addAction(vizact.method.visible(1)) self.paste1.addAction(vizact.fadeTo(1, time=.5)) self.paste1.addAction(vizact.moveTo([0,-.1,0], time=2)) self.paste2.addAction(vizact.waittime(1)) self.paste2.addAction(vizact.method.visible(1)) self.paste2.addAction(vizact.moveTo([0,0,0], time=2))
def jumpFlash(): # Display jump flash jump_flash.visible(True) jump_flash.runAction( vizact.fadeTo(viz.BLACK, begin=viz.WHITE, time=2.0, interpolate=vizact.easeOutStrong)) jump_flash.addAction(vizact.method.visible(False))
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)
def TogglePit(): """Toggle raising/lowering of pit""" pit.lowered = not pit.lowered pos = pit.positions[pit.lowered] pit.runAction(vizact.moveTo(pos, speed=2.0)) # Use pit color to blend between lower/upper lightmaps duration = pit.getActionInstance().getDuration() color = pit.colors[pit.lowered] pit.runAction(vizact.fadeTo(color, time=duration), pool=1)
def UpdateScore(self, points): curScore = int(self._score.getMessage()) if self._newScore == None: #this ensures correct update of the score self._newScore = curScore + points else: self._newScore += points self.SOUNDS['score'+str(int(points>0))].play() resize = vizact.sizeTo([1.5-(points<0),1.5-(points<0),0], time=.25) #resizes to .5 if deducting points color = [viz.RED, viz.GREEN][points>0] fade = vizact.fadeTo(color, time=.25) self._scoreIcon.addAction(vizact.parallel(resize, fade)) waitAnim = vizact.signal() self._scoreIcon.addAction(waitAnim.trigger) self._score.addAction(waitAnim.wait) self._score.addAction(vizact.method.message(str(self._newScore))) self._score.addAction(vizact.call(self.resetNewScore)) resize = vizact.sizeTo([1,1,0], time=.25) fade = vizact.fadeTo(viz.YELLOW, time=.25) self._scoreIcon.addAction(vizact.parallel(resize, fade))
def TogglePit(): """Toggle raising/lowering of pit""" pit.lowered = not pit.lowered pos = pit.positions[pit.lowered] pit.runAction(vizact.moveTo(pos,speed=2.0)) # Use pit color to blend between lower/upper lightmaps duration = pit.getActionInstance().getDuration() color = pit.colors[pit.lowered] pit.runAction(vizact.fadeTo(color,time=duration),pool=1)
def PasteInTank (self): hatch = self.components['hatch'+self.LR] hatch.addAction(vizact.moveTo([.3-.275, .976-.879, -0.956+.907], time=1, interpolate=vizact.easeInOut)) hatch.addAction(vizact.waittime(1)) openSignal = vizact.signal() hatch.addAction(openSignal.trigger) # code for pouring animation self.pourPulp.addAction(openSignal.wait) self.pourPulp.addAction(vizact.fadeTo(1, time=.5)) self.pourPulp.addAction(vizact.waittime(5)) self.pourPulp.addAction(vizact.fadeTo(0, time=.5)) self.tankPulp.addAction(openSignal.wait) self.tankPulp.addAction(vizact.waittime(.5)) self.tankPulp.addAction(vizact.moveTo([0,.4,0], time=5, interpolate=vizact.easeOut)) self.mixedPulp.addAction(openSignal.wait) # self.mixedPulp.addAction(vizact.fadeTo(0, time=5)) move = vizact.moveTo([0, -.28, 0], time=5, interpolate=vizact.easeOut) resize = vizact.sizeTo([.85,1,.85], time=5, interpolate=vizact.easeOut) self.mixedPulp.addAction(vizact.parallel(move, resize))
def LoadMat (self): self.mat2 = self.mat.copy() self.mat2.setParent(self.components['tray'+self.LR]) self.mat2.pick_parent = True #used in the Player.CheckPickObject() function counter = len(self.loadedMats) self.loadedMats.append(self.mat2) self.mat2.setPosition(0, .24+.01*counter, .01, viz.ABS_PARENT) self.mat2.addAction(vizact.method.visible(1)) self.mat2.addAction(vizact.fadeTo(1, begin=0, time=.5)) counter += 1 return counter
def sellObject(self): line = viz.MainWindow.screenToWorld([0.5, 0.5]) # TODO: Make sure this works for Rift intersection = self.scene.intersect(line.begin, line.end) if intersection.valid: self.foundObj = intersection.object if intersection.object.id in self.selectables: wait = vizact.waittime(self.delay) fadeout = vizact.fadeTo(0, time=self.fadetime) self.foundObj.addAction(wait) self.foundObj.addAction(fadeout) viztask.schedule(self.playAudio()) self.selectables.remove(intersection.object.id)
def exit_grid(e, grids): """ Fades out a grid when a proximity target leaves the chaperone path area. Args: grids: 4 side walls (visible as grids) at the bounding position of the room space. """ #print(e.sensor, "left by proximity target") for grid in grids: grid.visible(viz.ON) grid.addAction(vizact.fadeTo(0, time=0.25))
def __init__(self, x, y, z, zf, shoulder_width,TTC): # Width requires float variable, else round up... self.s_width = float(shoulder_width)/2 self.TTC = float(TTC) self.position1 = [x, y, z] self.position2 = [-x, y, z] self.finalpos1 = [self.s_width, y, zf] self.finalpos2 = [-self.s_width, y, zf] self.act1 = vizact.moveTo(self.finalpos1,self.position1, time = self.TTC) self.act2 = vizact.moveTo(self.finalpos2,self.position2, time = self.TTC) self.disappear = vizact.fadeTo(0,time = 0) self.pause = vizact.waittime(1) self.FagenSequence = vizact.sequence(self.pause,self.disappear)
def enable(self, animate = False): self._enabled = True if animate: fadein = vizact.fadeTo(1.0, time = 1.0) self.mesh.alpha(0.0) self.mesh.visible(viz.ON) self.mesh.addAction(fadein) #self.tooltip.alpha(0.0) #self.tooltip.visible(viz.ON) #self.tooltip.addAction(fadein) else: self.mesh.visible(viz.ON) #self.tooltip.visible(viz.ON) proxManager.addSensor(self._sensor)
def enter_grid(e, grids): """ Fades in a grid when a proximity target enters the chaperone path area. Args: e: triggered sensor event. grids: 4 side walls (visible as grids) at the bounding position of the room space. """ print(e.sensor, "entered by proximity target") for grid in grids: grid.visible(viz.ON) grid.addAction(vizact.fadeTo(1, time=0.25))
def fade_out(object_to_fadeout, duration, markerstream): """ Plays a fade out animation for a given 3D object. Args: object_to_fadeout: 3D object duration: duration: time it takes to fade out the object from 0 to 100% opacity markerstream: LSL markerstream to push start of object rotation """ fadeout = vizact.fadeTo(0, time=duration) object_to_fadeout.addAction(fadeout) markerstream.push_sample(['object_fadeout, duration:' + str(duration)])
def TogglePit(): """Toggle raising/lowering of pit""" pit.lowered = not pit.lowered if pit.lowered == True: cackle_sound.play() pos = pit.positions[pit.lowered] pit.audio_running.play() pit.runAction(vizact.moveTo(pos,speed=2.0)) pit.addAction(vizact.call(pit.audio_stop.play)) pit.addAction(vizact.call(pit.audio_running.pause)) # Use pit color to blend between lower/upper lightmaps duration = pit.getActionInstance().getDuration() color = pit.colors[pit.lowered] pit.runAction(vizact.fadeTo(color,time=duration),pool=1)
def MoveTank (self): #change tank and cart animation depending on mill if self.LR == 'L': offset = .50 self.cart = self.factory.add('models/objects/cart.osgb', pos = [-23.835,0,3.97]) else: offset = 0 self.cart = self.factory.add('models/objects/cart.osgb', pos = [-5.2166,0,4.448]) self.cart.setEuler(360*offset,0,0) #millL: rotate 180 deg cTank = self.cart.insertGroupBelow('tank') cTank.visible(0) cTank.alpha(0, node='pourPulp') tank = self.components['tank'+self.LR] tank.addAction(vizact.moveTo([-0.25+offset,0,-.5], time=1, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.moveTo([-0.25+offset,.5,-.5], time=.5, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.spinTo(euler=[60-270*offset,0,0], time=.5)) #millL: rotate -75 deg tank.addAction(vizact.moveTo([offset,.5,-1.5], time=1, interpolate=vizact.easeInOutSine)) tank.addAction(vizact.moveTo([offset,.2,-1.5], time=.5, interpolate=vizact.easeInSine)) waitLoad = vizact.signal() tank.addAction(waitLoad.trigger) tank.addAction(vizact.method.visible(0)) cTank.addAction(waitLoad.wait) cTank.addAction(vizact.method.visible(1)) self.cart.addAction(waitLoad.wait) self.cart.addAction(vizact.call(self.PlayAudio, 'cart_roll', self.cart, viz.PLAY)) self.cart.addAction(vizact.spinTo(euler=[-20+440*offset,0,0], time=.5)) #millL: rotate to 200 deg moveCart = vizact.moveTo([-14.65-4.9*offset, 0, .75], time=3, interpolate=vizact.easeInOut) rotateCart = vizact.spinTo(euler=[0+360*offset,0,0], time=3) #millL: rotate to 180 deg self.cart.addAction(vizact.parallel(moveCart, rotateCart)) waitMove = vizact.signal() self.cart.addAction(waitMove.trigger) cTank.addAction(waitMove.wait) cTank.addAction(vizact.moveTo([0,1,-0.1], time=1)) cTank.addAction(vizact.spinTo(euler=[0,-90,0], time=1)) cTank.addAction(vizact.fadeTo(1, time=.5, node='pourPulp')) cTank.addAction(vizact.fadeTo(0, time=3, node='pulp', interpolate=vizact.easeInExp)) cTank.addAction(vizact.fadeTo(0, time=.5, node='pourPulp'))
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)
def enable(self, animate=False): """Turn on visibility/set enabled flag""" self._enabled = True if animate: fadein = vizact.fadeTo(1.0, time=1.0) self.mesh.alpha(0.0) self.mesh.visible(viz.ON) self.mesh.addAction(fadein) #self.tooltip.alpha(0.0) #self.tooltip.visible(viz.ON) #self.tooltip.addAction(fadein) else: self.mesh.visible(viz.ON) #self.tooltip.visible(viz.ON) model.proxManager.addSensor(self._sensor)
def flash(self): """Flashes screen red and animates blur effect""" with viz.cluster.MaskedContext(self._clientMask): self._flashSphere.visible(True) self._flashSphere.color(self._color) self._flashSphere.disable(viz.LIGHTING) self._flashSphere.disable(viz.SHADOWS) self._flashSphere.disable(viz.SHADOW_CASTING) self._flashSphere.enable(viz.BLEND) self._flashSphere.disable(viz.DEPTH_TEST) self._flashSphere.disable(viz.DEPTH_WRITE) self._flashSphere.alpha(0.5) self._flashSphere.drawOrder(101, bin=viz.BIN_TRANSPARENT) fade_out = vizact.fadeTo(0, begin=.3, time=1) self._flashSphere.runAction( vizact.sequence(fade_out, vizact.method.visible(False)))
def myTask(): sound = viz.addAudio('sound/samplerButton.wav') sound.play() fadeout = vizact.fadeTo(0, time=2) yield text3D.addAction(fadeout) yield text3D.disable(True) yield grid.addAction(fadeout) yield viztask.waitTime(3) # ここでGLNAGANOのロゴ表示 import opning yield opning.Logo() yield viztask.waitTime(10) import promothion promothion
def TogglePit(): """Toggle raising/lowering of pit""" pit.lowered = not pit.lowered pos = pit.positions[pit.lowered] pit.audio_running.play() pit.runAction(vizact.moveTo(pos,speed=2.0)) pit.addAction(vizact.call(pit.audio_stop.play)) pit.addAction(vizact.call(pit.audio_running.pause)) #activates the music if pit.lowered: pit.soundtrack.play() else: pit.soundtrack.stop() duck.state(2) # Use pit color to blend between lower/upper lightmaps duration = pit.getActionInstance().getDuration() color = pit.colors[pit.lowered] pit.runAction(vizact.fadeTo(color,time=duration),pool=1)
def H2CO3formation(): global bigCO2, bigH2O, h2co3molecule x, y, z = bigH2O.getPosition() x -= 0.5 moveToH2O = vizact.moveTo([x, y, z], speed=0.75) yield viztask.addAction(bigCO2, moveToH2O) # yield viztask.waitTime(.05) h2co3_x = x + 1.5 h2co3_y = y + 0.18 h2co3_z = z + 0.05 h2co3molecule.setPosition(h2co3_x, h2co3_y, h2co3_z) # Fade molecules from bigCO2 and bigH2O to H2CO3 animation fadeOut = vizact.fadeTo(0, 0.5) h2co3molecule.visible(viz.ON) h2co3molecule.setAnimationTime(8.9) # starts animation at 17.8 seconds h2co3molecule.setAnimationLoopMode(0) viztask.waitTime(0.5) bigCO2.visible(viz.OFF) bigH2O.visible(viz.OFF)
def crystalBallScene(): global globeScene, crystalBall globeScene.enable(viz.RENDERING) viz.fog(0.2) crystalBall = globeScene.getChild('preview.osgb') crystalBall.alpha(0.7) #insideCrystal = globeScene.getChild('preview2.osgb') crystalBall.disable(viz.RENDERING) #insideCrystal.disable(viz.RENDERING) yield fader.fadeInTask() #globeScene.playsound('background.wav') globe = globeScene.getChild('earthGlobe.OSGB') spinForever = vizact.spin(0,-1,0, 25, dur = viz.FOREVER) spinForever2 = vizact.spin(0,1,0, 20, dur = viz.FOREVER) spinSome = vizact.spin(0,-1,0, 30, dur=5) globe.addAction(spinSome) crystalBall.addAction(spinForever) #insideCrystal.addAction(spinForever2) yield viztask.waitTime(5) fadeOutGlobe = vizact.fadeTo(0, speed = .7) globe.addAction(fadeOutGlobe) crystalBall.enable(viz.RENDERING) #insideCrystal.enable(viz.RENDERING) yield viztask.waitTime(1) globe.remove() manager = vizproximity.Manager() manager.setDebug(False) #make true to see the outline of the proximity sensor rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) ballSensor = vizproximity.Sensor(vizproximity.Sphere(1.5, center=[0,5.5,0]), source=crystalBall) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(ballSensor) #yield vizproximity.waitEnter(ballSensor) yield viztask.waitKeyDown('/') globals_oa.AUDIO_SUCCESS.play() yield fader.fadeOutTask() globeScene.remove() crystalBall.remove()
def TrialCountDownTask(): """Task that count downs to time limit for trial""" # Action for text fading out text_fade = vizact.parallel( vizact.fadeTo(0,time=0.8,interpolate=vizact.easeOut) ,vizact.sizeTo([1.5,1.5,1.0],time=0.8,interpolate=vizact.easeOut) ) # Reset time text time_text.clearActions() time_text.alpha(1.0) time_text.color(viz.WHITE) time_text.setScale([1,1,1]) time_text.message(str(int(TRIAL_DURATION))) # Countdown from time limit start_time = viz.getFrameTime() last_remain = int(TRIAL_DURATION) while (viz.getFrameTime() - start_time) < TRIAL_DURATION: # Compute remaining whole seconds remain = int(math.ceil(TRIAL_DURATION - (viz.getFrameTime() - start_time))) # Update text if time remaining changed if remain != last_remain: if remain <= 5: time_text.alpha(1.0) time_text.color(viz.RED) time_text.setScale([1]*3) time_text.runAction(text_fade) viz.playSound('sounds/beep.wav') time_text.message(str(remain)) last_remain = remain # Wait tenth of second yield viztask.waitTime(0.1)
def crystalBallSceneGo(): global crystalBall globals_oa.globeScene.enable(viz.RENDERING) # viz.fog(0.2) #add globe, spinning crystalBall = globals_oa.globeScene.getChild('crystalBall.osgb') crystalBall.alpha(.7) spinForever = vizact.spin(0,-1,0, 25, dur = viz.FOREVER) crystalBall.addAction(spinForever,0) # fadeInBall = vizact.fadeTo(.7, time = 60) # crystalBall.addAction(fadeInBall,1) globe = globals_oa.globeScene.getChild('earthGlobe.OSGB') spinSome = vizact.spin(0,-1,0, 30, dur=viz.FOREVER) globe.addAction(spinSome,2) yield fader.fadeInTask() #globals_oa.globeScene.playsound('background.wav') # spinForever2 = vizact.spin(0,1,0, 20, dur = viz.FOREVER) yield viztask.waitTime(5) fadeOutGlobe = vizact.fadeTo(0,time = 5) globe.addAction(fadeOutGlobe,3) yield viztask.waitTime(8) globe.remove() manager = vizproximity.Manager() manager.setDebug(False) #make true to see the outline of the proximity sensor rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) ballSensor = vizproximity.Sensor(vizproximity.Sphere(1.5, center=[0,5.5,0]), source=crystalBall) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(ballSensor) yield vizproximity.waitEnter(ballSensor) # yield viztask.waitKeyDown('/') globals_oa.AUDIO_SUCCESS.play() yield fader.fadeOutTask() globals_oa.globeScene.remove() crystalBall.remove()
def Pressing (self): # start moving the piston upwards (not sure why it's working with Z value) self.piston.addAction(vizact.moveTo([0,1.2,0], time=60, interpolate=vizact.easeOutCubic)) stopStrain=vizact.signal() # signal when the straining finished (60 secs) # self.mats.addAction(startSqueeze.trigger) self.mats.addAction(vizact.sizeTo([1,.5,1], time=60, interpolate=vizact.easeOutCubic)) self.mats.addAction(stopStrain.trigger) # oil straining starts 2'' after squeezing starts and stops 3'' after squeezing stops self.oilStrain.addAction(vizact.waittime(2)) # start straining after 2 secs startSqueeze = vizact.signal() # signal when straining starts self.oilStrain.addAction(startSqueeze.trigger) self.oilStrain.addAction(vizact.method.visible(1)) self.oilStrain.addAction(vizact.fadeTo(1, begin=0, time=1)) self.oilStrain.addAction(stopStrain.wait) self.oilStrain.addAction(vizact.fadeTo(0, time=3)) # oil gathering starts when mats reach the top and finishes 5'' after strain is over self.oilGathered.addAction(startSqueeze.wait) self.oilGathered.addAction(vizact.method.visible(1)) self.oilGathered.addAction(vizact.fadeTo(1, begin=0, time=5)) startDrop = vizact.signal() # signal when the drop should start (5'' after oil gathered) self.oilGathered.addAction(startDrop.trigger) self.oilGathered.addAction(stopStrain.wait) self.oilGathered.addAction(vizact.waittime(5)) # wait 5 more secs for gathered oil to drop self.oilGathered.addAction(vizact.fadeTo(0, time=1)) self.oilGathered.addAction(vizact.method.visible(0)) # oil drop stars 5'' after oil is gathered and finishes 5'' after strain is over self.oilDrop.addAction(startDrop.wait) # start drop and tank filling after 5 secs self.oilDrop.addAction(vizact.method.visible(1)) self.oilDrop.addAction(vizact.fadeTo(1, begin=0, time=1)) self.oilDrop.addAction(stopStrain.wait) self.oilDrop.addAction(vizact.waittime(5)) self.oilDrop.addAction(vizact.fadeTo(0, time=1)) self.oilDrop.addAction(vizact.method.visible(0)) # oil in can starts filling up when oil drop starts (45'') self.oilSurface.addAction(startDrop.wait) self.oilSurface.addAction(vizact.moveTo([0,0,0], time=45))
def AnkleTracking(flagL, flagR, LeftAnkle, RightAnkle, LeftGTO, RightGTO, ankleHeightL, ankleHeightR, successL_count, successR_count): global start_L, start_R, scoreText_L, scoreText_R # Show steps # Text_3d.message('{}'.format(numsteps)) # fadeOut4 = vizact.fadeTo(0,time=0.5) # Text_3d.addAction(fadeOut4) positionL = qualisys.getMarker(LeftAnkle).getPosition() #print positionL positionR = qualisys.getMarker(RightAnkle).getPosition() #print positionR analog = qualisys.getAnalog(0) #print analog ForcePlates = analog.getData() #print ForcePlates calibrationFz = 1000 # 3,3 value in Bertec calibation matrix GRFL = ForcePlates[3] * calibrationFz GRFR = ForcePlates[10] * calibrationFz #print "Left", GRFL #print "Right", GRFR positionL_Hip = qualisys.getMarker(LeftGTO).getPosition() positionR_Hip = qualisys.getMarker(RightGTO).getPosition() temp_stepLengthLeft = positionL[0] - positionR[0] temp_stepLengthRight = positionR[0] - positionL[0] # LEFT LEG if (50 < GRFL < 2000): # --> leg is in stance phase, hide ankle location markerposL = positionL[0] - positionR[0] markerL = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=(markerposL, positionL[1], positionL[2])) ankleHeightL = positionL[1] fadeOut = vizact.fadeTo(0, time=0.00) markerL.addAction(fadeOut) if (flagL == 1): if (temp_stepLengthLeft > 0): flagL = 0 if (abs(markerposL - median_stepLengthLeft) < 8 * sd_Left + 0.01) & (scoreText_L == True): # if (positionL[1] < ankleHeightL and # abs (positionL[2] - positionL_Hip[2] ) < 0.05): # successL_score = int( round(10 - 10 * abs(1 - (markerposL / SL_Left)))) # save_successL_count.append(successL_score) # print total_successR_count # f = open('C:\Users\User\Documents\Natalia\QTM\save_successL_count.txt','w') # json.dump(save_successL_count,f) # f.close() print successL_score Text_3d.message('{}'.format(successL_score)) # fadeOut = vizact.fadeTo(0,time=0.2) scoreText_L = False ##################################################### ###### ADJUST BASED ON TM SPEED, FOR SPEED>0.5 USE ~.5 ##### FOR SPEED < 0.5 USE ~.7 ####################### ##################################################### # time.sleep(.15) elif (GRFL < 50): # --> leg is in swing phase, track ankle location markerposL = positionL[0] - positionR[0] markerL = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=(markerposL, positionL[1], positionL[2])) fadeOut = vizact.fadeTo(0, time=0.00) markerL.addAction(fadeOut) temp_stepLengthLeft = positionL[0] - positionR[0] flagL = 1 scoreText_L = True # RIGHT LEG if (50 < GRFR < 2000): # --> leg is in stance phase, hide ankle location markerposR = positionR[0] - positionL[0] markerR = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=(markerposR, positionR[1], positionR[2])) ankleHeightR = positionR[1] fadeOut = vizact.fadeTo(0, time=0.00) markerR.addAction(fadeOut) if (flagR == 1): if (temp_stepLengthRight > 0): flagR = 0 start_R.append(time.clock()) if (abs(median_stepLengthRight - markerposR) < 8 * sd_Right + 0.01) & (scoreText_R == True): # if (positionR[1] < ankleHeightR and # abs (positionR[2] - positionR_Hip[2] ) < 0.05): # successR_score = int( round(10 - 10 * abs(1 - (markerposR / SL_Right)))) save_successR_count.append(successR_score) # print total_successR_count # f = open('C:\Users\User\Documents\Natalia\QTM\save_successR_count.txt','w') # json.dump(save_successR_count,f) # f.close() Text_3d_right.message('{}'.format(successR_score)) # ##################################################### ###### ADJUST BASED ON TM SPEED, FOR SPEED>0.5 USE ~.5 ##### FOR SPEED < 0.5 USE ~.7 ####################### ##################################################### scoreText_R = False elif (GRFR < 50): # --> leg is in swing phase, track ankle location markerposR = positionR[0] - positionL[0] markerR = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=(markerposR, positionR[1], positionR[2])) fadeOut = vizact.fadeTo(0, time=0.00) markerR.addAction(fadeOut) flagR = 1 scoreText_R = True
def FlashScreen(): """Flash screen and fade out""" flash_quad.visible(True) flash_quad.color(viz.WHITE) fade_out = vizact.fadeTo(viz.BLACK,time=FLASH_TIME,interpolate=vizact.easeOutStrong) flash_quad.runAction(vizact.sequence(fade_out,vizact.method.visible(False)))
def jumpSignal(): # jump_signal.visible(0) jump_signal.visible(1) jump_signal.runAction(vizact.fadeTo(0.8, begin=0, time=2))
def StepLength(COP_L, COP_R, width=0.05, length=0.05): global flagL, flagR, SL_Left, SL_Right, sd_Left, sd_Right, successL_count, successR_count, start_L, start_R # offset factors // QTM options > Force Data > Calibration Xoff = 0.2795 # X offset (for right force plate, invert to be -0.2795) Yoff = 0.889 h = 0 # Zoff = h FPtemp = qtm_receive() # force plate data # left force plate COP_L = [0,0] FxL = FPtemp[0] FyL = FPtemp[1] GRFL = FPtemp[2] MxL = FPtemp[3] MyL = FPtemp[4] # right force plate COP_R = [0,0] FxR = FPtemp[6] FyR = FPtemp[7] GRFR = FPtemp[8] MxR = FPtemp[9] MyR = FPtemp[10] # LEFT LEG if ( 80<GRFL<2000 ): # stance phase... if (flagL == 1): # swing phase flag flagL = 0 # not swing phase anymore start_L.append(time.clock()) #want to time btw heel strike # print start_L # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8162, +Xplate + 0.7798] COP_L = [ (-Yoff + (((-h*FyL)+MxL)/GRFL) + 0.8162) , (Xoff + (((-h*FxL)-MyL)/GRFL) + 0.7798) ] COP_R = [ (-Yoff + (((-h*FyR)+MxR)/GRFR) + 0.8154) ,(-Xoff + (((-h*FxR)-MyR)/GRFR) + 0.2124) ] SL_L = COP_L[0]-COP_R[0] #left step length markerL = vizshape.addQuad(size=(length, width),axis= -vizshape.AXIS_Y,cullFace=False,cornerRadius=0.05,pos=[SL_L,0.02,0.7]) fadeOut = vizact.fadeTo(0,time=0.7) markerL.addAction(fadeOut) # stepLengthLeft.append(SL_L) # step length list #stepLengthLeft.sort(reverse = True) # greatest first # print "stepLengthLeft", stepLengthLeft # should not overlap with the previous trial # filepath='C:\\Users\\User\\Documents\\Chang\\LeftStepLength'+test_no+filename # f = open(filepath,'w') # json.dump(stepLengthLeft,f) # f.close() #print "COP_L x", COP_L[0], "COP_R x", COP_R[0] #print "left step length", SL_L # if abs(SL_L-SL_Left) <= (2*sd_Left + 0.01): # success message # successL = viz.addText('Success!', parent=viz.SCREEN, scene = viz.MainScene, color=viz.GREEN, fontSize=80, pos=[0.2,0.05,0]) # fadeOut4 = vizact.fadeTo(0,time=0.5) # successL.addAction(fadeOut4) # # successL_count += 1 ## f = open('C:\Users\User\Documents\Chang\save_successL_count.txt','w') ## json.dump(successL_count,f) ## f.close() # # print "successL_count", successL_count ## time.sleep(0.15) elif ( GRFL<=80 ): # swing phase... flagL = 1 # RIGHT LEG if ( 80<GRFR<2000 ): # stance phase... if (flagR == 1): # swing phase flag flagR = 0 # not swing phase anymore start_R.append(time.clock()) # print "startR",start_R # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8154, +Xplate + 0.2124] COP_R = [ (-Yoff + (((-h*FyR)+MxR)/GRFR) + 0.8154) ,(-Xoff + (((-h*FxR)-MyR)/GRFR) + 0.2124) ] COP_L = [ (-Yoff + (((-h*FyL)+MxL)/GRFL) + 0.8162) , (Xoff + (((-h*FxL)-MyL)/GRFL) + 0.7798) ] SL_R = COP_R[0]-COP_L[0] #right step length markerR = vizshape.addQuad(size=(length, width),axis= -vizshape.AXIS_Y,cullFace=False,cornerRadius=0.05,pos=[SL_R,0.02,0.3]) fadeOut = vizact.fadeTo(0,time=0.7) markerR.addAction(fadeOut) # stepLengthRight.append(SL_R) # step length list #stepLengthRight.sort(reverse = True) # greatest first # print "stepLengthRight", stepLengthRight # filepath2='C:\\Users\\User\\Documents\\Chang\\RightStepLength'+test_no+filename # f1 = open(filepath2,'w') # json.dump(stepLengthRight,f1) # f1.close() #print "COP_R x", COP_R[0], "COP_L x", COP_L[0] #print "right step length", SL_R # if abs(SL_R-SL_Right) <= (2*sd_Right + 0.01): # success message # successR = viz.addText('Success!', parent=viz.SCREEN, scene = viz.MainScene, color=viz.BLUE, fontSize=80, pos=[0.55,0.05,0]) # fadeOut5 = vizact.fadeTo(0,time=0.5) # successR.addAction(fadeOut5) # # successR_count += 1 ## f = open('C:\Users\User\Documents\Chang\save_successR_count.txt','w') ## json.dump(successR_count,f) ## f.close() # print "successR_count", successR_count # time.sleep(0.15) elif ( GRFR<=80 ): # swing phase... flagR = 1
viz.SCREEN) textScreen.alignment(viz.ALIGN_RIGHT_BOTTOM) textScreen.setScale(0.2, 0.2, 0.2) textScreen.setPosition([0.95, 0.05, 0]) def textScreen2(): textScreen = viz.addText( 'school bus, students who are travelling in this bus are rich and excellent in studies', viz.SCREEN) textScreen.alignment(viz.ALIGN_RIGHT_BOTTOM) textScreen.setPosition([0.95, 0.05, 0]) fadeInOut = vizact.sequence(vizact.fadeTo(1, time=1), vizact.waittime(4), vizact.fadeTo(0, time=1)) def landmark(): object = viz.pick() if object.valid() and object == bomb_in_school: textbox1 = viz.addTextbox() #Make it twice as long. textbox1.length(2) textbox1.setPosition(.5, .5) #Have it grow when text reaches its boundary. textbox1.overflow(viz.OVERFLOW_GROW)
def FadeOut(): yield viztask.waitCall(blackScreen.runAction, vizact.fadeTo( 1.0, time=2.0)) # fade out black screen effect
def StepLength( flagL, flagR, stepLengthLeft, stepLengthRight, L=LeftAnkle, R=RightAnkle, width=0.05, length=0.05 ): # R: index in QTM for ankle marker right, L = index in QTM for ankle marker left positionL = qualisys.getMarker(L).getPosition() positionR = qualisys.getMarker(R).getPosition() analog = qualisys.getAnalog(0) ForcePlates = analog.getData() calibrationFz = 1000 # 3,3 value in Bertec calibation matrix GRFL = ForcePlates[3] * calibrationFz GRFR = ForcePlates[10] * calibrationFz temp_stepLengthLeft = positionL[0] - positionR[0] temp_stepLengthRight = positionR[0] - positionL[0] # LEFT LEG if (GRFL > 30): # --> leg is in stance phase, hide ankle location markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=positionL) if (flagL == 1): if (temp_stepLengthLeft > 0): stepLengthLeft.append(temp_stepLengthLeft) flagL = 0 stepLengthLeft.sort(reverse=True) # print stepLengthLeft # max_stepLengthLeft = stepLengthLeft[:100] filepath = 'C:\\Users\\User\\Documents\\Chang\\LeftStepLength' + filename f = open(filepath, 'w') json.dump(stepLengthLeft, f) f.close() # f_test = open('C:\Users\User\Documents\Natalia\QTM\LeftStepLengthtest.txt','w') # for item in max_stepLengthLeft: # f_test.write("%s\n" % item) # mean_stepLengthLeft = float(sum(max_stepLengthLeft)) / len(max_stepLengthLeft) # sd_Left = float(((sum(sd_Left_temp))/len(max_stepLengthLeft))**0.5) # f1 = open('C:\Users\User\Documents\Natalia\QTM\Left_MeanStepLength.txt','w') # json.dump(mean_stepLengthLeft,f1) # f1.close() else: # --> leg is in swing phase, track ankle location markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=positionL) fadeOut = vizact.fadeTo(0, time=.05) markerL.addAction(fadeOut) temp_stepLengthLeft = positionL[0] - positionR[0] flagL = 1 # RIGHT LEG if (GRFR > 30): # --> Right is in stance phase, hide ankle location markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=positionR) if (flagR == 1): if (temp_stepLengthRight > 0): stepLengthRight.append(temp_stepLengthRight) flagR = 0 stepLengthRight.sort(reverse=True) max_stepLengthRight = stepLengthRight[:100] print stepLengthRight filepath2 = 'C:\\Users\\User\\Documents\\Chang\\RightStepLength' + filename f1 = open(filepath2, 'w') json.dump(stepLengthRight, f1) f1.close() # f_testR = open('C:\Users\User\Documents\Natalia\QTM\RightStepLengthtest.txt','w') # for item in max_stepLengthRight: # f_testR.write("%s\n" % item) # mean_stepLengthRight = float(sum(max_stepLengthRight)) / len(max_stepLengthRight) # f3 = open('C:\Users\User\Documents\Natalia\QTM\Right_MeanStepLength.txt','w') # json.dump(mean_stepLengthRight,f3) # f3.close() else: # --> leg is in swing phase, track ankle location markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=positionR) fadeOut = vizact.fadeTo(0, time=.05) markerR.addAction(fadeOut) temp_stepLengthRight = positionR[0] - positionL[0] flagR = 1
# Proximity code manager = vizproximity.Manager() # Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView) manager.addTarget(target) # Add scene1 proximity sensor manager.addSensor(scene1.stoneSensor) scaleAction = vizact.sequence([ vizact.sizeTo(size=[1.3, 1.3, 1.3], time=1), vizact.sizeTo(size=[1, 1, 1], time=1) ], viz.FOREVER) fadeAction = vizact.sequence([ vizact.fadeTo([0.63, 0.32, 0.18], time=2), vizact.fadeTo(viz.WHITE, time=2) ], viz.FOREVER) def onGrab(e): e.grabbed.runAction(fadeAction, pool=1) e.grabbed.runAction(scaleAction, pool=2) if scene2.getActive(): scene2.music.play() viz.window.setPolyMode(viz.POLY_POINT) def onRelease(e): e.released.endAction(pool=viz.ALL_POOLS) pos = viz.MainView.getPosition()
def __init__(self, participant): self.visual_maze_instruktionen = { 'baseline_start': 'Zu Beginn wird eine Zusatzmessung aufgenommen.\n' 'Es geht gleich automatisch weiter...', 'baseline_standing': 'Halten Sie Ihre Augen offen und\n' 'entspannen sich.\n' 'Mit einem Klick,\n' 'beginnt die Messung', 'baseline_thrusting': 'Halten Sie Ihre Augen offen und\n' 'tasten wiederholt nach vorne.\n' 'Mit einem Klick,\n' 'beginnt die Messung.', 'baseline_end': 'Bitte beim Versuchsleiter melden.' } # call constructor of superclass super(VisualMaze, self).__init__(participant) #ground = viz.add('tut_ground.wrl') # Add ground # create scene of the experiment self.subject_id = participant.id self.scene = VisualMazeScene(participant.maze_config, self.subject) self.maze = None self.light = vizfx.addDirectionalLight(euler=(0, 90, 0), color=viz.WHITE) self.hand_tracker_id = None self.arm_tracker_id = None self.torso_tracker_id = None # permuted list of all 4 trial mazes L Z U S, with 24 subjects 1 permutation cycle is complete self.trial_list_all = [['Z', 'L', 'U', 'S'], ['L', 'Z', 'U', 'S'], ['U', 'L', 'Z', 'S'], ['L', 'U', 'Z', 'S'], ['Z', 'U', 'L', 'S'], ['U', 'Z', 'L', 'S'], ['U', 'Z', 'S', 'L'], ['Z', 'U', 'S', 'L'], ['S', 'U', 'Z', 'L'], ['U', 'S', 'Z', 'L'], ['Z', 'S', 'U', 'L'], ['S', 'Z', 'U', 'L'], ['S', 'L', 'U', 'Z'], ['L', 'S', 'U', 'Z'], ['U', 'S', 'L', 'Z'], ['S', 'U', 'L', 'Z'], ['L', 'U', 'S', 'Z'], ['U', 'L', 'S', 'Z'], ['Z', 'L', 'S', 'U'], ['L', 'Z', 'S', 'U'], ['S', 'Z', 'L', 'U'], ['Z', 'S', 'L', 'U'], ['L', 'S', 'Z', 'U'], ['S', 'L', 'Z', 'U']] # permuted list of all 3 objects to test in rvd task (G = Global Landmark, L = Local, S = Start) with 24 subjects 4 permutation cycles are complete self.rvd_list_all = [['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G']] # # keys for video recording # vidname = str(participant.id) + '_' + str(participant.control_style) + '.avi' # viz.setOption('viz.AVIRecorder.fps','25') # viz.setOption('viz.AVIRecorder.maxWidth','1280') # viz.setOption('viz.AVIRecorder.maxHeight', '720') # vizact.onkeydown('b', viz.window.startRecording, vidname) # vizact.onkeydown('e', viz.window.stopRecording) # ---- collision event params ---- # # objects handling current state of visual maze experiment # wall enter and exit collision event callbacks self.hand_in_wall = False self.head_in_wall = False # placeholders for visual feedback functions self.feedback_hand = None self.feedback_start_time = 0 self.feedback_duration = 0 self.new_touch_allowed = True self.feedback = vizact.sequence(vizact.waittime(0.5), vizact.fadeTo( 0, time=.2)) # event is 700 ms self.help_sphere = vizshape.addSphere(.1) self.help_sphere.color(viz.GREEN) self.help_sphere.visible(viz.OFF) # ---- Bookkeeping variables for behavioral data collection ---- # self.current_maze = None self.current_trial_run = None # ---- Reward tracking variables ---- # self.hand_hits = 0 self.head_hits = 0 self.local_landmark_hits = 0 self.duration = 0 self.start_return = 0 # pointing task self.pointing_task_on = False # RVD task objects self.rvd_task_on = False self.in_rvd_table = False self.rvd_table = vizshape.addCube(1) self.rvd_table.alpha(0.3) # make surface barely visible self.rvd_table.visible(viz.OFF) self.start_sign = viz.add('resources/start.dae') self.start_sign.setScale(.02, .02, .02) self.start_sign.visible(viz.OFF)
def FadeIn(): yield viztask.waitCall(blackScreen.runAction, vizact.fadeTo( 0.0, time=2.0)) # fade in black screen effect
def StepLength(filename, stepLengthLeft, stepLengthRight, COP_L, COP_R, width=0.05, length=0.05): global flagL, flagR analog = qualisys.getAnalog(0) #print "analog", analog ForcePlates = analog.getData() # [Zero, Fx1, Fy1, ..., My2, Mz2] #print "ForcePlates", ForcePlates # calibration/offset factors // QTM options > Force Data > Calibration Fcal = (500, 500, 1000, 800, 400, 400 ) # Fx,Fy,Fz,Mx,My,Mz // Calibration Matrix Xoff = 0.2795 # X offset (for right force plate, invert to be -0.2795) Yoff = 0.889 h = 0 # Zoff = h # left force plate COP_L = [0, 0] FxL = ForcePlates[1] * Fcal[0] FyL = ForcePlates[2] * Fcal[1] GRFL = ForcePlates[3] * Fcal[2] MxL = ForcePlates[4] * Fcal[3] MyL = ForcePlates[5] * Fcal[4] # right force plate COP_R = [0, 0] FxR = ForcePlates[8] * Fcal[0] FyR = ForcePlates[9] * Fcal[1] GRFR = ForcePlates[10] * Fcal[2] MxR = ForcePlates[11] * Fcal[3] MyR = ForcePlates[12] * Fcal[4] # LEFT LEG if (200 < GRFL < 2000): # stance phase...# Does it need to change if (flagL == 1): # swing phase flag flagL = 0 # not swing phase anymore # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8162, +Xplate + 0.7798] COP_L = [(-Yoff + (((-h * FyL) + MxL) / GRFL) + 0.8162), (Xoff + (((-h * FxL) - MyL) / GRFL) + 0.7798)] COP_R = [(-Yoff + (((-h * FyR) + MxR) / GRFR) + 0.8154), (-Xoff + (((-h * FxR) - MyR) / GRFR) + 0.2124)] SL_L = COP_L[0] - COP_R[0] #left step length markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=[SL_L, 0.15, 0.7]) fadeOut = vizact.fadeTo(0, time=0.7) markerL.addAction(fadeOut) #print "COP_L x", COP_L[0], "COP_R x", COP_R[0] print "step length", SL_L stepLengthLeft.append(SL_L) # step length list #stepLengthLeft.sort(reverse = True) # greatest first #print "stepLengthLeft", stepLengthLeft #should not overlap with the previous trial filepath = 'C:\\Users\\User\\Documents\\Chang\\LeftStepLength' + filename f = open(filepath, 'w') json.dump(stepLengthLeft, f) f.close() elif (GRFL <= 100): # swing phase... flagL = 1 # RIGHT LEG if (200 < GRFR < 2000): # stance phase... if (flagR == 1): # swing phase flag flagR = 0 # not swing phase anymore # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8154, +Xplate + 0.2124] COP_R = [(-Yoff + (((-h * FyR) + MxR) / GRFR) + 0.8154), (-Xoff + (((-h * FxR) - MyR) / GRFR) + 0.2124)] COP_L = [(-Yoff + (((-h * FyL) + MxL) / GRFL) + 0.8162), (Xoff + (((-h * FxL) - MyL) / GRFL) + 0.7798)] SL_R = COP_R[0] - COP_L[0] #right step length markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=[SL_R, 0.15, 0.3]) fadeOut = vizact.fadeTo(0, time=0.7) markerR.addAction(fadeOut) #print "COP_R x", COP_R[0], "COP_L x", COP_L[0] print "step length", SL_R stepLengthRight.append(SL_R) # step length list #stepLengthRight.sort(reverse = True) # greatest first print "stepLengthRight", stepLengthRight filepath2 = 'C:\\Users\\User\\Documents\\Chang\\RightStepLength' + filename f1 = open(filepath2, 'w') json.dump(stepLengthRight, f1) f1.close() elif (GRFR <= 100): # swing phase... flagR = 1