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 GameFinish (self, delay): self.info = vizinfo.add(self.tooltips['congrats']) self.info.visible(0) self.info.icon(viz.add('textures/c-olive_icon.png')) self.info.add(viz.TEXT3D, self.tooltips['finish']+'\n'+self.tooltips['produce'] % self._oil.getMessage()) self.info.add(viz.TEXT3D, self.tooltips['stats']) self.info.translate(0.1,0.95) self.info.alignment(vizinfo.UPPER_LEFT) self.info.scale(2.4,2.6) self.info.messagecolor(100,100,0) self.info.bgcolor(viz.BLACK, 0.8) self.info.bordercolor([100,100,0], .9) points = self.info.add(viz.TEXQUAD, self.tooltips['score']+': %s' % self._total.getMessage()) points.texture(viz.add('textures/total_icon.png')) time = self.info.add(viz.TEXQUAD, self.tooltips['time']+': %s' % self.ConvertTime(viz.tick())) time.texture(viz.add('textures/time_icon.png')) self.info.shrink() #hide all other panels self._scorePanel.visible(0) self._infoPanel.visible(0) self._alertPanel.visible(0) for p in self.PLAYERS.values(): p._infoPanel.visible(0) p._alertPanel.visible(0) p._hud.visible(0) time.addAction(vizact.waittime(delay)) time.addAction(vizact.call(self.info.visible, 1)) time.addAction(vizact.waittime(.1)) time.addAction(vizact.call(self.PlayVictory)) time.addAction(vizact.call(self.info.expand))
def makeMove(): walk_over = vizact.walkTo([-.5,0,-2.2]) yield viztask.addAction( female, walk_over ) female.state(1) wait = vizact.waittime(3) yield male.addAction(wait) react()
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 reachTeapotTask(): tryNum = 0 while(True) : global reachedTeapot reachedTeapot = False global avoidCat avoidCat = True # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) instructions.setText("Welcome!") instructions.runAction(DelayHide) yield viztask.waitTime(5) instructions.runAction(Show) instructions.setText("Now, try to get the teapot without touching the cat in 15 seconds!") instructions.runAction(DelayHide) yield viztask.waitTime(15) instructions.runAction(Show) instructions.setText("Reached Teapot: "+str(reachedTeapot)+" Avoided Cat: "+str(avoidCat)) yield viztask.waitTime(5) yield ClapTask() tryNum = tryNum + 1 data = 'Try '+str(tryNum)+' Reached Teapot: '+str(reachedTeapot)+' Avoided Cat: '+str(avoidCat)+'\n' teapot_game_data.write(data) instructions.setText("Now, try again or exit to leave!") yield viztask.waitTime(5)
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 pigeonsFeed(): random_speed = vizact.method.setAnimationSpeed(0,vizact.randfloat(0.7,1.5)) random_walk = vizact.walkTo(pos=[vizact.randfloat(-4,4),0,vizact.randfloat(3,7)]) random_animation = vizact.method.state(vizact.choice([1,3],vizact.RANDOM)) random_wait = vizact.waittime(vizact.randfloat(5.0,10.0)) pigeon_idle = vizact.sequence( random_speed, random_walk, random_animation, random_wait, viz.FOREVER) for pigeon in pigeons: pigeon.addAction(pigeon_idle)
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 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 __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 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 destinationsTask(): # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) yield viztask.waitTime(6) instructions.setText("Walk around!") instructions.runAction(DelayHide) yield viztask.waitTime(30) instructions.runAction(Show) instructions.setText("Thank you for your participation :)") #Show results of experiment print 'Avoided avatar:',avoidAvatar print 'Avoided cat:',avoidCat
def destinationsTask(): # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) yield viztask.waitTime(12) instructions.setText("Walk to the potted plant directly ahead on the opposite side of the courtyard.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(plantSensor) instructions.runAction(Show) instructions.setText("Face the arch side of the courtyard. Walk to the piles of crates directly ahead.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(cratesSensor) instructions.runAction(Show) instructions.setText("Walk into the cafe on the opposite side of the courtyard.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(cafeSensor) instructions.runAction(Show) instructions.setText("Thank you for your participation.") #Show results of experiment print 'Avoided sitting avatar:',avoidSitting print 'Avoided standing avatar:',avoidStanding print 'Avoided dancing avatar:',avoidDancing
crate2 = crate1.clone(pos=[-9.8,0.3,5.05],euler=[5,0,0],scale=[0.6,0.6,0.6]) crate3 = crate1.clone(pos=[-9.8,0.9,5.35],euler=[-5,0,0],scale=[0.6,0.6,0.6]) #Boolean variables to store trial results avoidSitting = True avoidStanding = True avoidDancing = True pigeonPositions=[[-6.9,0,7.2],[3.3,0,14.5],[0.8,0,16],[-2.3,0,14.7],[2.9,0,-1.6],[-0.7,0,-1.7]] for pos in pigeonPositions: pigeon = pigeon.copy(pos=pos) random_speed = vizact.method.setAnimationSpeed(0,vizact.randfloat(0.7,1.5)) random_walk = vizact.walkTo(pos=[vizact.randfloat(pos[0]-0.3,pos[0]+0.3),0,vizact.randfloat(pos[2]-0.5,pos[2]+0.5)]) random_animation = vizact.method.state(vizact.choice([1,3],vizact.RANDOM)) random_wait = vizact.waittime(vizact.randfloat(5.0,10.0)) pigeon_idle = vizact.sequence( random_speed, random_walk, random_animation, random_wait, viz.FOREVER) pigeon.runAction(pigeon_idle) #Add three avatars in different locations with different animations avatar1 = viz.addAvatar('vcc_male2.cfg',pos=[2.1,0, 21.4],euler=[180,0,0],scale=[0.95,0.95,0.95]) avatar2 = avatar1.copy(pos=[-10.2,0,12],euler=[90,0,0]) avatar3 = avatar1.copy(pos=[1.5,0,5.6],euler=[180,0,0]) avatar1.state(6) avatar2.state(1) avatar3.state(5) #Create sensors for destinations plantSensor = vizproximity.Sensor(vizproximity.Box([4,5,5],center=[0,2.5,0]),source=plantMarker) cratesSensor = vizproximity.Sensor(vizproximity.Box([5,4,4],center=[0,1.7,0]),source=crate1) cafeSensor = vizproximity.Sensor(vizproximity.Box([5,4,10]),source=viz.Matrix.translate(12,2,7.5))
def execute_actions (self, actList): # check if this is a valid list and if it contains at least one action try: if len(actList) > 0: print self._name.getMessage(), "executing...", actList ex = True else: ex = False except: ex = False pass if not ex: return #action list for action in actList: #get a list timer delay(s) (contained inside brackets, e.g. [10,20]) if '[' in action: action, delay = self.parse_action(action) ########## ENGINE ACTIONS ############## if action == 'turning_valve_on': self._factory.factory.addAction(vizact.call(self._factory.engine.E_openValve, 3)) elif action == 'turning_valve_off': self._factory.factory.addAction(vizact.call(self._factory.engine.E_closeValve, 3)) elif action == 'starting_engine': self._factory.factory.addAction(vizact.waittime(3)) #wait for valve animation self._factory.factory.addAction(vizact.call(self._factory.StartFactory)) elif action == 'stopping_engine': self._factory.StopFactory() ########## BOILER ACTIONS ############## elif action == 'loading_boiler': self._factory.boiler.OpenCloseHatch(True) self._factory.factory.addAction(vizact.waittime(2)) self._factory.factory.addAction(vizact.call(self._factory.boiler.CoalAction, 1)) #self._factory.factory.addAction(vizact.waittime(1)) #self._factory.factory.addAction(vizact.call(self._factory.boiler.CoalAction, 2)) elif action == 'starting_timer': viz.starttimer(10, delay[0], 0) #timer for the first warning viz.starttimer(15, delay[1], 0) #timer for the second warning viz.starttimer(20, delay[2], 0) #timer for stopping factory elif action == 'stopping_timer': viz.killtimer(10) viz.killtimer(15) viz.killtimer(20) elif 'pressure' in action: #get the pressure and send it as an argument to the machine specified by the first word machine = action.partition('_')[0] pressure = action.rpartition('_')[2][:-3] #get psi or rpm value exec('self._factory.'+machine+'.ChangePressure('+pressure+','+str(delay[0])+')') elif action == 'lighting_furnace': #coals appear inside furnace and light up self._factory.boiler.CoalAction(2) self._factory.factory.addAction(vizact.waittime(2)) self._factory.factory.addAction(vizact.call(self._factory.boiler.OpenCloseHatch, False)) elif action == 'dying_away_fire': #fire dies away and coals are wasted self._factory.boiler.CoalAction(3) elif action == 'renewing_fire': #fire dies away and coals are wasted self._factory.boiler.CoalAction(4) elif action == 'exhausting_fire': #fire dies away and coals are wasted self._factory.boiler.CoalAction(5) viz.starttimer(5, 5, 0) #timer for waiting fire die out, before sending anim-finished ########## MILL ACTIONS ############## elif 'loading_mill' in action: #has * at the end if '*' in action: #don't let the second player (no *) execute the animation again LR = action[-2:-1] viz.starttimer(ord(LR), 5, 0) #timer while loading the olives -> anim-finished mill = 'mill'+ LR sackID = action[-3:-1] exec('self._factory.'+mill+'.SackAnim(\"'+sackID+'\")') elif 'starting_crash' in action: LR = action[-1:] mill = 'mill'+ LR exec('self._factory.'+mill+'.OlivesToPaste()') elif 'pouring_paste' in action: LR = action[-1:] mill = 'mill'+ LR viz.starttimer(ord(LR), 5, 0) #timer while pouring the paste -> anim-finished exec('self._factory.'+mill+'.PasteInTank()') elif 'wasting_paste' in action: LR = action[-1:] mill = 'mill'+ LR viz.starttimer(ord(LR), delay[0], 0) #timer while wasting the paste -> anim-finished exec('self._factory.'+mill+'.Damage(True)') exec('self._factory.'+mill+'.WastePaste()') elif 'transferring_tank' in action: if '*' in action: #don't let the second player (no *) execute the action again LR = action[-2:-1] mill = 'mill'+ LR viz.starttimer(ord(LR), 10, 0) #timer while transferring the tank -> anim-finshed exec('self._factory.'+mill+'.MoveTank()') elif 'finishing_transfer' in action: LR = action[-1:] mill = 'mill'+ LR viz.starttimer(ord(LR), 4, 0) #timer while big tank fills up -> anim-finshed elif 'replenishing_sacks' in action: LR = action[-1:] mill = 'mill'+ LR exec('self._factory.'+mill+'.ReplenishSacks()') elif 'resetting_mill' in action: LR = action[-1:] mill = 'mill'+ LR exec('self._factory.'+mill+'.ResetMill()') elif 'timerM' in action: LR = action[-1:] action = action.replace(LR, '') #delete the last character timerTag = action.partition('_')[2] timerCode = action.partition('_')[0][-1:] #1=set timer, 0=kill timer #e.g., (1,5) -> set timer id=77 (76+1) or id=83 (82+1) for 5 secs #wasted is called with thick and hot and needs to expire later timers = {'dilute':1, 'thick':2, 'ready':3, 'hot':4, 'wasted':5} if int(timerCode) == 1: viz.starttimer(ord(LR)+timers[timerTag], delay[0], 0) else: viz.killtimer(ord(LR)+timers[timerTag]) ########## LOADER ACTIONS ############## elif action == 'serving_mat': self._factory.loader.MatOnTable() elif 'getting_pulp' in action: amount = delay[0]*.5 self._factory.loader.PulpInTank(amount) elif action == 'scooping_pulp': self._CanFull(True) # sent to player holding can elif 'filling_mat' in action: if '*' in action: #don't let the second player (no *) execute the action again self._factory.loader.FillMat() if self._selected == 'canful': #the one holding the can should... self._CanFull(False) #empty the can being held elif action == 'picking_mat': if self.AddToToolbox('mat'): #prevents picking the mat when inventory full viz.starttimer(200+self._player, .1, 0) #send mat-picked event from this player self._feedback = 'picked' #avoids displaying the 'undefined' message self.SelectTool('mat') #select the mat from the toolbox self.HoldObject('mat') #sets the mat as the holding object (cursor) self._factory.loader.PickMat() elif action == 'mat_as_tool': matObj = self._factory.loader.components['mat'] self._factory.AddMatAsTool('matP', matObj) ######## PRESS ACTIONS ############### elif 'loading_press' in action: LR = action[-1:] press = 'press'+ LR matsLoaded = eval('self._factory.'+press+'.LoadMat()') matsFull = delay[0] #delay->number of mats to load before full if matsLoaded == matsFull: viz.starttimer(ord(LR)+501, 2, 0) #timer for filling up press elif action == 'dropping_mat': self.DropObject(putBack=False, matOnTray=True) elif 'fillingup_press' in action: LR = action[-1:] #L:76, R:82 press = 'press'+ LR exec('self._factory.'+press+'.FillUp()') elif 'starting_press' in action: # called from the pump LR = action[-1:] viz.starttimer(ord(LR)+502, 1, 0) #timer for staring press elif 'finishing_press' in action: # called from the pump LR = action[-1:] viz.starttimer(ord(LR)+503, 1, 0) #timer for finishing press elif 'pumping_oil_press' in action: # called from the oil pump LR = action[-1:] viz.starttimer(ord(LR)+505, 1, 0) #timer for emptying the oil tanks elif 'resetting_press' in action: # called from the pump LR = action[-1:] viz.starttimer(ord(LR)+504, 1, 0) #timer for releasing press elif 'releasing_press' in action: # used as delay to send the 'anim-finished' event LR = action[-1:] press = 'press'+ LR viz.starttimer(ord(LR)+500, 10, 0) #waiting to send anim-finished exec('self._factory.'+press+'.Releasing(10)') elif 'pressing_press' in action: LR = action[-1:] press = 'press'+ LR exec('self._factory.'+press+'.Pressing()') elif 'removing_mats' in action: LR = action[-1:] press = 'press'+ LR exec('self._factory.'+press+'.RestoreMats()') elif 'damaging_press' in action: LR = action[-1:] press = 'press'+ LR viz.starttimer(ord(LR)+500, delay[0], 0) #waiting to send anim-finished exec('self._factory.'+press+'.Damage(True)') elif 'emptying_oil' in action: LR = action[-1:] press = 'press'+ LR exec('self._factory.'+press+'.PumpOil()') ######## PUMP ACTIONS ############### elif 'starting_pump' in action: LR = action[-1:] pump = 'pump'+ LR func = 'self._factory.'+pump+'.ChangeGuide, 1' exec('self._factory.factory.addAction(vizact.call('+func+'))') func = 'self._factory.'+pump+'.StopCrazy' exec('self._factory.factory.addAction(vizact.call('+func+'))') func = 'self._factory.'+pump+'.SetMotion' exec('self._factory.factory.addAction(vizact.call('+func+'))') elif 'stopping_pump' in action: LR = action[-1:] pump = 'pump'+ LR func = 'self._factory.'+pump+'.ChangeGuide, -1' exec('self._factory.factory.addAction(vizact.call('+func+'))') func = 'self._factory.'+pump+'.StartCrazy' exec('self._factory.factory.addAction(vizact.call('+func+'))') func = 'self._factory.'+pump+'.EndMotion' exec('self._factory.factory.addAction(vizact.call('+func+'))') elif 'opening_bypass' in action: LR = action[-1:] pump = 'pump'+ LR exec('self._factory.'+pump+'.TurnValve(1)') elif 'closing_bypass' in action: LR = action[-1:] pump = 'pump'+ LR exec('self._factory.'+pump+'.TurnValve(-1)') elif 'lifting_bar' in action: LR = action[-1:] pump = 'pump'+ LR exec('self._factory.'+pump+'.LiftBar(True)') elif 'dropping_bar' in action: LR = action[-1:] pump = 'pump'+ LR exec('self._factory.'+pump+'.LiftBar(False)') elif 'damaging_pump' in action: LR = action[-1:] pump = 'pump'+ LR viz.starttimer(ord(LR)+100, delay[0], 0) elif 'timerP' in action: LR = action[-1:] action = action.replace(LR, '') #delete the last character timerTag = action.partition('_')[2] timerCode = action.partition('_')[0][-1:] #1=set timer, 0=kill timer #e.g., (101,20) -> set timer id=177 (76+101) or id=184 (82+102) for 20 secs #safe+done=60 (the duration of the pressing animation) #10, 60, 30 secs should be also set in the pump's ChangePressure function timers = {'good':101, 'safe':102, 'done':103, 'high':104, 'max':105} if int(timerCode) == 1: viz.starttimer(ord(LR)+timers[timerTag], delay[0], 0) else: viz.killtimer(ord(LR)+timers[timerTag]) ######## OIL PUMP ACTIONS ############### elif action == 'start_pumping': self._factory.oilPump.ChangeGuide(1) elif action == 'stop_pumping': self._factory.oilPump.ChangeGuide(-1) elif action == 'filling_lavals': self._factory.oilPump.OilPourInLavals(1) elif action == 'emptying_tanks': self._factory.oilPump.OilPourInLavals(0) elif 'timerO' in action: timerTag = action.partition('_')[2] timerCode = action.partition('_')[0][-1:] #1=set timer, 0=kill timer timers = {'tanks':(701,5), 'lavals':(702,10)} if int(timerCode) == 1: viz.starttimer(timers[timerTag][0], timers[timerTag][1], 0) else: viz.killtimer(timers[timerTag][0]) ######## LAVAL ACTIONS ############### elif action == 'detaching_laval_belt': self._factory.lavalR.DetachBelt() elif 'attaching_belt' in action: #has * at the end if '*' in action: #execute the action only the first time (second no *) print "ATTACHING BELTTTTTTTTTTT by", self._name.getMessage() self._factory.lavalR.AttachBelt() if self._selected == 'belt':#the one holding the belt should... self.DropObject(False) #drop it without putting in back in place elif 'starting_laval' in action: LR = action[-1:] laval = 'laval'+ LR exec('self._factory.'+laval+'.ChangeGuide(1)') elif 'stopping_laval' in action: LR = action[-1:] laval = 'laval'+ LR exec('self._factory.'+laval+'.ChangeGuide(-1)') elif 'starting_separation' in action: LR = action[-1:] laval = 'laval'+ LR exec('self._factory.'+laval+'.StartSeparation(1)') elif 'stopping_separation' in action: LR = action[-1:] laval = 'laval'+ LR exec('self._factory.'+laval+'.StartSeparation(0)') elif 'transferring_pitcher' in action: if '*' in action: #don't let the second player execute the animation again LR = action[-2:-1] laval = 'laval'+ LR viz.starttimer(400+ord(LR), 7, 0) #timer while transferring the pitcher -> anim-finshed exec('self._factory.'+laval+'.MovePitcher('+str(delay[0])+')') elif 'damaging_laval' in action: LR = action[-1:] laval = 'laval'+ LR viz.starttimer(ord(LR)+400, delay[0], 0) #waiting to send anim-finished exec('self._factory.'+laval+'.Damage(True)') elif 'timerL' in action: LR = action[-1:] action = action.replace(LR, '') #delete the last character timerTag = action.partition('_')[2] timerCode = action.partition('_')[0][-1:] #1=set timer, 0=kill timer #e.g., (401,10) -> set timer id=477 (76+401) or id=484 (82+402) for 10 secs #10, 30, 30 secs should be also set in the laval's ChangePressure function timers = {'start':401, 'done':402, 'critical':403, 'max':404} if int(timerCode) == 1: viz.starttimer(ord(LR)+timers[timerTag], delay[0], 0) else: viz.killtimer(ord(LR)+timers[timerTag]) ######## SCALE ACTIONS ############### elif action == 'pitcher_on_scale': #called from the lavals viz.starttimer(801, 1, 0) elif action == 'weighing_pitcher': #increase counter by delay[1] lbs in delay[0] secs self._factory.scale.WeighPitcher(delay[0], delay[1], delay[2]) elif 'timerS' in action: viz.starttimer(802, delay[0], 0) elif action == 'finishing_production': viz.starttimer(803, delay[0], 0) elif action == 'finishing_game': self._mapWin.GameFinish(delay[0]) elif action == 'save_data': viz.starttimer(2000, 0, 0) ####### WATER PIPE ACTIONS [PRACTICE] ###### elif 'detaching_pipe' in action: self._factory.waterPipe.DetachPipe() elif 'attaching_pipe' in action: if '*' in action: self._factory.waterPipe.AttachPipe() if self._selected == 'pipe':#the one holding the pipe should... self.DropObject(False) #drop it without putting in back in place elif action == 'opening_valve': self._factory.waterPipe.OpenValve(2) elif action == 'closing_valve': self._factory.waterPipe.CloseValve(2) viz.starttimer(1000, 10, 0) elif action == 'damaging_pipe': viz.starttimer(1000, delay[0], 0) self._factory.waterPipe.Damage(True) elif action == 'resetting_pipe': self.AddToWorld('pipe') elif 'timerW' in action: timerTag = action.partition('_')[2] timerCode = action.partition('_')[0][-1:] #1=set timer, 0=kill timer timers = {'done':1001, 'high':1002, 'max':1003} if int(timerCode) == 1: viz.starttimer(timers[timerTag], delay[0], 0) else: viz.killtimer(timers[timerTag]) ####### WHEEL BARROW ACTIONS [PRACTICE] ###### elif 'moving_barrow' in action: if '*' in action: self._factory.wheelBarrow.MoveBarrow() elif action == 'reset_delay': viz.starttimer(1010, delay[0], 0) elif action == 'resetting_barrow': self._factory.wheelBarrow.ResetBarrow() # CHECK IF IN 1P CONDITION AND REMOVE SECOND PLAYER DEMAND elif 'enable1P' in action: otherAct = action.partition('_')[2] self.EnablePlayer1ForMultiInput(otherAct) # REMOVING SMOKE FROM MACHINERY elif 'removing_smoke' in action: mach = action.rpartition('_')[2] exec('self._factory.'+mach+'.Damage(False)') # ALERTS ON MACHINERY elif 'error' in action: mach = action.partition('_')[2] machPos = self._factory.machines[mach].object.getPosition() errorCode = action.partition('_')[0][-1:] #1=error on, 0=error off self._mapWin.ShowErrorOnMap(mach, machPos, int(errorCode)) #check if any of the players is near a machine and update their alert panels for p in self.PLAYERS.values(): p.CheckForAlertNearMachine(mach, int(errorCode)) # SCORE KEEPING elif 'score' in action: print "Points:", delay[0] self._mapWin.UpdateScore(delay[0]) elif action == 'revealing_total_counter': self._mapWin.ShowTotalScore() elif action == 'increasing_total': self._mapWin.IncreaseOilTotal(delay[0], delay[1])
viz.go(viz.FULLSCREEN) # Setup keyboard/mouse tracker tracker = vizcam.addWalkNavigate(moveScale=2.0) tracker.setPosition([0,1.8,0]) viz.link(tracker,viz.MainView) viz.mouse.setVisible(False) # Load piazza environment piazza = viz.addChild('piazza.osgb') viz.addChild('piazza_animations.osgb') # Loop fountain sound #piazza.playsound('fountain.wav',viz.LOOP,node='fountain-sound') # Swap out sky with animated sky dome piazza.getChild('pz_skydome').remove() day = viz.add('sky_day.osgb') day.renderToBackground() kobe = viz.add('resources/CC2_m016_hipoly_A1_v2.cfg',pos=(0,0,5),euler=(180,0,0)) kobe.state(32) head = viz.addFace('avatars/kobe/kobe.vzf') kobe.setFace(head) talk = vizact.speak('kobe_speech.wav', threshold = 0, scale = 0.01, sync = True) sequence = vizact.sequence(talk, vizact.waittime(5), viz.FOREVER) kobe.addAction(sequence)
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)
day = viz.add('sky_day.osgb') day.renderToBackground() male = viz.addAvatar('resources/CC2_m001_hipoly_A1_v2.cfg',pos=(-6.5,0,8),euler=(180,0,0)) male.state(3) startedWalking = False female = viz.addAvatar('resources/CC2_f020_hipoly_A1_v2.cfg',pos=FEMALE_POSITION,euler=(-90,0,0)) female.state(3) pigeon = viz.addAvatar('pigeon.cfg', pos=PIGEON_POSITION) pigeon.setScale(2,2,2) pigeon.setEuler(random.randint(120, 180)) randomAnimation = vizact.method.state(vizact.choice([1,3], vizact.RANDOM)) randomWait = vizact.waittime(vizact.randfloat(2,3)) pigeon_idle = vizact.sequence(randomAnimation, randomWait, viz.FOREVER) pigeon.runAction(pigeon_idle) #pigeonSensor = vizproximity.Sensor(vizproximity.Sphere(5, center=PIGEON_POSITION), source=pigeon) pigeonSensor = vizproximity.Sensor(vizproximity.Box([1.5,3,1.5]),source=pigeon) target = vizproximity.Target(male) manager = vizproximity.Manager() manager.addSensor(pigeonSensor) manager.addTarget(target) def pigeonRun(e): runAction = vizact.walkTo([vizact.randfloat(2,4), 0, vizact.randfloat(3, 6)], 4) pigeon.runAction(runAction) pigeon.addAction(pigeon_idle)
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)
sofa.setPosition([-9.2, 0.15, -0]) sofa.setEuler([-90, 0, 0]) #stand=viz.addChild('F:\Objects\max\obj1.ive') #stand.setScale([.00030,.00030,.00030]) #stand.setPosition([-0,0.15,-0]) #stand.setEuler([0,0,0]) shadow_texture = viz.addTexture('shadow.png') shadow = vizshape.addQuad(parent=avatar, axis=vizshape.AXIS_Y) shadow.texture(shadow_texture) shadow.zoffset() avatarMove = [[-5.7, -5.2, 300], [-5.7, 6.5, 270], [0, 8, 0], [5.7, 6.5, 70], [5.7, 2.6, 70], [5.7, 1, 130]] actions = [] RandomWait = vizact.waittime(vizact.randfloat(0, 0)) for loc in avatarMove: if loc == avatarMove[2]: RandomWait = vizact.waittime(vizact.randfloat(5, 10)) else: RandomWait = vizact.waittime(vizact.randfloat(0, 0)) actions.append(vizact.method.playsound('footsteps.wav', viz.LOOP)) actions.append(vizact.walkTo([loc[0], 0, loc[1]], turnSpeed=250.0)) actions.append(vizact.method.playsound('footsteps.wav', viz.STOP)) actions.append(vizact.turn(loc[2], 250.0)) actions.append(RandomWait) avatar.addAction(vizact.sequence(actions, viz.FOREVER))
def react(): male.state(2) wait = vizact.waittime(3) scratchAndShrug = vizact.sequence(wait, vizact.animation(4),vizact.animation(6)) male.add(scratchAndShrug)
piazza.getChild('pz_skydome').remove() day = viz.add('sky_day.osgb') # Add avatar sitting on a bench male = viz.addAvatar('vcc_male2.cfg',pos=(-6.5,0,13.5),euler=(90,0,0)) male.state(6) # Create pigeon pigeon_root = viz.addGroup() pigeon_root.visible(False) pigeon = viz.addAvatar('pigeon.cfg',parent=pigeon_root) # Add idle animation random_walk = vizact.walkTo(pos=[vizact.randfloat(-0.5,0.5),0,vizact.randfloat(-0.5,0.5)]) random_animation = vizact.method.state(vizact.choice([1,3],vizact.RANDOM)) random_wait = vizact.waittime(vizact.randfloat(4.0,8.0)) pigeon_idle = vizact.sequence( random_walk, random_animation, random_wait, viz.FOREVER) pigeon.runAction(pigeon_idle) # Adding sound to pigeon hooting = pigeon.playsound('birds.wav',viz.LOOP) hooting.pause() # Create flash screen quad flash_quad = viz.addTexQuad(parent=viz.ORTHO) flash_quad.color(viz.WHITE) flash_quad.alignment(viz.ALIGN_LEFT_BOTTOM) flash_quad.drawOrder(-10) flash_quad.blendFunc(viz.GL_ONE,viz.GL_ONE) flash_quad.visible(False) viz.link(viz.MainWindow.WindowSize,flash_quad,mask=viz.LINK_SCALE)
def stageAxes(self, NAxes, relSpeed, holes): # Function for swinging the axes def swing(object, t, startAngle, endAngle): d = (math.sin(t[0]) + 1.0) / 2.0 angle = startAngle + d * (endAngle - startAngle) object.setEuler([90,0,angle]) t[0] += 0.03 * relSpeed # Add axes beginPosition = 400 endPosition = 6600 nrAxes = NAxes self.axes = [] self.axest = [] self.swoosh = [] for i in range(nrAxes): self.axes.append(viz.addChild('axe.OSGB', cache=viz.CACHE_CLONE)) self.axes[i].setPosition([beginPosition+i*(endPosition/nrAxes),750,0], viz.REL_LOCAL) self.axest.append([float(i)]) sound_node = viz.addGroup(pos=[beginPosition+i*(endPosition/nrAxes),75,0]) self.swoosh.append(sound_node.playsound('swoosh.wav')) self.swoosh[i].minmax(0, 20) vizact.ontimer(3.14/relSpeed, self.swoosh[i].play) vizact.ontimer(0.03, swing, self.axes[i], self.axest[i], 120, 240) # Add ducky self.newduck = viz.addAvatar('duck.cfg') self.newduck.setScale([170,170,170]) self.newduck.setPosition([7200,0,0],viz.REL_LOCAL) self.newduck.setEuler([-90,0,0]) # Add proximity sensors manager = vizproximity.Manager() target = vizproximity.Target(viz.MainView) manager.addTarget(target) self.axesensors = [] for i in range(nrAxes): self.axesensors.append(vizproximity.addBoundingBoxSensor(self.axes[i])) manager.addSensor(self.axesensors[i]) duckSensor = vizproximity.addBoundingBoxSensor(self.newduck,scale=(2.5,2.5,3)) manager.addSensor(duckSensor) # Boolean variables to store trial results self.axesHit = [] for i in range(nrAxes): self.axesHit.append(0) # for i in range(nrAxes): # sensors.append(vizproximity.addBoundingBoxSensor(self.axes[i])) # manager.addSensor(sensors[i]) holeCoordinates = [ [755,0,95], [755,0,-98], [1391,0,-1.5], [2017,0,98], [2503,0,-5], [2987,0,-108], [3776,0,-55], [4726,0,49], [5525,0,95], [5525,0,-104], [6011,0,-7]] self.holesensor = [] k=-1 for hole in holeCoordinates: k+=1 self.holesensor.append(vizproximity.Sensor(vizproximity.Box([50,300,100],center=hole),source=viz.Matrix.translate(0,0,0))) manager.addSensor(self.holesensor[k]) self.holesHit = [] for i in range(len(self.holesensor)): self.holesHit.append(0) # Called when we enter a proximity def EnterProximity(e): for i in range(nrAxes): if e.sensor == self.axesensors[i]: self.axesHit[i] += 1 print "Hit axe #" + str(i) + " " + str(self.axesHit[i]) + " times!" if holes: for i in range(len(self.holesensor)): if e.sensor == self.holesensor[i]: self.holesHit[i] += 1 print "Hit hole #" + str(i) + " " + str(self.holesHit[i]) + " times!" manager.onEnter(None,EnterProximity) #Add info panel to display messages to participant self.instructions = vizinfo.InfoPanel(icon=False,key=None) vizact.onkeydown('g',manager.setDebug,viz.TOGGLE) # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) #instructions.setText("Reach the duck."+str(self.time)) self.startTime = viz.tick() print "done with scene, awaiting duck" print "----------Begin stage "+str(self.stage)+"----------" # When finished yield vizproximity.waitEnter(duckSensor) self.elapsedTime = viz.tick() - self.startTime self.elapsedTime = str(round(self.elapsedTime,2)) yayString = "Total number of axes hit: " if NAxes>0: yayString += str(self.axesHit[0]) for i in range(1, nrAxes): yayString += ", " + str(self.axesHit[i]) if holes: yayString += ".\nTotal number of holes hit: " for i in range(len(self.holesensor)): yayString += ", " + str(self.holesHit[i]) yayString += ".\nTime is: " + str(self.elapsedTime) print yayString self.tracking_data.write(yayString) print "----------End stage----------"
sofa.setScale([.030,.030,.030]) sofa.setPosition([-9.2,0.15,-0]) sofa.setEuler([-90,0,0]) #stand=viz.addChild('F:\Objects\max\obj1.ive') #stand.setScale([.00030,.00030,.00030]) #stand.setPosition([-0,0.15,-0]) #stand.setEuler([0,0,0]) shadow_texture = viz.addTexture('shadow.png') shadow = vizshape.addQuad(parent=avatar,axis=vizshape.AXIS_Y) shadow.texture(shadow_texture) shadow.zoffset() avatarMove = [[-5.7,-5.2,300],[-5.7,6.5,270],[0,8,0],[5.7,6.5,70],[5.7,2.6,70],[5.7,1,130]] actions = [] RandomWait = vizact.waittime(vizact.randfloat(0,0)) for loc in avatarMove: if loc == avatarMove[2]: RandomWait = vizact.waittime(vizact.randfloat(5,10)) else: RandomWait = vizact.waittime(vizact.randfloat(0,0)) actions.append(vizact.method.playsound('footsteps.wav',viz.LOOP)) actions.append(vizact.walkTo([loc[0],0,loc[1]],turnSpeed=250.0)) actions.append(vizact.method.playsound('footsteps.wav',viz.STOP)) actions.append(vizact.turn(loc[2],250.0)) actions.append(RandomWait) avatar.addAction(vizact.sequence(actions,viz.FOREVER))
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)
pigeon.setScale(5,5,5) # Create a cat cat = viz.addAvatar('cat_tabby_high.cfg') cat.setPosition(2,0,5) cat.state(1) # Add idle animation #random_walk = vizact.walkTo(pos=[vizact.randfloat(-0.5,0.5),0,vizact.randfloat(-0.5,0.5)]) #random_animation = vizact.method.state(vizact.choice([1,3],vizact.RANDOM)) #random_wait = vizact.waittime(vizact.randfloat(4.0,8.0)) #pigeon_idle = vizact.sequence( random_walk, random_animation, random_wait, viz.FOREVER) #pigeon.runAction(pigeon_idle) randomTime = vizact.randfloat(0.5,3.0) randomWait = vizact.waittime(randomTime) runAwayAction = vizact.sequence(randomWait, runAway(viz.MainView), viz.FOREVER) # Adding sound to pigeon hooting = pigeon.playsound('birds.wav',viz.LOOP) hooting.pause() # Create flash screen quad flash_quad = viz.addTexQuad(parent=viz.ORTHO) flash_quad.color(viz.WHITE) flash_quad.drawOrder(-10) flash_quad.blendFunc(viz.GL_ONE,viz.GL_ONE) flash_quad.visible(False) flash_quad.setBoxTransform(viz.BOX_ENABLED) # Create status bar background
def cityScene(): global city, skyDome2 city.enable(viz.RENDERING) skyDome2.enable(viz.RENDERING) yield fader.fadeInTask() manager = vizproximity.Manager() manager.setDebug(False) rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) car1 = city.getChild('BlueCar.OSGB') car1Sensor = vizproximity.Sensor(vizproximity.Box([3.3,1.6,1.8], center=[5,0.4,-10.5]), source=car1) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(car1Sensor) CAR_TOUCHED = False def startCar1(): mole1 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) 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) 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) mole3.setPosition([-1.05,0.29,-0.05]) mole3.setScale([3,3,3]) mole3.setAnimationSpeed(5) mole3.setEuler(-90,0,0) def floatersGo(): mole4 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) 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) 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) 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) 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) 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) 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) 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) mole11.setPosition([-.2,2.9,0]) mole11.setEuler([135,-90,0]) mole11.setScale([3,3,3]) mole11.setAnimationSpeed(2) yield vizproximity.waitEnter(car1Sensor) globals_oa.AUDIO_SUCCESS.play() yield vizact.ontimer2(1,10, startCar1) yield vizact.waittime(1.5) yield vizact.ontimer2(1,10, floatersGo) yield viztask.waitTime(100)