def Collect(objName, objLoc, ScaleFac, tel): viz.MainWindow.setScene(1) #teleport to new location each trial? if tel: x, y = pol2cart(numpy.random.randint(12, radius), numpy.random.randint(0, 360)) viz.MainView.setPosition(x, 0, y) viz.MainView.setEuler(numpy.random.randint(0, 360), 0, 0) #add object obj = viz.addChild(objName + '.osgb') obj.setPosition(objLoc) obj.setScale([ScaleFac, ScaleFac, ScaleFac]) sensor = vizproximity.addBoundingBoxSensor(obj, scale=(1.5, 10, 1.5)) manager.addSensor(sensor) obj.visible(viz.ON) yield vizproximity.waitEnter(sensor) obj.remove() manager.removeSensor(sensor)
def main(): global co2models, moleculeManager,overOceanSensor loadBoatScene() #terrain_LW = vizfx.addChild(('./art/ENV_Island_Main.osgb').getChild('Ocean001')) setUpMolecAnimation() # viz.MainScene.enable(viz.FOG, op=viz.OP_ROOT) vizact.ontimer(0, masterTimer) overOceanSensor = vizproximity.addBoundingBoxSensor(globals_oa.boat, scale = [.8,.8,.65]) moleculeManager.addSensor(overOceanSensor) initializeBoatGrabberAndPhysics() setUpHandSensors()
def __init__(self, gem, gempos, escena, sound): print "ESCENA-2", escena self.gem = viz.addChild(gem, scene=escena) self.gem.setScale(2.5, 2.5, 2.5) self.gem.setPosition(gempos[0], gempos[1]) self.sensorGem = vizproximity.addBoundingBoxSensor(self.gem, scale=[6, 4, 6]) self.chimesound = sound self.canvas = viz.addGUICanvas() self.canvas.alignment(viz.ALIGN_CENTER) viz.MainWindow.setDefaultGUICanvas(self.canvas) self.info = vizinfo.InfoPanel('AVERNO', align=viz.ALIGN_RIGHT_TOP, icon=False) self.info.setTitle('Ejemplo') self.info.setPanelVisible(False) self.canvas.setRenderWorld([600, 500], [3, viz.AUTO_COMPUTE]) self.canvas.setPosition([ self.gem.getPosition()[0], self.gem.getPosition()[1] + 0.5, self.gem.getPosition()[2] ]) self.canvas.setEuler(0, 0, 0)
def initialize(zonePointer, fileWithListOfObjects): global species, nodesToHuntForEachSpecies, nodeNamesToHuntForEachSpecies, numObjectsToFind, displayObjects, dictionaryMappingHuntItemsToNamesFromZoneModel, flagPileSensor vizact.onkeydown('-', endHunt) if globals_oa.scavengerHuntInProgress: print "Please finish the previous species search first!" return #format of the input files: # each line has one species, and the nodes of that species from the zone model, which are to be hunted # the first name in each line is the name of the species and the following names are the names of the nodes # there should be no spaces before or after the commas separating the names # speciesWithNodeNamesToHunt = createListFromInputFile(fileWithListOfObjects, False) createListFromInputFile(fileWithListOfObjects) # for s in speciesWithNodeNamesToHunt: # species.append(s[0]) # numObjectsToFind.append(0) # nodesToHuntForEachSpecies[s[0]] = [] # speciesRegex[s[0]] = re.compile(s[1] + '[ ]*\d*$') #Assuming node names are of the form 'species + maybe a space + number' hud = None if globals_oa.hmdUsed == globals_oa.HMD_TYPE['RIFT']: hud = globals_oa.rift.getHUD() displayPos = [0, 0.05, 1] print "TO FIND:" # for zone in [zonePointer]:#, terrainZone2, terrainZone3]: for name in zonePointer.getNodeNames(): # nameBlocks = name.split(' ') # if 'Ocinebrina' in nameBlocks: # print name item = None speciesIndexCounter = 0 for s in species: # if speciesRegex[s].match(name):#s in name: if name in nodeNamesToHuntForEachSpecies[s]: item = zonePointer.getChild(name) if item: nodesToHuntForEachSpecies[s].append(item) dictionaryMappingHuntItemsToNamesFromZoneModel[item] = [] dictionaryMappingHuntItemsToNamesFromZoneModel[item].append(name) numObjectsToFind[speciesIndexCounter] += 1 if 'octopus' in name.lower(): Octopus.append(item) if 'eel' in name.lower(): Eel.append(item) if 'grass' in name.lower(): Grass.append(item) else: print name + ' cannot be located' break else: speciesIndexCounter += 1 # if globals_oa.currentZoneNumber == 3: # addHiddenSnailInZone3() #adding the display objects for each species for the current zone # for s in species: # displaySpeciesLoc = globals_oa.DISPLAY_OBJECT_DIRECTORY + str(globals_oa.currentZoneNumber) + '/' + str(s).lower()+ '.osgb' # print "loading display object from " + displaySpeciesLoc # if hud is not None: # displaySpeciesNode = vizfx.addChild(displaySpeciesLoc, pos=displayPos, parent=hud) # # displayEdwardsii = vizfx.addChild(FAUNA_DIRECTORY + globals_oa.SNAIL, pos=displayPos, parent=hud) # displaySpeciesNode.visible(False) # displayObjects.append(displaySpeciesNode) print "SPECIES:" print str(len(species)) # print species print nodesToHuntForEachSpecies print numObjectsToFind #set up display objects (all invisible) # hud = transport_vhil.rift.getHUD() # displayEdwardsii = vizfx.addChild(FAUNA_DIRECTORY + globals_oa.SNAIL, pos=displayPos, parent=hud) # displayEdwardsii.visible(False) # displayObjects.append(displayEdwardsii) # displayOctopus = vizfx.addChild(FAUNA_DIRECTORY + 'octopus_vulgaris/octopus vulgaris.osgb', pos=displayPos, parent=hud) # displayOctopus.visible(False) # displayObjects.append(displayOctopus) # global slate if globals_oa.slate is not None: # slate = vizfx.addChild(EQUIPMENT_DIRECTORY + 'Slate_New.osgb') # slateLink = viz.link(viz.MainView, globals_oa.slate, offset = (0, -0.75, 0.0)) # slateLink.setEuler([None,0,0], 1) # slateLink.preTrans(globals_oa.INITIAL_POSITIONAL_OFFSET_FOR_SLATE, 0) # slateLink.preEuler(globals_oa.INITIAL_ROTATIONAL_OFFSET_FOR_SLATE) # slateLink.clampPosY([-1.25, -0.75]) # else: globals_oa.slate.visible(True) # if globals_oa.lhModel is not None: globals_oa.slate.setParent(globals_oa.lhModel) # globals_oa.slate.setPosition([0.01, 0, -0.5]) # globals_oa.slate.setEuler([-90,0,0]) # globals_oa.slate.setScale([0.8,0.8,0.8]) # global basket # basket = vizfx.addChild(EQUIPMENT_DIRECTORY + 'diveBasket.osgb') # basket.setScale([0.75, 0.85, 0.75]) globals_oa.basket.visible(True) if globals_oa.currentZoneNumber == 1: #globals_oa.basket.setPosition([0,-1.74,0]) old basket position #globals_oa.basket.setPosition([2,-.2,0]) # globals_oa.basket.setPosition([2,-1.3,2]) globals_oa.basket.setPosition(globals_oa.basketPosInCGscene1) elif globals_oa.currentZoneNumber == 3: globals_oa.basket.setPosition([58.8, -1.78, 0.281726598739624])#947296142578125 # basketLink = viz.link(viz.MainView, basket, offset = (0, -0.75, 0.0)) # basketLink.setEuler([None,0,0], 1) # basketLink.preTrans([.5, 0, 0.70], 0) # basketLink.preEuler([50,0,0]) # basketLink.clampPosY([-1.25, -0.75]) global basketManager basketManager = vizproximity.Manager() basketSensor = vizproximity.addBoundingBoxSensor(globals_oa.basket, scale = (1.5, 2, 1.5)) basketManager.addSensor(basketSensor) # basketManager.onEnter(None, selectObject) # vizact.onkeydown('f',basketManager.setDebug,viz.TOGGLE) # global slateFadingManager # slateFadingManager = vizproximity.Manager() # # ## slateFadingManager.addSensor(globals_oa.oceanFloorCollisionSensor) ## slateFadingManager.addSensor(globals_oa.rockChunkCollisionSensor1) ## slateFadingManager.addSensor(globals_oa.rockChunkCollisionSensor2) ## slateFadingManager.addSensor(globals_oa.rockChunkCollisionSensor3) # # target = vizproximity.Target(globals_oa.slate) # slateFadingManager.addTarget(target) # # slateFadingManager.onEnter(None,EnterProximity) # slateFadingManager.onExit(None,ExitProximity) # # vizact.onkeydown('0',slateFadingManager.setDebug,viz.TOGGLE) textScale = 0.05 slateEuler = [0,0,0] averageInitPos = [0.0, 1.5, -0.15] # Create time limit text global time_text # if time_text is None: # time_text_link.setEuler([None,90,0], 2) # time_text_link.preTrans([0.0, 0.01, 0.1], 1) # else: if time_text is not None: time_text.visible(True) # time_text = viz.addText3D('', pos = [0, 0, 0]) time_text.alignment(viz.ALIGN_CENTER_TOP) time_text.setParent(globals_oa.slate) # time_text.setPosition([0,0.01,0.25]) time_text.setPosition(averageInitPos[0], averageInitPos[1] + 0.5, averageInitPos[2]) time_text.setEuler(slateEuler) # time_text_link = viz.link(globals_oa.slate, time_text)#, offset = (0, 0.01,0.05)) time_text.setScale(textScale, textScale, textScale) # Create score text # global score_text # if score_text is None: # #score_text = viz.addText3D('',pos = [-0.4, 0.3, 1], parent=hud) # score_text = viz.addText('',pos = [0, 0.01, -0.05]) # score_text.setScale(textScale, textScale, textScale) # score_text.alignment(viz.ALIGN_CENTER_TOP) # score_text.setParent(globals_oa.slate) # score_text.setPosition([0,0.01,-0.05]) # score_text.setEuler([180,-90,0]) ## score_text_link = viz.link(globals_oa.slate, score_text) ## #score_text_link.setMask(viz.LINK_POS) ## #score_text.setEuler([0, 90, 0], mode = viz.REL_LOCAL) ## score_text_link.setEuler([None,90,0], 2) ### score_text_link.preTrans([0.0, 0.01, -0.05], 1) ## score_text_link.preTrans([0.05, 0.01, 0.0], 1) ## # score_text.color(viz.BLACK) # #score_text.alignment(viz.ALIGN_LEFT_TOP) # #score_text.setBackdrop(viz.BACKDROP_OUTLINE) # #viz.link(viz.MainWindow.LeftTop,score_text,offset=[20,-20,0]) # else: # score_text.visible(True) # global pics # pics = [] # pics.append( viz.addTexture('resources/Ocinebrina Edwardsii_Zone' + str(globals_oa.currentZoneNumber) + '.png') ) # pics.append( viz.addTexture('resources/Octopus_2D.png') ) # pics.append( viz.addTexture('resources/Eel_2D.png') ) # pics.append( viz.addTexture('resources/seagrass.jpg') ) # Get picture of seagrass global count_text1 global count_text2 global count_text3 global quad1 global quad2 global quad3 if quad1 is not None: quad1.visible(True) quad2.visible(True) quad3.visible(True) count_text1.visible(True) count_text2.visible(True) count_text3.visible(True) # if quad1 is None: #need to be initialized # quad1 = viz.addTexQuad(size = 0.15) # quad2 = viz.addTexQuad(size = 0.15) # quad3 = viz.addTexQuad(size = 0.15) # count_text1 = viz.addText('count: 0') # count_text2 = viz.addText('count: 0') # count_text3 = viz.addText('count: 0') #the following should be read from a file carrying textures names for species to be hunted, specific to each zone horizontalShift = 0.1 if globals_oa.currentZoneNumber == 1: quad1.setTexQuadDisplayMode(viz.TEXQUAD_FIT) quad1.setParent(globals_oa.slate) # quad1.setPosition([-.1,0.01,0.1]) quad1.setPosition(averageInitPos[0] - horizontalShift, averageInitPos[1] + 0.25, averageInitPos[2]) quad1.setEuler(slateEuler) #quad1.setScale([0.75,0.75,0.75]) quad1.texture(pics[0]) pics[0].hint(viz.PRELOAD_HINT) count_text1.setScale(textScale, textScale, textScale) count_text1.alignment(viz.ALIGN_CENTER_TOP) count_text1.setParent(globals_oa.slate) count_text1.setPosition(averageInitPos[0] + horizontalShift, averageInitPos[1] + 0.25, averageInitPos[2])#[0.1,0.01,0.15]) count_text1.setEuler(slateEuler) count_text1.color(viz.BLACK) # quad2.setTexQuadDisplayMode(viz.TEXQUAD_FIT) # quad2.setParent(globals_oa.slate) ## quad2.setPosition([-.1,0.01,-0.1]) # quad2.setPosition(averageInitPos[0] - horizontalShift, averageInitPos[1] + 0.2, averageInitPos[2]) # quad2.setEuler(slateEuler) # #quad2.setScale([0.75,0.75,0.75]) # quad2.texture(pics[1]) # pics[1].hint(viz.PRELOAD_HINT) # # count_text2.setScale(textScale, textScale, textScale) # count_text2.alignment(viz.ALIGN_CENTER_TOP) # count_text2.setParent(globals_oa.slate) ## count_text2.setPosition([0.1,0.01,-0.05]) # count_text2.setPosition(averageInitPos[0] + horizontalShift, averageInitPos[1] + 0.2, averageInitPos[2]) # count_text2.setEuler(slateEuler) # count_text2.color(viz.BLACK) quad2.visible(False) count_text2.visible(False) # quad3.setTexQuadDisplayMode(viz.TEXQUAD_FIT) # quad3.setParent(globals_oa.slate) ## quad3.setPosition([-0.1,0.01,-0.3]) # quad3.setPosition(averageInitPos[0] - horizontalShift, averageInitPos[1] + 0.05, averageInitPos[2]) # quad3.setEuler(slateEuler) # #quad3.setScale([0.75,0.75,0.75]) # quad3.texture(pics[2]) # pics[2].hint(viz.PRELOAD_HINT) # # count_text3.setScale(textScale, textScale, textScale) # count_text3.alignment(viz.ALIGN_CENTER_TOP) # count_text3.setParent(globals_oa.slate) ## count_text3.setPosition([0.1,0.01,-0.25]) # count_text3.setPosition(averageInitPos[0] + horizontalShift, averageInitPos[1] + 0.05, averageInitPos[2]) # count_text3.setEuler(slateEuler) # count_text3.color(viz.BLACK) quad3.visible(False) count_text3.visible(False) elif globals_oa.currentZoneNumber == 3: quad1.setTexQuadDisplayMode(viz.TEXQUAD_FIT) quad1.setParent(globals_oa.slate) # quad1.setPosition([-0.1,0.01,0.1]) quad1.setPosition(averageInitPos[0] - horizontalShift, averageInitPos[1] + 0.3, averageInitPos[2]) quad1.setEuler(slateEuler) quad1.texture(pics[0]) pics[0].hint(viz.PRELOAD_HINT) count_text1.setScale(textScale, textScale, textScale) count_text1.alignment(viz.ALIGN_CENTER_TOP) count_text1.setParent(globals_oa.slate) # count_text1.setPosition([0.1,0.01,0.15]) count_text1.setPosition(averageInitPos[0] + horizontalShift, averageInitPos[1] + 0.3, averageInitPos[2]) count_text1.setEuler(slateEuler) count_text1.color(viz.BLACK) count_text1.message('found: 0') quad2.setTexQuadDisplayMode(viz.TEXQUAD_FIT) quad2.setParent(globals_oa.slate) # quad2.setPosition([-0.1,0.01,-0.1]) quad2.setPosition(averageInitPos[0] - horizontalShift, averageInitPos[1] + 0.1, averageInitPos[2]) quad2.setEuler(slateEuler) quad2.texture(pics[3]) pics[3].hint(viz.PRELOAD_HINT) count_text2.setScale(textScale, textScale, textScale) count_text2.alignment(viz.ALIGN_CENTER_TOP) count_text2.setParent(globals_oa.slate) # count_text2.setPosition([0.1,0.01,-0.05]) count_text2.setPosition(averageInitPos[0] + horizontalShift, averageInitPos[1] + 0.1, averageInitPos[2]) count_text2.setEuler(slateEuler) count_text2.color(viz.BLACK) count_text2.message('found: 0') quad3.visible(False) count_text3.visible(False) # Create surface to wrap the texture on # global quad # if quad is None: # quad = viz.addTexQuad(size = 0.25) # quad.setTexQuadDisplayMode(viz.TEXQUAD_FIT) # quad.setParent(globals_oa.slate) # quad.setPosition([0,0.01,0]) # quad.setEuler([180,-90,0]) # quad.setScale([0.5,0.5,0.5]) # # Wrap texture on quad # display_image_link = viz.link(globals_oa.slate, quad)# offset = (0.0, 0.01, 0.25)) # #display_image_link = viz.addTexQuad(texture=viz.add('resources/Ocinebrina Edwardsii.tif'), size=0.1) # #display_image_link.setMask(viz.LINK_POS) # display_image_link.setEuler([None,90,0], 1) # display_image_link.preTrans([0.0, 0.01, 0.25], 0) # #quad.setEuler([0, 90, 0], mode = viz.REL_LOCAL) # quad.disable(viz.INTERSECTION) # quad.disable(viz.LIGHTING) # quad.disable(viz.FOG) else: quad.visible(True) textPos = [0, -0.05, 1] speciesTextScale = 0.05 global speciesText if speciesText is None: if hud is not None: speciesText = viz.addText("", pos=textPos, parent=hud) speciesText.alignment(viz.ALIGN_CENTER_TOP) speciesText.setScale(speciesTextScale, speciesTextScale, speciesTextScale) speciesText.color(viz.BLACK) speciesText.visible(False) #viz.callback(viz.TIMER_EVENT,onTimer) if (((globals_oa.currentZoneNumber == 0) and globals_oa.scavengerHuntCompleteInTestZone) or ((globals_oa.currentZoneNumber == 1) and globals_oa.scavengerHuntCompleteInZone1) or ((globals_oa.currentZoneNumber == 2) and globals_oa.scavengerHuntCompleteInZone2) or ((globals_oa.currentZoneNumber == 3) and globals_oa.scavengerHuntCompleteInZone3)): print "This scavenger hunt is already completed! Please try the hunt in a different zone." return print 'Scavenger Hunt started' global scavengerHuntStartSound if scavengerHuntStartSound is None: scavengerHuntStartSound = loadAudioFile(AUDIO_DIRECTORY + 'bell.wav') #adding a manager for touching the snails global snailTouchManager snailTouchManager = vizproximity.Manager() # snailTouchManager.setDebug(viz.ON) vizact.onkeydown('k',snailTouchManager.setDebug,viz.TOGGLE) #adding sensor for the flag pile global flagPileManager flagPileSensor = vizproximity.Sensor(vizproximity.Sphere(.3,center=[1.3, -1.23484, 0.8]), source=flagPile) flagPileManager = vizproximity.Manager() flagPileManager.addSensor(flagPileSensor) vizact.onkeydown(';', flagPileManager.setDebug, viz.TOGGLE) #scavengerHuntStartSound.play() #vizact.onsensordown(globals_oa.wiimote, globals_oa.wii.BUTTON_B,selectObject) if (globals_oa.hmdUsed == globals_oa.HMD_TYPE['VIVE']) and (globals_oa.rhViveTracker is not None): print "USING VIVE" #vizact.onsensordown(globals_oa.rhViveTracker, steamvr.BUTTON_TRIGGER,selectObject) # if globals_oa.rhViveTracker: # handModel1 = globals_oa.rhViveTracker.addModel() # link1 = viz.link(globals_oa.rightHandLink, handModel1) # if globals_oa.lhViveTracker: # handModel2 = globals_oa.lhViveTracker.addModel() # link2 = viz.link(globals_oa.leftHandLink, handModel2) # from tools import grabber # from tools import highlighter # global rhtool, lhtool # # if rhtool is None: # rhtool = grabber.Grabber(usingPhysics=False, usingSprings=False, highlightMode=highlighter.MODE_BOX) # if lhtool is None: # lhtool = grabber.Grabber(usingPhysics=False, usingSprings=False, highlightMode=highlighter.MODE_BOX) # rhtool.setUpdateFunction(rUpdateGrabber) # if globals_oa.rhModel is not None:rhtool.setParent(globals_oa.rhModel) # # lhtool.setUpdateFunction(lUpdateGrabber) # if globals_oa.lhModel is not None: lhtool.setParent(globals_oa.lhModel) #sphere = vizshape.addSphere(radius = 0.3) #sphere.setParent(globals_oa.rhModel) global rhandtar, lhandtar if globals_oa.rhModel is not None: rhsphere = vizshape.addSphere(radius = 0.05) rhsphere.setParent(globals_oa.rhModel) rhsphere.setPosition([0,0,.55]) rhsphere.disable(viz.RENDERING) rhandtar = vizproximity.Target(rhsphere)#globals_oa.rhModel) snailTouchManager.addTarget(rhandtar) flagPileManager.addTarget(rhandtar) if globals_oa.lhModel is not None: lhsphere = vizshape.addSphere(radius = 0.05) lhsphere.setParent(globals_oa.lhModel) lhsphere.setPosition([0,0,.55]) lhsphere.disable(viz.RENDERING) lhandtar = vizproximity.Target(lhsphere)#globals_oa.lhModel) snailTouchManager.addTarget(lhandtar) flagPileManager.addTarget(lhandtar) # basketManager.addTarget(rhandtar) # basketManager.addTarget(lhandtar) #adding the sensors around the snails for snailAndFlagItem in globals_oa.snailAndFlagItemsInZone1: snailSensor = vizproximity.addBoundingSphereSensor(snailAndFlagItem.snailItemFromZoneModel, scale = (1.0)) snailTouchManager.addSensor(snailSensor) def EnterProximity(e): global snapFlagLeftHand, snapFlagRightHand if e.target == lhandtar: snapFlagLeftHand() elif e.target ==rhandtar: snapFlagRightHand() flagPileManager.onEnter(flagPileSensor, EnterProximity) #viz.link(globals_oa.rhModel, tool) # viz.callback(grabber.GRAB_EVENT,grabObject) # viz.callback(grabber.RELEASE_EVENT, releaseObject) snailTouchManager.onEnter(None, ShowFlagAtSnail) if globals_oa.currentZoneNumber == 1: globals_oa.MOVEMENT_DATA_RECORDING_TAG = globals_oa.TAG_SCAVENGER_HUNT_START_ZONE_1 else: globals_oa.MOVEMENT_DATA_RECORDING_TAG = globals_oa.TAG_SCAVENGER_HUNT_START_ZONE_3 global speciesIndex, numFound speciesIndex = 0 numFound = 0 viztask.schedule( findObject() )
# elif e.sensor == xyloBar10: # sp.playXylo32() # elif e.sensor == xyloBar10: # sp.playXylo33() # elif e.sensor == xyloBar10: # sp.playXylo34() # elif e.sensor == xyloBar10: # sp.playXylo35() # manager = vizproximity.Manager() manager.addTarget(rHandTar) manager.addTarget(lHandTar) xyloBar1 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_38"), scale=(1, 1, 1)) # #xyloBar2 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_39"),scale=(1,1,1))# #xyloBar3 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_40"),scale=(1,1,1))# #xyloBar4 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_41"),scale=(1,1,1))# #xyloBar5 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_42"),scale=(1,1,1))# #xyloBar6 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_43"),scale=(1,1,1))# #xyloBar7 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_44"),scale=(1,1,1))# #xyloBar8 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_45"),scale=(1,1,1))# #xyloBar9 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_46"),scale=(1,1,1))# #xyloBar10 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_47"),scale=(1,1,1))# #xyloBar11 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_48"),scale=(1,1,1))# #xyloBar12 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_49"),scale=(1,1,1))# #xyloBar13 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_50"),scale=(1,1,1))# #xyloBar14 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_51"),scale=(1,1,1))# #xyloBar15 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_52"),scale=(1,1,1))# #xyloBar16 = vizproximity.addBoundingBoxSensor(xylo.getChild("instance_53"),scale=(1,1,1))#
btn_regresa4.setPosition(0.9,0.1) vizact.onbuttonup(btn_regresa4, returntoMenu) ################################################################# ################################################################# #Create proximity manager manager = vizproximity.Manager() manager.setDebug(viz.ON) #Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView) manager.addTarget(target) sensorRock = vizproximity.addBoundingBoxSensor(rock,scale=[6,4,6]) manager.addSensor(sensorRock) #sensor = vizproximity.addBoundingSphereSensor(lamp,scale=2) #sensor = vizproximity.Sensor( vizproximity.RectangleArea([2,2],center=[lamp.getPosition(0)[0],0]), None ) #sensor = vizproximity.Sensor( vizproximity.RectangleArea([2,10],center=[gem.getPosition(0)[0],0]), None ) #sensor2 = vizproximity.Sensor( vizproximity.RectangleArea([2,10],center=[gem2.getPosition(0)[0],0]), None ) #sensor3 = vizproximity.Sensor( vizproximity.RectangleArea([2,10],center=[gem3.getPosition(0)[0],0]), None ) #sensor4 = vizproximity.Sensor( vizproximity.RectangleArea([2,10],center=[gem4.getPosition(0)[0],0]), None ) #manager.removeSensor(sensor) ''' manager.onEnter(sensor,EnterProximity) manager.onExit(sensor,ExitProximity) manager.onEnter(sensor2,EnterProximity) manager.onExit(sensor2,ExitProximity) manager.onEnter(sensor3,EnterProximity)
vizact.onbuttonup(btn_regresa5, returntoMenu) ################################################################# ################################################################# #Create proximity manager manager = vizproximity.Manager() manager.setDebug(viz.ON) #Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView) manager.addTarget(target) #Sensor boundary sensorGem12 = vizproximity.addBoundingBoxSensor(gem12, scale=[6, 4, 6]) sensorGem13 = vizproximity.addBoundingBoxSensor(gem13, scale=[6, 4, 6]) ######################################################################## sensorGem21 = vizproximity.addBoundingBoxSensor(gem13, scale=[6, 4, 6]) ######################################################################## sensorGem31 = vizproximity.addBoundingBoxSensor(gem31, scale=[6, 4, 6]) ######################################################################## ######################################################################## sensorGem51 = vizproximity.addBoundingBoxSensor(gem51, scale=[6, 4, 6]) sensorGem52 = vizproximity.addBoundingBoxSensor(gem52, scale=[6, 4, 6]) sensorGem53 = vizproximity.addBoundingBoxSensor(gem53, scale=[6, 4, 6]) ######################################################################## sensorPlane1 = vizproximity.addBoundingBoxSensor(plane1, scale=[10, 8, 8]) sensorPlane2 = vizproximity.addBoundingBoxSensor(plane2, scale=[10, 10, 10]) sensorPlane3 = vizproximity.addBoundingBoxSensor(plane3, scale=[10, 10, 10])
def initializeBoatGrabberAndPhysics(): global grabberTool, boatObjectsToGrab, ALL_GRABBED_EVENT #physics stuff # viz.phys.disable() # Enable physics # viz.phys.enable() # Enable physics globals_oa.boat.collideMesh() # globals_oa.boat.disable( viz.DYNAMICS ) usingPhysics=False from tools import grabber from tools import highlighter global rhGrabber, lhGrabber if rhGrabber is None: rhGrabber = grabber.Grabber(usingPhysics=False, usingSprings=False, highlightMode=highlighter.MODE_BOX) if lhGrabber is None: lhGrabber = grabber.Grabber(usingPhysics=False, usingSprings=False, highlightMode=highlighter.MODE_BOX) rhGrabber.setUpdateFunction(rUpdateGrabberOnBoat) if globals_oa.rhModel is not None: rhGrabber.setParent(globals_oa.rhModel) lhGrabber.setUpdateFunction(lUpdateGrabberOnBoat) if globals_oa.lhModel is not None: lhGrabber.setParent(globals_oa.lhModel) boatObjectsToGrab = [] #read object list from txt file filePointerToBoatGrabbableList = open(globals_oa.filePathToBoatItemsToGrab, 'r') for line in filePointerToBoatGrabbableList: s = line.strip('\n').split(' ') print s if globals_oa.boat is not None: if s[0] != "combine": item = globals_oa.boat.getChild(s[0]) if item: boatObjectsToGrab.append(item) item.collideBox() else: item1 = globals_oa.boat.getChild(s[1]) if item1: boatObjectsToGrab.append(item1) item2 = globals_oa.boat.getChild(s[2]) if item2: linkBetweenTwoSeparateModelsWhichNeedToBeTogether = viz.link(item1, item2) rhGrabber.setItems(boatObjectsToGrab) lhGrabber.setItems(boatObjectsToGrab) viz.callback(grabber.GRAB_EVENT,grabObject) viz.callback(grabber.RELEASE_EVENT, releaseObject) #proximity stuff basketOnBoat = globals_oa.boat.getChild('diveBasket.OSGB') global basketManager basketManager = vizproximity.Manager() basketSensor = vizproximity.addBoundingBoxSensor(basketOnBoat, scale = (1.5, 4.5, 1.5)) basketManager.addSensor(basketSensor) # basketManager.onEnter(None, objectBasketed) global rhandtar, lhandtar rhsphere = vizshape.addSphere(radius = 0.05) rhsphere.setParent(globals_oa.rhModel) rhsphere.setPosition([0,0,.55]) rhsphere.disable(viz.RENDERING) lhsphere = vizshape.addSphere(radius = 0.05) lhsphere.setParent(globals_oa.lhModel) lhsphere.setPosition([0,0,.55]) lhsphere.disable(viz.RENDERING) if globals_oa.rhModel is not None:rhandtar = vizproximity.Target(rhsphere)#globals_oa.rhModel) if globals_oa.lhModel is not None:lhandtar = vizproximity.Target(lhsphere)#globals_oa.lhModel) basketManager.addTarget(rhandtar) basketManager.addTarget(lhandtar) ALL_GRABBED_EVENT = viz.getEventID("all items grabbed on the boat")
def pointerInput(mode, pointer,arena): viz.phys.enable() """ Initialize the pointer tool Mode selection: 0 - Keyboard driven 1 - Spacemouse (WARNING: potential conflict with camera mode 1) """ proxy = vizproximity.Manager() proxy.setDebug(viz.TOGGLE) theSensor = vizproximity.addBoundingBoxSensor(arena,scale=[.95,.95,.95]) theTarget = vizproximity.Target(pointer) proxy.addSensor(theSensor) proxy.addTarget(theTarget) def EnterProximity(e): #print('Hit the wall') pointer.setVelocity([0,0,0]) pointer.setAngularVelocity([0,0,0]) print(e.target.getPosition()) temp = e.target.getPosition() #pointer.setPosition([1,1,1]) def ExitProximity(e): #print('Hit the wall') x,y,z = pointer.getPosition() if(y < .4): y = .5 elif(y > 4.5 ): y = 4.4 if(abs(x) > abs(z) and abs(x) > 5): if(x<0): x = -4.9 else: x = 4.9 elif(abs(z) > 4): if(z<0): z = -3.9 elif(z>0): z = 3.9 pointer.setPosition(x,y,z) pointer.setVelocity([0,0,0]) pointer.setAngularVelocity([0,0,0]) proxy.onEnter(None,EnterProximity) proxy.onExit(None,ExitProximity) vizact.onkeydown('l',pointer.setPosition,[0,1,0]) vizact.onkeydown('l',pointer.setVelocity,[0,0,0]) vizact.onkeydown('l',pointer.setAngularVelocity,[0,0,0]) if mode == 0: # Keyboard driven pointer, in case you don't have a space mouse # wx/da/ez control #For keyboard controls the glove is only linked via orientation #linking via position was causing issues with the camera focusing feature #fixedRotation = viz.link(viz.MainView,pointer) #fixedRotation.setMask(viz.LINK_ORI) speed = 3.0 vizact.whilekeydown('w',pointer.setPosition,[0,vizact.elapsed(speed),0],viz.REL_LOCAL) vizact.whilekeydown('x',pointer.setPosition,[0,vizact.elapsed(-speed),0],viz.REL_LOCAL) vizact.whilekeydown('d',pointer.setPosition,[vizact.elapsed(speed),0,0],viz.REL_LOCAL) vizact.whilekeydown('a',pointer.setPosition,[vizact.elapsed(-speed),0,0],viz.REL_LOCAL) vizact.whilekeydown('e',pointer.setPosition,[0,0,vizact.elapsed(speed)],viz.REL_LOCAL) vizact.whilekeydown('z',pointer.setPosition,[0,0,vizact.elapsed(-speed)],viz.REL_LOCAL) elif mode == 1: # Set up pointer control with the Spacemouse connexion = viz.add('3dconnexion.dle') device = connexion.addDevice() def buttonPress(e): pointer.setPosition([0,1,0]) pointer.setVelocity([0,0,0]) pointer.setAngularVelocity([0,0,0]) viz.callback(viz.SENSOR_DOWN_EVENT,buttonPress) #device.setTranslateScale([1,1,1]) #device.setRotateScale([0,0,0]) # i don't think we need this #add 3Dnode object that follows mainview exactly, called MainViewShadow # MainViewShadow = vizshape.addSphere(radius = .5) # MainViewShadow.disable(viz.RENDERING) # viz.link(viz.MainView, MainViewShadow) #make glove () child of MainViewShadow #fixedRotation = viz.link(MainViewShadow,pointer) #fixedRotation.setMask(viz.LINK_ORI) #pointer.setParent(MainViewShadow) #call this every loop #all of this should likely go in controls, we need to fix controls!! -ADE def getCoords(source, destination): """ source should be a 3D connection device, and the destination should be a 3d node type """ def logScale(orientation): """ list or len() = 3 -> list of len 3 takes the orintation list and returns the log of the magnitude of each element , and then keeps the original sign ex) [ 10 , -10 ,1000] -> [1 , -1, 3] """ import math base = 2 mag_orientation = [] sign = [] #list of signs #make all elements positive, store original signs for element in orientation: if math.fabs(element) == element: #element is positive mag_orientation.append(element) sign.append(1) else: #element is negative mag_orientation.append(-1*element) sign.append(-1) #handle case where number is zero, and set to 1 n = 0 for element in mag_orientation: if element == 0: mag_orientation[n] = 1 n+=1 #take log of each element log_orientation=[] for element in mag_orientation: log = math.log(element, base) log_orientation.append(log) #restablish original signs orientation = scalarMult(sign, log_orientation) return orientation #set source scale # scale1 = [.0001,.0001,.0001] # scale2 =[.01,.01,.01] #log log = False while True: yield viztask.waitTime( .01 ) position = source.getRawTranslation() orientation = source.getRawRotation() #sets the velocity of the glove (destination) to zero destination.setVelocity([0,0,0], viz.ABS_GLOBAL) destination.setAngularVelocity([0,0,0] ,viz.ABS_GLOBAL) #if selected do log scale on orientation if log == True: config.orientationVector= [.5, .5 , .5] orientation = logScale(orientation) #rescale position position = scalarMult(position,config.positionVector) orientation = scalarMult(orientation,config.orientationVector) #invert signs of x and z x,y,z = position #invert signs of x and z rotations, and exchange b and a a,b,g = orientation orientation = [b,a,g] #print(orientation) destination.setPosition(position, viz.REL_PARENT) destination.setEuler(orientation, viz.REL_PARENT) def scalarMult(lst1,lst2): """ takes 2 lists, and returns the scalar multiplication of the lists *lists must be the same length """ new_lst = [] for i in range(len(lst1)): n_val = lst1[i]*lst2[i] new_lst.append(n_val) return new_lst #schedule controller loop with viztask scheduler viztask.schedule( getCoords(device,pointer)) #vizact.ontimer2(.01,1, delayedSet ) #viz.link(device, pointer, viz.REL_PARENT) #link.preEuler([0,90,0]) return device else: raise ValueError('Invaid control mode selection') #question guys. if keyboard is selected, should the init script call code #in the control module to set the functions? - Alex
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----------"
sphere3 = vizshape.addSphere(radius=.1) sphere3.setPosition(8.62, .3, 12) sphere3.color(0, 0, 1) #blue sphere3physics = sphere3.collideSphere(bounce=1.5) shapes = [sphere1, sphere2, sphere3] grabber = vizconnect.getRawTool('grabber') grabber.setItems(shapes) #rgb boxes p1 = vizshape.addCube(size=1) p1.color(1, 0, 0) p1.setPosition(9, 0, 10) p1p = p1.collideBox() sensor1 = vizproximity.addBoundingBoxSensor(p1) target1 = vizproximity.Target(sphere1) p2 = vizshape.addCube(size=1) p2.color(0, 1, 0) p2.setPosition(9, 0, 8) p2p = p2.collideBox() sensor2 = vizproximity.addBoundingBoxSensor(p2) target2 = vizproximity.Target(sphere2) p3 = vizshape.addCube(size=1) p3.color(0, 0, 1) p3.setPosition(9, 0, 6) p3p = p3.collideBox() sensor3 = vizproximity.addBoundingBoxSensor(p3) target3 = vizproximity.Target(sphere3)
dpos = Doorbath_GEODE.getPosition(viz.ABS_GLOBAL) new_dpos = [dpos[0], dpos[1], dpos[2] - 0.8] Doorbath_GEODE.setPosition(new_dpos, viz.ABS_GLOBAL) cpos = Circle_GEODE.getPosition(viz.ABS_GLOBAL) new_cpos = [cpos[0], cpos[1], cpos[2] - 0.75] Circle_GEODE.setPosition(new_cpos, viz.ABS_GLOBAL) state_doorbath = 1 doorSuich_bath = lab.getChild('Light_Switch out bathroom') sensor_doorSuichbath = vizproximity.addBoundingSphereSensor(doorSuich_bath, scale = 4) manager.addSensor(sensor_doorSuichbath) global sensor_planta node = viz.addChild('plant.osgb',pos=(0,0.58,5)) sensor_planta = vizproximity.addBoundingBoxSensor(node, scale = (2,10,2)) manager.addSensor(sensor_planta) #action = vizact.onpick(doorSuich_bath, doorbath) #action2 = vizact.onpick(Doorbath_GEODE, doorbath) #ABRIR Y CERRAR PUERTAS COCINA Y SALÓN DoorKitchen_GEODE = lab.getChild('Glass002-GEODE') DoorKit_frame_GEODE = lab.getChild('Door_Frame001-GEODE') DoorSalon_GEODE = lab.getChild('Glass004-GEODE') DoorSal_frame_GEODE = lab.getChild('Door_Frame003-GEODE') #def doorKitchen (e): #SALA RV def doorKitchen (): def openDoorKitchen ():
def swimFromZoneToZone(): global SWIM_ZONE_TO_ZONE_COMPLETE_EVENT, LOOKED_OPENING_EVENT, lookingOpeningTimer, skipKey yield viztask.waitEvent(scavengerhunt.ZONE1_OVER_EVENT) scavengerhunt.disableGrabber() globals_oa.ZONE1_AUDIO_1.stop() globals_oa.basket.disable(viz.RENDERING) # Uncomment next block for immediately fading to zone 3 from zone 1; comment out lines 783 to 881 to skip swimming through the trench # yield fader.fadeOutTask() # for school in schooling.all_fish_schools: # school.hidePercentage(50) # globals_oa.currentZoneNumber = 2 # transport_vhil.cycleZones() # yield fader.fadeInTask() #get the child of the zone1 to hide stuffToHide1 = globals_oa.terrainZone1.getChild('RemoveThisWall') stuffToHide1.visible(False) playAudioAndSaveGlobalPointer(globals_oa.ZONE3_TRANSITION) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.ZONE3_TRANSITION), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.ZONE3_TRANSITION.stop() #playAudioAndSaveGlobalPointer(globals_oa.ZONE3_TRANSITION2) #yield viztask.waitMediaEnd(globals_oa.ZONE3_TRANSITION2) #markAudioPlayAsEnded() vizact.onkeydown('q', shootForward) # viz.phys.disable() # Waits until the user has looked at the opening for 2 seconds before it starts swimming instructions viz.setCollectRenderStats(True) lookingOpeningTimer = vizact.ontimer(0.1, lookingAtOpening) yield viztask.waitAny([viztask.waitEvent(LOOKED_OPENING_EVENT), skipKey]) #create proximity sensor for the swimming between zones swimBetweenZonesProximityManager = vizproximity.Manager() # swimBetweenZonesProximityManager.setDebug(viz.ON) swimBetweenZonesProximityTarget = vizproximity.Target(viz.MainView) swimBetweenZonesProximityManager.addTarget(swimBetweenZonesProximityTarget) #create a box to act as the end of tunnel sensor, for zone-to-zone swimming endOfTunnelBox = vizshape.addBox(size = [3.0, 3.0, 3.0]) endOfTunnelBox.setPosition(globals_oa.CURRENT_ABS_POS_OF_END_OF_ZONE_TO_ZONE_TUNNEL) endOfTunnelBox.visible(False) zone3Sensor = vizproximity.addBoundingBoxSensor(endOfTunnelBox) swimBetweenZonesProximityManager.addSensor(zone3Sensor) swimBetweenZonesProximityManager.onEnter(zone3Sensor, EnterZone3Proximity) #create a sensor around the tube through the tunnel tunnelBox1 = globals_oa.terrainZone1.getChild('Box001') tunnelBox2 = globals_oa.terrainZone1.getChild('Box002') tunnelBox3 = globals_oa.terrainZone1.getChild('Box003') tunnelBox4 = globals_oa.terrainZone1.getChild('Box004') tunnelBox1.visible(False) tunnelBox2.visible(False) tunnelBox3.visible(False) tunnelBox4.visible(False) tunnelBoxSensor1 = vizproximity.addBoundingBoxSensor(tunnelBox1) tunnelBoxSensor2 = vizproximity.addBoundingBoxSensor(tunnelBox2) tunnelBoxSensor3 = vizproximity.addBoundingBoxSensor(tunnelBox3) tunnelBoxSensor4 = vizproximity.addBoundingBoxSensor(tunnelBox4) boundingBox = stuffToHide1.getBoundingBox() trackerLink = viz.link(stuffToHide1, viz.NullLinkable) tunnelOpeningSensor = vizproximity.Sensor(vizproximity.Box([boundingBox.width * 0.6, boundingBox.height * 0.3, boundingBox.depth * 1.2], [boundingBox.center[0] + 2.2, boundingBox.center[1], boundingBox.center[2] + 2]), trackerLink) swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor1) swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor2) swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor3) swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor4) swimBetweenZonesProximityManager.addSensor(tunnelOpeningSensor) swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor1, EnterTunnelTube) swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor2, EnterTunnelTube) swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor3, EnterTunnelTube) swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor4, EnterTunnelTube) swimBetweenZonesProximityManager.onEnter(tunnelOpeningSensor, EnterTunnelOpening) swimBetweenZonesProximityManager.onExit(tunnelBoxSensor1, ExitTunnelTube) swimBetweenZonesProximityManager.onExit(tunnelBoxSensor2, ExitTunnelTube) swimBetweenZonesProximityManager.onExit(tunnelBoxSensor3, ExitTunnelTube) swimBetweenZonesProximityManager.onExit(tunnelBoxSensor4, ExitTunnelTube) swimBetweenZonesProximityManager.onExit(tunnelOpeningSensor, ExitTunnelOpening) #turning on swimming transport_vhil.onKeyDown('g') playAudioAndSaveGlobalPointer(globals_oa.SWIMMING_INSTRUCTIONS) viztask.schedule(swimTutorial) viztask.schedule(removeGhostHands) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.SWIMMING_INSTRUCTIONS), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.SWIMMING_INSTRUCTIONS.stop() # print "waiting for swimming to end" yield viztask.waitAny([viztask.waitEvent(SWIM_ZONE_TO_ZONE_COMPLETE_EVENT), skipKey]) viztask.schedule(startZone3Hunt())
def startBoatIntro(): global boatScene, ALL_GRABBED_EVENT, wheel, radius, wheelTimer, skipKey # hideOceanScene() # FADE_IN_TIME = 4 globals_oa.user.setPosition([0,0,0]) # yield fader.fadeOutTask() yield fader.fadeInTask() #1.5 yield viztask.waitTime(4) #4 yield fader.fadeOutTask() #1.5 yield crystalBallScene() yield cityScene() yield globals_oa.AUDIO_BOAT_AMBIENT_INTRO.play() yield fader.fadeInTask() #1.5 yield viztask.waitTime(globals_oa.BETWEEN_FADING_TIME - 1) #4 yield fader.fadeOutTask() #1.5 yield viztask.waitTime(1) boatscene.unhideBoatAndIschia() yield fader.fadeInTask() # Next few blocks of code for making the steering wheel on the boat spin wheel = globals_oa.boat.getChild('steeringWheel') box = wheel.getBoundingBox() wheel.setCenter(box.center) radius = box.height / 2 wheelTimer = vizact.ontimer(0.01, rotateWheel, radius) wheelManager = vizproximity.Manager() global rhandtar, lhandtar rhsphere = vizshape.addSphere(radius = 0.05) rhsphere.setParent(globals_oa.rhModel) rhsphere.setPosition([0,0,.55]) rhsphere.disable(viz.RENDERING) lhsphere = vizshape.addSphere(radius = 0.05) lhsphere.setParent(globals_oa.lhModel) lhsphere.setPosition([0,0,.55]) lhsphere.disable(viz.RENDERING) if globals_oa.rhModel is not None:rhandtar = vizproximity.Target(rhsphere)#globals_oa.rhModel) if globals_oa.lhModel is not None:lhandtar = vizproximity.Target(lhsphere)#globals_oa.lhModel) wheelManager.addTarget(rhandtar) wheelManager.addTarget(lhandtar) wheelSource = vizshape.addBox([box.width - 2, box.height, box.depth - 2]) wheelSource.setPosition([box.center[0] - 3.65, box.center[1], box.center[2] + 0.83]) wheelSource.visible(False) wheelSensor = vizproximity.addBoundingBoxSensor(wheelSource) wheelManager.addSensor(wheelSensor) # wheelManager.setDebug(viz.ON) wheelManager.onEnter(wheelSensor, enterWheel) wheelManager.onExit(wheelSensor, exitWheel) ####new audio additions yield viztask.waitAny([viztask.waitTime(globals_oa.INITIAL_WAIT_TIME), skipKey]) # yield globals_oa.BOAT_AUDIO_INTRO_1.play() playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_1) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_1), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.BOAT_AUDIO_INTRO_1.stop() else: yield viztask.waitAny([viztask.waitTime(2), skipKey]) ### loadDisabledZonesAndInitWorldvizCode() boatscene.Quad1() # yield globals_oa.BOAT_AUDIO_INTRO_2.play() playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_2) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_2), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.BOAT_AUDIO_INTRO_2.stop() else: yield viztask.waitAny([viztask.waitTime(3), skipKey]) boatscene.Quad2() # yield globals_oa.BOAT_AUDIO_INTRO_3.play() playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_3) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_3), skipKey]) if result.condition is skipKey: globals_oa.BOAT_AUDIO_INTRO_3.stop() else: yield viztask.waitAny([viztask.waitTime(3), skipKey]) boatscene.Quad3() # yield globals_oa.BOAT_AUDIO_INTRO_4.play() playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_4) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_4), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.BOAT_AUDIO_INTRO_4.stop() else: yield viztask.waitAny([viztask.waitTime(3), skipKey]) yield globals_oa.CANVAS_QUAD.visible(False) globals_oa.CANVAS_QUAD_3_TEXTURE.remove() #grab on boat: start #init grab on boat initializeBoatGrabberAndPhysics() # yield globals_oa.BOAT_AUDIO_INTRO_5.play() playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_5) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_5), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.BOAT_AUDIO_INTRO_5.stop() #adding a 1 min slot for grab testing on boat yield viztask.waitAny( [viztask.waitTime(1 * 60), viztask.waitEvent(ALL_GRABBED_EVENT), skipKey]) #stop grabbing, now that you are going underwater! disableBoatGrabberAndPhysics() wheelTimer.setEnabled(0) #grab on boat: end yield fader.fadeOutTask() boatscene.hideScene() enableOceanScene() #hiding the tunnel boxes before diving underwater tunnelBox1 = globals_oa.terrainZone1.getChild('Box001') tunnelBox2 = globals_oa.terrainZone1.getChild('Box002') tunnelBox3 = globals_oa.terrainZone1.getChild('Box003') tunnelBox4 = globals_oa.terrainZone1.getChild('Box004') tunnelBox1.visible(False) tunnelBox2.visible(False) tunnelBox3.visible(False) tunnelBox4.visible(False) globals_oa.AUDIO_BOAT_AMBIENT_INTRO.stop() # globals_oa.ZONE1_TRANSITION.play() playAudioAndSaveGlobalPointer(globals_oa.ZONE1_TRANSITION) globals_oa.AUDIO_BOAT_AMBIENT_SPLASH.play() # yield viztask.waitMediaEnd(globals_oa.AUDIO_BOAT_AMBIENT_SPLASH) result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.ZONE1_TRANSITION), skipKey]) markAudioPlayAsEnded() if result.condition is skipKey: globals_oa.ZONE1_TRANSITION.stop() #viz.res.addPublishFile('data/speciesToFindZone1.txt') scavengerhunt.initialize(globals_oa.terrainZone1, globals_oa.filePathToSpeciesForScavengerHuntInZone1) # transport_vhil.onKeyDown('g') viztask.schedule(swimFromZoneToZone()) #the scheduling below is moved to swimFromZoneToZone # viztask.schedule(startZone3Hunt()) yield fader.fadeInTask() # removeSphere() # showOceanScene() globals_oa.AUDIO_ZONE1_AMBIENT.play() globals_oa.ZONE1_AUDIO_1.play()
def pointerInput(mode, pointer, arena): viz.phys.enable() """ Initialize the pointer tool Mode selection: 0 - Keyboard driven 1 - Spacemouse (WARNING: potential conflict with camera mode 1) """ proxy = vizproximity.Manager() proxy.setDebug(viz.TOGGLE) theSensor = vizproximity.addBoundingBoxSensor(arena, scale=[.95, .95, .95]) theTarget = vizproximity.Target(pointer) proxy.addSensor(theSensor) proxy.addTarget(theTarget) def EnterProximity(e): #print('Hit the wall') pointer.setVelocity([0, 0, 0]) pointer.setAngularVelocity([0, 0, 0]) print(e.target.getPosition()) temp = e.target.getPosition() #pointer.setPosition([1,1,1]) def ExitProximity(e): #print('Hit the wall') x, y, z = pointer.getPosition() if (y < .4): y = .5 elif (y > 4.5): y = 4.4 if (abs(x) > abs(z) and abs(x) > 5): if (x < 0): x = -4.9 else: x = 4.9 elif (abs(z) > 4): if (z < 0): z = -3.9 elif (z > 0): z = 3.9 pointer.setPosition(x, y, z) pointer.setVelocity([0, 0, 0]) pointer.setAngularVelocity([0, 0, 0]) proxy.onEnter(None, EnterProximity) proxy.onExit(None, ExitProximity) vizact.onkeydown('l', pointer.setPosition, [0, 1, 0]) vizact.onkeydown('l', pointer.setVelocity, [0, 0, 0]) vizact.onkeydown('l', pointer.setAngularVelocity, [0, 0, 0]) if mode == 0: # Keyboard driven pointer, in case you don't have a space mouse # wx/da/ez control #For keyboard controls the glove is only linked via orientation #linking via position was causing issues with the camera focusing feature #fixedRotation = viz.link(viz.MainView,pointer) #fixedRotation.setMask(viz.LINK_ORI) speed = 3.0 vizact.whilekeydown('w', pointer.setPosition, [0, vizact.elapsed(speed), 0], viz.REL_LOCAL) vizact.whilekeydown('x', pointer.setPosition, [0, vizact.elapsed(-speed), 0], viz.REL_LOCAL) vizact.whilekeydown('d', pointer.setPosition, [vizact.elapsed(speed), 0, 0], viz.REL_LOCAL) vizact.whilekeydown('a', pointer.setPosition, [vizact.elapsed(-speed), 0, 0], viz.REL_LOCAL) vizact.whilekeydown('e', pointer.setPosition, [0, 0, vizact.elapsed(speed)], viz.REL_LOCAL) vizact.whilekeydown('z', pointer.setPosition, [0, 0, vizact.elapsed(-speed)], viz.REL_LOCAL) elif mode == 1: # Set up pointer control with the Spacemouse connexion = viz.add('3dconnexion.dle') device = connexion.addDevice() def buttonPress(e): pointer.setPosition([0, 1, 0]) pointer.setVelocity([0, 0, 0]) pointer.setAngularVelocity([0, 0, 0]) viz.callback(viz.SENSOR_DOWN_EVENT, buttonPress) #device.setTranslateScale([1,1,1]) #device.setRotateScale([0,0,0]) # i don't think we need this #add 3Dnode object that follows mainview exactly, called MainViewShadow # MainViewShadow = vizshape.addSphere(radius = .5) # MainViewShadow.disable(viz.RENDERING) # viz.link(viz.MainView, MainViewShadow) #make glove () child of MainViewShadow #fixedRotation = viz.link(MainViewShadow,pointer) #fixedRotation.setMask(viz.LINK_ORI) #pointer.setParent(MainViewShadow) #call this every loop #all of this should likely go in controls, we need to fix controls!! -ADE def getCoords(source, destination): """ source should be a 3D connection device, and the destination should be a 3d node type """ def logScale(orientation): """ list or len() = 3 -> list of len 3 takes the orintation list and returns the log of the magnitude of each element , and then keeps the original sign ex) [ 10 , -10 ,1000] -> [1 , -1, 3] """ import math base = 2 mag_orientation = [] sign = [] #list of signs #make all elements positive, store original signs for element in orientation: if math.fabs(element) == element: #element is positive mag_orientation.append(element) sign.append(1) else: #element is negative mag_orientation.append(-1 * element) sign.append(-1) #handle case where number is zero, and set to 1 n = 0 for element in mag_orientation: if element == 0: mag_orientation[n] = 1 n += 1 #take log of each element log_orientation = [] for element in mag_orientation: log = math.log(element, base) log_orientation.append(log) #restablish original signs orientation = scalarMult(sign, log_orientation) return orientation #set source scale # scale1 = [.0001,.0001,.0001] # scale2 =[.01,.01,.01] #log log = False while True: yield viztask.waitTime(.01) position = source.getRawTranslation() orientation = source.getRawRotation() #sets the velocity of the glove (destination) to zero destination.setVelocity([0, 0, 0], viz.ABS_GLOBAL) destination.setAngularVelocity([0, 0, 0], viz.ABS_GLOBAL) #if selected do log scale on orientation if log == True: config.orientationVector = [.5, .5, .5] orientation = logScale(orientation) #rescale position position = scalarMult(position, config.positionVector) orientation = scalarMult(orientation, config.orientationVector) #invert signs of x and z x, y, z = position #invert signs of x and z rotations, and exchange b and a a, b, g = orientation orientation = [b, a, g] #print(orientation) destination.setPosition(position, viz.REL_PARENT) destination.setEuler(orientation, viz.REL_PARENT) def scalarMult(lst1, lst2): """ takes 2 lists, and returns the scalar multiplication of the lists *lists must be the same length """ new_lst = [] for i in range(len(lst1)): n_val = lst1[i] * lst2[i] new_lst.append(n_val) return new_lst #schedule controller loop with viztask scheduler viztask.schedule(getCoords(device, pointer)) #vizact.ontimer2(.01,1, delayedSet ) #viz.link(device, pointer, viz.REL_PARENT) #link.preEuler([0,90,0]) return device else: raise ValueError('Invaid control mode selection') #question guys. if keyboard is selected, should the init script call code #in the control module to set the functions? - Alex
def goBoat(): global skipKey, bigCO2, bigH2O, boatProximityManager, h2co3molecule, footprints, rightHandTarget, leftHandTarget, h2co3FormationTriggered ##### ** participant is standing on the back platform of the boat** #load the environment if not already loaded # print "waiting for city scene to end" # yield viztask.waitEvent(globals_oa.CITY_SCENE_END_EVENT) # print "received city end event" loadStuffAtStartAndHideThemALL() print "starting molecule scene" # globals_oa.user.setPosition(globals_oa.boatSceneUserStartPos) #turning the user around globals_oa.user.setAxisAngle([0.0, 1.0, 0.0, 180.0]) #adding a manager for handling boat proximity events boatProximityManager = vizproximity.Manager() # boatProximityManager.setDebug(viz.ON) boatProximityManager.setDebugColor(viz.PURPLE) boatProximityManager.setDebugActiveColor(viz.GREEN) leftHandTarget = None rightHandTarget = None if globals_oa.lhModel != None: leftHandTarget = vizproximity.Target(globals_oa.leftHand) else: print "lhModel not set up" if globals_oa.rhModel != None: rightHandTarget = vizproximity.Target(globals_oa.rightHand) else: print "rhModel not set up" if globals_oa.fader is None: globals_oa.fader = View_Fader.addFader(fadeTime=5) globals_oa.BOAT_SCENE_AMBIENT.play() viz.fog(0) globals_oa.fader.fadeIn() globals_oa.fadingSphere.alpha(0) #unhide boat and stuff showStuff() # globals_oa.boat.enable(viz.RENDERING) ##### You’re now on a boat in the middle of the ocean. Look around and observe the CO2 molecules surrounding you. # globals_oa.BOAT_SCENE1.play() # print "playing BOAT_SCENE1 now" # yield viztask.waitAny([viztask.waitTime(29), skipKey]) ##### Look down at the floor and move so that you’re standing on top of the footprints. #####*wait until the participant is in the correct position to start* # TODO: add a position sensor for the viewpoint of the user to step in # boatProximityManager.clearTargets() # boatProximityManager.addTarget(vizproximity.Target(viz.MainView)) # boatProximityManager.clearSensors() # footprintsSensor = vizproximity.Sensor(vizproximity.RectangleArea([0.6, 0.6], center = globals_oa.footprintPos), None) # boatProximityManager.addSensor(footprintsSensor) # # boatProximityManager.onEnter(footprintsSensor, footprintSteppedOnEvent) # # print "waiting for the footprint event ..." # yield viztask.waitAny([viztask.waitEvent(globals_oa.FOOTPRINT_EVENT), skipKey]) #####Look at water behind the boat. The molecule you see floating on the ocean’s surface is a water molecule, also known as H2O. #####Now, remember that CO2 molecule from the car? It’s floating towards you right now. yield viztask.waitTime(12) #adds a little time before narration starts, not sure why the number has to be so large... globals_oa.BOAT_SCENE2.play() print "playing BOAT_SCENE2 now, which is atually the first boat scene" yield viztask.waitAny([viztask.waitTime(16), skipKey]) # yield viztask.waitAny([viztask.waitTime(globals_oa.BOAT_SCENE2.getDuration()), skipKey]) #####**molecule drops down at the back of the boat** print "showing the falling molecule and setting its animation time to 0.0" yield flyingCO2() #####To view the chemical reaction that occurs when CO2 is absorbed into the ocean, push the molecule over the side of the boat. globals_oa.BOAT_SCENE3.play() print "playing BOAT_SCENE3 now" yield viztask.waitAny([viztask.waitTime(15), skipKey]) #TODO: add a CO2 to the list of sensors in the molecule scene proximity manager boatProximityManager.clearTargets() if leftHandTarget is not None: boatProximityManager.addTarget(leftHandTarget) if rightHandTarget is not None: boatProximityManager.addTarget(rightHandTarget) boatProximityManager.clearSensors() co2Sensor = vizproximity.addBoundingBoxSensor(bigCO2) boatProximityManager.addSensor(co2Sensor) boatProximityManager.onEnter(co2Sensor, h2co3FormationTriggerEvent) print "waiting for the H2CO3 reaction-animation completion event ..." moleculePushFailAudio = globals_oa.BOAT_SCENE_TOUCH failTimer = vizact.ontimer(5 + moleculePushFailAudio.getDuration(), moleculePushFailAudio.play) yield viztask.waitAny([viztask.waitEvent(globals_oa.H2CO3_COMPLETION_EVENT), skipKey]) # yield skipKey # yield viztask.waitAny([viztask.waitTime(4), skipKey]) failTimer.remove() if not h2co3FormationTriggered: viztask.schedule(H2CO3formation()) #####Observe the chemical reaction. When carbon dioxide, or CO2, is absorbed into the ocean it reacts with seawater to form carbonic acid, or H2CO3. #####This process is called ocean acidification. If enough carbonic acid is created, the seawater becomes corrosive. #####The ocean covers over 70% of the Earth’s surface. Since the Industrial Revolution the ocean has absorbed #####roughly ¼ of the carbon dioxide produced by burning fossil fuels. #####We may not be able to see these reactions in our daily lives, but we can take a look at how these reactions affect marine life. #####You will now travel to a special site where scientists have made a breakthrough discovery about carbon dioxide emissions. globals_oa.BOAT_SCENE4.play() print "playing BOAT_SCENE4 now" yield viztask.waitAny([viztask.waitTime(22), skipKey]) #hide H2CO3 h2co3molecule.visible(viz.OFF) yield showHiddenMolecules() yield viztask.waitAny([viztask.waitTime(21), skipKey]) # print "waiting for a final skip key to fade out now - NOT PART OF THE NARRATION" # yield skipKey globals_oa.BOAT_SCENE_AMBIENT.stop() globals_oa.fader.fadeOut() #Cleanup hideStuff() #turning the user around globals_oa.user.setAxisAngle([0.0, 1.0, 0.0, 0.0]) viz.sendEvent(globals_oa.BOAT_SCENE_END_EVENT)
canvas12.setEuler(0, 0, 0) vizact.onbuttonup(btn_regresa1, returntoMenu) ################################################################# ################################################################# #Create proximity manager manager = vizproximity.Manager() manager.setDebug(viz.ON) #Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView) manager.addTarget(target) sensorGem11 = vizproximity.addBoundingBoxSensor(gem11, scale=[6, 4, 6]) sensorGem12 = vizproximity.addBoundingBoxSensor(gem12, scale=[6, 4, 6]) manager.onEnter(sensorGem11, EnterGem, info11) manager.onEnter(sensorGem12, EnterGem, info12) vizact.onbuttonup(btn_regresa1, returntoMenu) vizact.onkeydown('d', manager.setDebug, viz.TOGGLE) #Menu principal bgTexture = viz.add(image['portada']) quad_bgtexture = viz.addTexQuad(parent=viz.SCREEN, scene=viz.Scene6) quad_bgtexture.texture(bgTexture) quad_bgtexture.setScale(12.8, 10.24, 0) #Escala a pantalla completa quad_bgtexture.setPosition(0.5, 0.5) #Centro de pantalla viz.scene(viz.Scene6) #Mostrar menú principal