def ChargePower(): #Get detailed information about where the mouse is pointed info = viz.pick(1) #Show and place marker based on intersection result marker.visible(info.valid) marker.setPosition(info.point) #Increment the amount of power charged up power.set(power.get() + 0.05)
def pushObject(): info = viz.pick( True ) #Get object that cursor is pointing at if info.valid and ( info.object == ball or info.object ==box ): #Create a vector from the mouse position into the world line = viz.MainWindow.screenToWorld(viz.mouse.getPosition()) vec = viz.Vector( line.dir ) vec.setLength( 1 ) info.object.applyForce( dir = vec, duration = 0.1, pos = info.point ) return True
def onMouseDown(self, button): if button == viz.MOUSEBUTTON_LEFT: print("left mouse pressed") self.obj = viz.pick() if self.obj == self.ball.getNode(): self.bz = self.z self.bx = self.x self.ball.setOrientation(self.x,.5,self.z+.2, .1, 0) self.picked = True
def onPick(): object = viz.pick() handle = pump.components['bypassL'] if object == handle: print 'valve picked' object.color(viz.GREEN, op=viz.OP_OVERRIDE) elif getattr(object, 'pick_parent', False): object.getParents()[0].color(viz.GREEN, op=viz.OP_OVERRIDE) else: handle.clearAttribute(viz.ATTR_COLOR, op=viz.OP_OVERRIDE)
def grabBall(): object = viz.pick( ) # Command detects which object the mouse is currently over and returns it if object == basketball: # Check to see if object is basketball print "You've clicked on the basketball" ser.writelines(b'T') # Turn led/thumb electrode on global link link = viz.grab(hand, basketball) # Use hand to grab basketball else: print "This is not a basketball"
def getPickInfo(self): """Returns selected cube environment's cube face and coordinates. (e.g. [[front][x,y,z]]""" info = viz.pick(info=True) picked = {} picked = { 'face': info.name, 'x': info.point[0], 'y': info.point[1], 'z': info.point[2] } return picked
def onMouseDown(self, button): if button == viz.MOUSEBUTTON_LEFT: print("Left Pressed") obj = viz.pick() if obj == self.desk.getNode(): print("desk") self.deskPressed = True self.shelfPressed = False elif obj == self.shelf.getNode(): print("shelf") self.deskPressed = False self.shelfPressed = True else: print("Neither") self.deskPressed = False self.shelfPressed = False
def onClick(self, click): if self.picking: choice = viz.pick(info=True) if choice.valid: if choice.object.id in [self.xWing.id, self.tie.id]: if choice.object.id == self.xWing.id: print("xwing") self.model = self.xWing self.tie.remove() self.winSong = 'audio/good-win.wav' self.loseSong = 'audio/good-fail.wav' self.ambient = viz.addAudio('audio/xWing-ambient.wav') self.ambient.loop(viz.ON) self.ambient.play() self.picking = False elif choice.object.id == self.tie.id: print("tie") self.model = self.tie self.rotmatrix.postAxisAngle(0, 1, 0, 180) self.xWing.remove() self.winSong = 'audio/bad-win.wav' self.loseSong = 'audio/bad-lose.wav' self.ambient = viz.addAudio('audio/tie-ambient.wav') self.ambient.loop(viz.ON) self.ambient.play() self.picking = False self.setOrientation() self.setView() self.trench = self.addTrench() self.trench.collideMesh() self.model.collideMesh() self.model.enable(viz.COLLIDE_NOTIFY) self.model.enable(viz.LIGHTING) self.starttimer(1, viz.FASTEST_EXPIRATION, viz.FOREVER) self.starttimer(3, 2, viz.FOREVER)
def onClick(self, click): if self.picking: choice = viz.pick(info=True) if choice.valid: if choice.object.id == self.xWing.id: print("xwing") self.model = self.xWing self.tie.remove() self.z += 10 self.picking = False elif choice.object.id == self.tie.id: print("tie") self.model = self.tie self.xWing.remove() self.z += 10 self.picking = False self.moveShip()
def getHittedObject(self, e): print 'hit1 =',e.obj1.name print 'hit2 =',e.obj2.name print 'nextShot = ',self.nextShot if e.obj2.name == "target" and self.nextShot == False : hitPosition = e.pos worldPosition = viz.worldtoscreen(hitPosition) pickedObject = viz.pick(pos = [worldPosition[0], worldPosition[1]], info = True, mode = viz.WORLD, all=True) count = len(pickedObject) hittedRing = '' for i in range(count): obj = pickedObject[i] name = obj.name print 'pickObject', i, ' = ', name if name in self.rings: hittedRing = name self.getHitPoint(hittedRing) return
def grabBall(): gesture = int(sensor.get()[-1]) gestureText.message(gestureName[gesture]) object = viz.pick( ) # Command detects which object the mouse is currently over and returns it if (gesture == 0) and (object == basketball): # Check to see if object is basketball print "closed fist - gripped basketball" # ser.writelines(b'T') global link link = viz.grab(hand, basketball) # Use hand to grab basketball glove.getSensorRawAll() else: print "This is not a basketball" # ser.writelines(b'L') vizact.ontimer(1, releaseBall) vizact.ontimer(2, releaseBall) vizact.ontimer(3, releaseBall) vizact.ontimer(4, releaseBall) vizact.ontimer(5, releaseBall) vizact.ontimer(6, releaseBall) vizact.ontimer(7, releaseBall) vizact.ontimer(8, releaseBall) vizact.ontimer(9, releaseBall) vizact.ontimer(10, releaseBall) vizact.ontimer(11, releaseBall) vizact.ontimer(12, releaseBall) vizact.ontimer(13, releaseBall) vizact.ontimer(14, releaseBall) vizact.ontimer(15, releaseBall) vizact.ontimer(16, releaseBall)
def ChargePower(): #Get detailed information about where the mouse is pointed info = viz.pick(1) marker.setPosition(info.point) #Increment the amount of power charged up power.set(power.get() + 0.05)
def onMouseDown(self,button): selectedObject = viz.pick() print(selectedObject.id)
def onMouseDown(self, button): selectedObject = viz.pick() print(selectedObject.id)
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) textbox1.message('you are at the public school') textbox1.add(fadeInOut) elif object.valid() and object == bomb_in_trashcan: 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) textbox1.message('you are at the park') textbox1.add(fadeInOut) elif object.valid() and object == police_station: 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) textbox1.message('you are at the police station') textbox1.add(fadeInOut) elif object.valid() and object == bomb_in_schoolbus: 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) textbox1.message('you are near to school bus') textbox1.add(fadeInOut) elif object.valid() and object == bomb_under_car_at_gas_station: 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) textbox1.message('you are at the gas station') textbox1.add(fadeInOut)