def __init__(self, fileName, SF=1.0 / 500): """Pull the BodyParts3D mesh into an instance and set everything up""" self.tooltip = None self.snapAttempts = 0 self.metaData = model.ds.getMetaData(file=fileName) self.centerPoint = self.metaData['centerPoint'] self.centerPointScaled = [a * SF for a in self.centerPoint] self.centerPointScaledFlipped = [a * SF * -1 for a in self.centerPoint] self._lineUpdateEvent = None self.name = self.metaData['name'] for region, names in config.OntologicalGroups.regions.iteritems(): files = model.ds.getOntologySet([(set.union, names)]) if self.metaData['filename'] in files: self.region = region break else: self.region = None self.nameFormatted = '' for i, w in enumerate(self.name.split()): if (i + 1) % 2 == 0 and i != 0: self.nameFormatted += w + '\n' else: self.nameFormatted += w + ' ' # We are using a 'center' viznode to make manipulation easy self.center = vizshape.addCube(0.001) # An arbitrary placeholder cube super(Mesh, self).__init__(self.center.id) # This is the actual mesh we will see self.mesh = viz.addChild(config.DATASET_PATH + fileName + '.obj') self.mesh.setScale([SF, SF, SF]) # This is the viznode that will be moved around to check distances for snapping self.checker = vizshape.addCube(0.001) # Setup heirarchy for proper movement behavior self.mesh.setParent(self) self.checker.setParent(self.mesh) # Offset mesh to lie in center of center viznode self.mesh.setPosition(self.centerPointScaledFlipped, viz.ABS_PARENT) self.checker.setPosition(self.centerPoint) # Turn off visibility of center and checker viznodes self.mesh.color(self.metaData['color']) self.checker.disable([viz.RENDERING, viz.INTERSECTION, viz.PHYSICS]) self.center.disable([viz.RENDERING, viz.INTERSECTION, viz.PHYSICS]) self.scale = SF self._enabled = True self.grounded = False self.grabbedFlag = 0 self.proxCounter = 0 # Group handling self.group = MeshGroup([self])
def __init__(self): # base class constructor viz.EventClass.__init__(self) self.desk = Model('desk\\model1.dae') self.shelf = Model('shelf\\model.dae') self.desk.setOrientation(3,0,4,1,90) self.shelf.setOrientation(0, .5, 0, 1, 0) self.deskPressed = False self.shelfPressed = False # set up keyboard and timer callback methods self.callback(viz.KEYDOWN_EVENT,self.onKeyDown) self.callback(viz.MOUSEDOWN_EVENT, self.onMouseDown) #avatar's postion and rotation angle self.x = 0.5 self.z = 0.5 self.theta = 0 # The 2D array below stores the representation of a maze. # Array entries containing a 2 represent 1 x 2 x 1 wall blocks. # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks. self.maze = [] self.maze = [[2,2,2,2,2,2,2,2,2]] + self.maze # row 8 self.maze = [[2,0,0,0,0,0,0,0,2]] + self.maze # row 7 self.maze = [[2,0,0,0,0,0,0,0,2]] + self.maze # row 6 self.maze = [[2,0,0,0,2,0,0,0,2]] + self.maze # row 5 self.maze = [[2,0,0,0,0,0,0,0,2]] + self.maze # row 4 self.maze = [[2,0,0,0,0,0,0,0,2]] + self.maze # row 2 self.maze = [[0,0,0,0,0,0,0,0,2]] + self.maze # row 0 self.maze = [[0,0,0,0,0,0,0,0,2]] + self.maze # row 1 self.maze = [[0,0,0,2,2,2,2,2,2]] + self.maze # row 0 # Add +x,+y,+z coordinate axes to scene to help with placing the blocks correctly self.addCoordinateAxes() # Code to create blocks forming the maze goes here for r in range(0,len(self.maze)): for c in range(0, len(self.maze[0])): if (self.maze[r][c] == 0): box = vizshape.addCube( size=1, color=viz.YELLOW ) mat = viz.Matrix() mat.postScale(1,.1,1) mat.postTrans(c+.5,0.05,r+.5) box.setMatrix( mat ) elif (self.maze[r][c] == 2): box = vizshape.addCube( size=1, color=viz.GREEN ) mat = viz.Matrix() mat.postScale(1,2,1) mat.postTrans(c+.5,1,r+.5) box.setMatrix( mat ) self.avatar = viz.add('vcc_female.cfg') mat = viz.Matrix() mat.postAxisAngle(0,1,0,self.theta) mat.postTrans(self.x,.1,self.z); self.avatar.setMatrix(mat) self.mode = "thirdperson"
def __init__(self): # base class constructor viz.EventClass.__init__(self) # set up keyboard and timer callback methods self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) # avatar's x,z location in maze and its rotation angle self.theta = 0 self.x = 0.5 self.z = 0.5 self.fp = False # The 2D array below stores the representation of a maze. # Array entries containing a 2 represent 1 x 2 x 1 wall blocks. # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks. self.maze = [] self.maze = [[2, 2, 2, 2, 2, 2, 2, 2, 2]] + self.maze # row 8 self.maze = [[2, 0, 0, 0, 0, 0, 0, 0, 2]] + self.maze # row 7 self.maze = [[2, 0, 0, 0, 0, 0, 0, 0, 2]] + self.maze # row 6 self.maze = [[2, 0, 0, 2, 2, 2, 0, 0, 2]] + self.maze # row 5 self.maze = [[2, 0, 0, 2, 2, 2, 0, 0, 2]] + self.maze # row 4 self.maze = [[2, 0, 0, 2, 2, 2, 0, 0, 2]] + self.maze # row 2 self.maze = [[0, 0, 0, 0, 0, 0, 0, 0, 2]] + self.maze # row 0 self.maze = [[0, 0, 0, 0, 0, 0, 0, 0, 2]] + self.maze # row 1 self.maze = [[0, 0, 0, 2, 2, 2, 2, 2, 2]] + self.maze # row 0 # Add +x,+y,+z coordinate axes to scene to help with placing the blocks correctly self.addCoordinateAxes() # Code to create blocks forming the maze goes here for x in range(0, len(self.maze)): for z in range(0, len(self.maze[0])): if self.maze[x][z] == 0: block = vizshape.addCube(size=1, color=viz.YELLOW) mat = viz.Matrix() mat.postScale(1, 0.1, 1) mat.postTrans(x + .5, .05, z + .5) block.setMatrix(mat) elif self.maze[x][z] == 2: block = vizshape.addCube(size=1, color=viz.GREEN) mat = viz.Matrix() mat.postScale(1, 2, 1) mat.postTrans(x + .5, 1, z + .5) block.setMatrix(mat) self.avatar = viz.add('vcc_female.cfg') mat = viz.Matrix() mat.postTrans(self.x, .1, self.z) self.avatar.setMatrix(mat) self.avatar.state(1)
def __init__(self): viz.callback(viz.COLLIDE_BEGIN_EVENT, onCollide) self.node = vizshape.addCube(TouchCube.DEFAULT_SIZE) viz.VizNode.__init__(self,self.node.id) self.collideBox() self.disable(viz.DYNAMICS) self.enable(viz.COLLIDE_NOTIFY) #BL:start if USING_VIZSONIC: if TouchCube.activateSound == None: TouchCube.activateSound = self.playsound("./Resources/Misc/tcActivate.wav", viz.STOP, volume=0.1) if TouchCube.bingSound == None: # Bing TouchCube.bingSound = self.playsound("./Resources/Misc/bingCropped.wav", viz.STOP, volume = 0.1) else: print "skipping those errors!" if TouchCube.activateSound == None: TouchCube.activateSound = self.playsound("./Resources/Misc/tcActivate_mono.wav", viz.STOP) if TouchCube.bingSound == None: # Bing TouchCube.bingSound = self.playsound("./Resources/Misc/bingCropped_mono.wav", viz.STOP) #BL:end self.color = self._changeColor self._dimColor = [1,1,1] self._isLit = False self.disabledTouchers = []
def makeDiamond(position, color): # diamond = vizshape.addCube(size=0.1) diamond = vizshape.addCube(size=0.07) diamond.setPosition(exp.shape_positions[position]) diamond.color(color) diamond.setEuler(15, 45, 0) return diamond
def __init__(self): viz.callback(viz.COLLIDE_BEGIN_EVENT, onCollide) self.node = vizshape.addCube(TouchCube.DEFAULT_SIZE) viz.VizNode.__init__(self,self.node.id) self.collideBox() self.disable(viz.DYNAMICS) self.enable(viz.COLLIDE_NOTIFY) #BL:start if some_global_variables.PPT1: if TouchCube.activateSound == None: TouchCube.activateSound = self.playsound(PATH_TO_STUFF + "./Resources/Misc/tcActivate.wav", viz.STOP, volume=0.1) if TouchCube.bingSound == None: # Bing TouchCube.bingSound = self.playsound(PATH_TO_STUFF + "./Resources/Misc/bingCropped.wav", viz.STOP, volume = 0.1) else: if TouchCube.activateSound == None: TouchCube.activateSound = self.playsound(PATH_TO_STUFF + "./Resources/Misc/tcActivate_mono.wav", viz.STOP) if TouchCube.bingSound == None: # Bing TouchCube.bingSound = self.playsound(PATH_TO_STUFF + "./Resources/Misc/bingCropped_mono.wav", viz.STOP) #BL:end self.color = self._changeColor self._dimColor = [1,1,1] self._isLit = False self.disabledTouchers = []
def __init__(self): self.delay = 3 viz.EventClass.__init__(self) self.cube = vizshape.addCube(size=1024, splitFaces=True) self.cube.disable(viz.RENDERING) self.current = 0 self.valid_pid = 0 self.savedb_all = [] #self.__button_press_cnt = 1 self.save_dbase = []
def __init__(self, meshes): """ Populate environment with bounding boxes allowing easy manipulation of subassemblies of the entire model. Currently partitioned by region. """ self.name = '' self._alpha = 0.3 self._members = [] self._keystones = [] self._pureKeystones = [] self.wireFrame = None self._showGroupFlag = True self.finishedRegion = False self.axis = vizshape.addAxes() self.cube = vizshape.addCube() super(BoundingBox, self).__init__(self.cube.id) self.cube.disable(viz.RENDERING) self.axis.setParent(self) self.axis.setScale([0.2, 0.2, 0.2]) self.addSensor() self.addMembers(meshes) self.regionGroup = RegionGroup([self]) # self.moveToCenter() # Add Bounding Box checker self.checker = vizshape.addCube(0.001) self.checker.setParent(self) self.checker.disable([viz.RENDERING,viz.INTERSECTION,viz.PHYSICS]) self.highlight(False) self._imploded = False
def rotateAbout(meshes, point, euler): pointCube = vizshape.addCube() pointCube.setPosition(point, viz.ABS_GLOBAL) for m in meshes: changeParent(m, pointCube) pointCube.setEuler(euler) for m in meshes: m.storeMat() m.setParent(viz.WORLD) m.setMatrix(m.loadMat()) pointCube.remove()
def startLeap(self, headset): # Create a listener and controller. self.controller = Leap.Controller() self.controller.add_listener(self) # Set controller policies for VR. self.controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) self.controller.set_policy(Leap.Controller.POLICY_OPTIMIZE_HMD) # Set up relationships for the hands, joints, bones to the head. self.hand_box = viz.addGroup() self.left_joints = viz.addGroup() self.left_bones = viz.addGroup() self.ljLink = viz.link(self.hand_box, self.left_joints) self.lbLink = viz.link(self.hand_box, self.left_bones) self.right_joints = viz.addGroup() self.right_bones = viz.addGroup() self.rjLink = viz.link(self.hand_box, self.right_joints) self.rbLink = viz.link(self.hand_box, self.right_bones) self.headlink = viz.link(headset, self.hand_box) self.headlink.preTrans([0,0,0.1143]) self.rhj = [] # right hand joints (knuckles) for i in range(23): if i is 0: self.rhj.append(vizshape.addSphere(.015)) else: self.rhj.append(vizshape.addSphere(self.JOINT_SIZE)) self.rhj[i].setParent(self.right_joints) self.rhb = [] # right hand bones for i in range(21): if (i == 12) or (i == 8) or (i >= 20) : self.rhb.append(vizshape.addCube(.01)) self.rhb[i].visible(viz.OFF) else: self.rhb.append(vizshape.addCylinder(1.0, self.FINGER_WIDTH, axis=vizshape.AXIS_Z)) self.rhb[i].setParent(self.right_bones) self.lhj = [] # left hand joints (knuckles) for i in range(23): if i is 0: self.lhj.append(vizshape.addSphere(.015)) else: self.lhj.append(vizshape.addSphere(self.JOINT_SIZE)) self.lhj[i].setParent(self.left_joints) self.lhb = [] # left hand bones for i in range(21): if (i == 12) or (i == 8) or (i >= 20) : self.lhb.append(vizshape.addCube(0.01)) self.lhb[i].visible(viz.OFF) else: self.lhb.append(vizshape.addCylinder(1.0, self.FINGER_WIDTH, axis=vizshape.AXIS_Z)) self.lhb[i].setParent(self.left_bones) self.right_bones.color(viz.WHITE) self.left_bones.color(viz.WHITE) self.right_joints.color(viz.AZURE) self.left_joints.color(viz.AZURE) self.initialized = True print 'Initialized the Hands!'
def __init__(self, fileName, SF = 1.0/200): """Pull the BodyParts3D mesh into an instance and set everything up""" self.metaData = ds.getMetaData(file = fileName) self.centerPoint = self.metaData['centerPoint'] self.centerPointScaled = [a*SF for a in self.centerPoint] self.centerPointScaledFlipped = [a*SF*-1 for a in self.centerPoint] print self.centerPointScaledFlipped self.name = self.metaData['name'] self.nameFormatted = '' for i, w in enumerate(self.name.split()): if (i + 1) % 2 == 0 and i != 0: self.nameFormatted += w + '\n' else: self.nameFormatted += w + ' ' #give a bone an information property # self.info = '' # for j,bd in enumerate(boneDesc['info'].split()): # if(j+1) % 10 ==0 and j != 0: # self.info += bd + ' \n' # else: # self.info += bd + ' ' # We are using a 'center' viznode to make manipulation easy self.center = vizshape.addCube(0.1) # An arbitrary placeholder cube super(Mesh, self).__init__(self.center.id) # This is the actual mesh we will see self.mesh = viz.addChild(config.DATASET_PATH + fileName + '.obj') self.mesh.setScale([SF,SF,SF]) # This is the viznode that will be moved around to check distances for snapping self.checker = vizshape.addCube(10.0) # Tooltip self.tooltip = viz.addText(self.nameFormatted) self.tooltip.color(0,5,1) self.tooltip.billboard(viz.BILLBOARD_VIEW) self.tooltip.setScale(0.001,0.001,0.001) #small scale for bounding box calc #Description # if display.displayMode == 2: # self.dialogue = viz.addText(self.info,pos = [0,3,0],parent=viz.WORLD) # self.dialogue.billboard(viz.BILLBOARD_VIEW) # self.dialogue.setBackdrop(viz.BACKDROP_CENTER_TOP) # self.dialogue.setScale(0.15,0.15,0.15) # self.dialogue.alignment(viz.ALIGN_CENTER_CENTER) # #self.dialogue.setPosition([0.03,0.85,0]) # #self.dialogue.color(viz.BLACK) # else: # self.dialogue = viz.addText(self.info,parent=viz.SCREEN) # #self.dialogue.setBackdrop(viz.BACKDROP_CENTER_TOP) # self.dialogue.setScale(0.3,0.3,0.0) # self.dialogue.alignment(viz.ALIGN_LEFT_BOTTOM) # self.dialogue.setPosition([0.03,0.85,0]) # #self.dialogue.color(viz.BLACK) # Setup heirarchy for proper movement behavior self.mesh.setParent(self) self.tooltip.setParent(self.center) self.checker.setParent(self.mesh) # Offset mesh to lie in center of center viznode self.mesh.setPosition(self.centerPointScaledFlipped, viz.ABS_PARENT) self.checker.setPosition(self.centerPoint) self.addSensor() # Tooltip formatting self.tooltip.setScale(0.1,0.1,0.1)#set to prefered scale self.tooltip.setPosition(0,0,-1) self.tooltip.alignment(viz.TEXT_CENTER_CENTER) self.tooltip.visible(viz.OFF) #Line between tooltip and mesh centerPoint # viz.startLayer(viz.LINES) # viz.vertexColor(viz.BLUE) # viz.lineWidth(5) # viz.vertex(self.getPosition(viz.ABS_GLOBAL)) # viz.vertex(self.tooltip.getPosition(viz.ABS_GLOBAL)) # self.nameLine = viz.endLayer() # self.nameLine.dynamic() # self.nameLine.visible(viz.OFF) # Turn off visibility of center and checker viznodes self.center.disable([viz.RENDERING]) self.color([0.3,0,0]) self.checker.disable([viz.RENDERING,viz.INTERSECTION,viz.PHYSICS]) self.scale = SF self._enabled = True self.nameAudioFlag = 1 #defualt: 1, 1 allows name to be played, 0 does not allow name playback self.descAudioFlag = 1 #default: 1, 1 allows description to be played, 0 does not allow dec playback self.grabbedFlag = 0 self.proxCounter = 0 # Group handling self.group = BoneGroup([self]) groups.append(self.group)
sphere2 = vizshape.addSphere(radius=.1) sphere2.setPosition(9.62, .3, 12) sphere2.color(0, 1, 0) #green sphere2physics = sphere2.collideSphere(bounce=1.5) 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)
def __init__(self, x, y, z): self.body = vizshape.addCube(1) self.body.setPosition([x, y, z]) self.body.color([200, 0, 0]) print("Apple generated.")
def __init__(self): self.mylight = viz.addLight() self.mylight.position(9, 500, -25) self.mylight.color(.3, .3, .3) # base class constructor self.boolean = False viz.EventClass.__init__(self) self.callback(viz.TIMER_EVENT, self.onTimer) self.starttimer(1, 1 / 5.0, viz.FOREVER) self.cyl1hei = 0 self.bZ = 0 self.startbZ = 0 self.ang = 10 self.tower = 1 self.score = 0 self.life = 5 self.t = viz.addText("Score:" + "" + ` self.score `, viz.SCREEN, pos=[0, 0, 0]) self.t.fontSize(100) self.t.font('Chiller') self.t1 = viz.addText("Lives:" + "" + ` self.life `, viz.SCREEN, pos=[0.8, 0, 0]) self.t1.fontSize(100) self.t1.font('Chiller') self.bullet = None # Load texture pic = viz.addTexture('start.jpg') # Create surface to wrap the texture on self.start = viz.addTexQuad() mat = viz.Matrix() mat.postScale(1.995, 1.5, 1.5) self.start.setMatrix(mat) self.start.setPosition([0, 0, 0]) #put quad in view # Wrap texture on quad self.start.texture(pic) self.t1.remove() self.t.remove() #snow self.bigSnowman = Model('snowman\\model.dae') self.snowman = Model('snowman\\model.dae') self.glacier = Model('glacier\\model.dae') self.bigGlacier = Model('glacier\\model.dae') self.bigSnowman.setOrientation(8, .1, 5, .5, -50) self.snowman.setOrientation(3.1, .1, .7, .2, 75) self.glacier.setOrientation(7, .1, 2, .2, -90) self.bigGlacier.setOrientation(2.7, .1, 4.5, .32, 0) #desert self.bigPyr = Model('pyramidsmooth\\model.dae') self.pyr = Model('pyramidsmooth\\model.dae') self.sphinx = Model('sphinx\\model.dae') self.bigSphinx = Model('sphinx\\model.dae') self.bigPyr.setOrientation(7.3, -0.2, 12, .7, -50) self.pyr.setOrientation(8, -0.2, 17, .4, 75) self.sphinx.setOrientation(5.5, 0.2, 15.1, .6, 0) self.bigSphinx.setOrientation(2.9, 0.1, 10, 2, -90) #city self.city = Model('city\\model.dae') self.sCity = Model('city\\model.dae') self.empstbu = Model('empire\\model.dae') self.skyskr = Model('skyskraper\\model.dae') self.towe = Model('tower\\model.dae') self.city.setOrientation(14, 0.2, 9.8, .0087, 0) self.sCity.setOrientation(13, 0.2, 13.4, .006, 180) self.empstbu.setOrientation(14.8, -0.1, 15.17, .0082, 0) self.skyskr.setOrientation(11.8, 0.2, 9.7, .006, 0) self.towe.setOrientation(11.5, 0.2, 15.5, .03, 0) #forest self.fores = Model('forest\\model.dae') self.fores1 = Model('forest\\model.dae') self.garde = Model('garden\\model.dae') self.fores.setOrientation(18.4, 0.1, .3, 0.07, 0) self.fores1.setOrientation(18.4, 0.1, 9, 0.04, -90) self.garde.setzScale(0.8) #spaceship self.ship = Model('ship\\model.dae') self.ship.setOrientation(4.5, .7, 4, 0.06, 180) self.bZ = self.ship.getZ() + 0.05 self.startbZ = self.ship.getZ() # set up keyboard and timer callback methods self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) self.callback(viz.COLLIDE_BEGIN_EVENT, self.onCollideBegin) #avatar's postion and rotation angle self.x = 4.5 self.y = 0.85 self.z = 2 self.theta = 0 # The 2D array below stores the representation of a maze. # Array entries containing a 2 represent 1 x 2 x 1 wall blocks. # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks. self.maze = [] self.maze = [[ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 ]] + self.maze # row 17 self.maze = [[ 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 17 self.maze = [[ 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 16 self.maze = [[ 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 15 self.maze = [[ 11, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 14 self.maze = [[ 11, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 4, 1, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 13 self.maze = [[ 11, 0, 0, 0, 8, 0, 0, 0, 0, 0, 4, 4, 4, 7, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 12 self.maze = [[ 11, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 4, 1, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 11 self.maze = [[ 11, 0, 0, 0, 10, 0, 0, 0, 0, 0, 4, 4, 4, 10, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 10 self.maze = [[ 11, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 4, 1, 4, 4, 4, 4, 4, 12 ]] + self.maze # row 9 self.maze = [[ 13, 3, 3, 3, 1, 3, 3, 3, 3, 3, 6, 6, 6, 1, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 8 self.maze = [[ 13, 3, 3, 3, 1, 3, 3, 3, 3, 3, 6, 6, 6, 1, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 7 self.maze = [[ 13, 3, 3, 3, 1, 3, 3, 3, 3, 3, 6, 6, 6, 1, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 6 self.maze = [[ 13, 3, 3, 3, 2, 3, 3, 3, 3, 3, 6, 6, 6, 9, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 5 self.maze = [[ 13, 3, 3, 3, 1, 3, 3, 3, 3, 3, 6, 6, 6, 1, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 4 self.maze = [[ 13, 3, 3, 3, 10, 1, 1, 1, 1, 1, 1, 1, 1, 10, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 3 self.maze = [[ 13, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 2 self.maze = [[ 13, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 1 self.maze = [[ 13, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 14 ]] + self.maze # row 0 # Code to create blocks forming the maze goes here for r in range(0, len(self.maze)): for c in range(0, len(self.maze[0])): self.cVal = c self.rVal = r #Desert floor if (self.maze[r][c] == 0): box = vizshape.addCube(size=1, color=[.92, .90, .68]) mat = viz.Matrix() mat.postScale(1, .1, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) elif (self.maze[r][c] == 11): box = vizshape.addCube(size=1, color=[.92, .90, .68]) mat = viz.Matrix() mat.postScale(1, 10, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) #Snow tower elif (self.maze[r][c] == 2): self.tower1 = vizshape.addCube(size=1, color=[1, .98, .98]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) self.tower1.setMatrix(mat) y = 0.4 self.cyl1 = vizshape.addCylinder(height=15.2, radius=0.375, color=[1, 1, 1], alpha=0) for i in range(19): water = vizshape.addCylinder(height=0.2, radius=0.375, slices=20, stacks=20, color=[0.13, .53, .85]) mat = viz.Matrix() mat.postTrans(0, y, 0) water.setMatrix(mat) y += 0.2 snow = vizshape.addCube(size=0.6, color=[0.76, .87, 1]) mat = viz.Matrix() mat.postTrans(0, y, 0) snow.setMatrix(mat) y += 0.2 snow.setParent(self.cyl1) water.setParent(self.cyl1) self.cyl1.setParent(self.tower1) self.cyl1.collideMesh() self.cyl1.enable(viz.COLLIDE_NOTIFY) self.barricade11 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade11.setParent(self.tower1) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, -0.48) self.barricade11.setMatrix(mat) self.barricade11.collideMesh() self.barricade11.enable(viz.COLLIDE_NOTIFY) self.barricade12 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade12.setParent(self.tower1) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, 0.48) self.barricade12.setMatrix(mat) self.barricade12.collideMesh() self.barricade12.enable(viz.COLLIDE_NOTIFY) self.barricade13 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade13.setParent(self.tower1) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(0.48, 0.7, 0) self.barricade13.setMatrix(mat) self.barricade13.collideMesh() self.barricade13.enable(viz.COLLIDE_NOTIFY) self.barricade14 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade14.setParent(self.tower1) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(-0.48, 0.7, 0) self.barricade14.setMatrix(mat) self.barricade14.collideMesh() self.barricade14.enable(viz.COLLIDE_NOTIFY) #City tower elif (self.maze[r][c] == 7): self.tower3 = vizshape.addCube(size=1, color=[.43, .49, .50]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) self.tower3.setMatrix(mat) y = 0.4 self.cyl3 = vizshape.addCylinder(height=15.2, radius=0.375, color=[1, 1, 1], alpha=0) for i in range(19): sand = vizshape.addCylinder(height=0.2, radius=0.375, slices=20, stacks=20, color=[0.31, 0.31, 0.31]) mat = viz.Matrix() mat.postTrans(0, y, 0) sand.setMatrix(mat) y += 0.2 pyra = vizshape.addCube(size=0.6, color=[0.88, 0.88, 0.88]) mat = viz.Matrix() mat.postTrans(0, y, 0) pyra.setMatrix(mat) y += 0.2 sand.setParent(self.cyl3) pyra.setParent(self.cyl3) self.cyl3.setParent(self.tower3) self.cyl3.collideMesh() self.cyl3.enable(viz.COLLIDE_NOTIFY) self.barricade21 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade21.setParent(self.tower3) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, -0.48) self.barricade21.setMatrix(mat) self.barricade21.collideMesh() self.barricade21.enable(viz.COLLIDE_NOTIFY) self.barricade22 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade22.setParent(self.tower3) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, 0.48) self.barricade22.setMatrix(mat) self.barricade22.collideMesh() self.barricade22.enable(viz.COLLIDE_NOTIFY) self.barricade23 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade23.setParent(self.tower3) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(0.48, 0.7, 0) self.barricade23.setMatrix(mat) self.barricade23.collideMesh() self.barricade23.enable(viz.COLLIDE_NOTIFY) self.barricade24 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade24.setParent(self.tower3) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(-0.48, 0.7, 0) self.barricade24.setMatrix(mat) self.barricade24.collideMesh() self.barricade24.enable(viz.COLLIDE_NOTIFY) #Desert tower elif (self.maze[r][c] == 8): self.tower2 = vizshape.addCube(size=1, color=[.92, .90, .68]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) self.tower2.setMatrix(mat) y = 0.4 self.cyl2 = vizshape.addCylinder(height=15.2, radius=0.375, color=[1, 1, 1], alpha=0) for i in range(19): street = vizshape.addCylinder(height=0.2, radius=0.375, slices=20, stacks=20, color=[0.74, 0.49, 0.24]) mat = viz.Matrix() mat.postTrans(0, y, 0) street.setMatrix(mat) y += 0.2 pole = vizshape.addCube(size=0.6, color=[0.86, 0.72, 0.58]) mat = viz.Matrix() mat.postTrans(0, y, 0) pole.setMatrix(mat) y += 0.2 street.setParent(self.cyl2) pole.setParent(self.cyl2) self.cyl2.setParent(self.tower2) self.cyl2.collideMesh() self.cyl2.enable(viz.COLLIDE_NOTIFY) self.barricade31 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade31.setParent(self.tower2) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, -0.48) self.barricade31.setMatrix(mat) self.barricade31.collideMesh() self.barricade31.enable(viz.COLLIDE_NOTIFY) self.barricade32 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade32.setParent(self.tower2) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, 0.48) self.barricade32.setMatrix(mat) self.barricade32.collideMesh() self.barricade32.enable(viz.COLLIDE_NOTIFY) self.barricade33 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade33.setParent(self.tower2) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(0.48, 0.7, 0) self.barricade33.setMatrix(mat) self.barricade33.collideMesh() self.barricade33.enable(viz.COLLIDE_NOTIFY) self.barricade34 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade34.setParent(self.tower2) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(-0.48, 0.7, 0) self.barricade34.setMatrix(mat) self.barricade34.collideMesh() self.barricade34.enable(viz.COLLIDE_NOTIFY) #Forrest tower elif (self.maze[r][c] == 9): self.tower4 = vizshape.addCube(size=1, color=[.27, .40, .20]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) self.tower4.setMatrix(mat) y = 0.4 self.cyl4 = vizshape.addCylinder(height=15.2, radius=0.375, color=[1, 1, 1], alpha=0) for i in range(19): grass = vizshape.addCylinder(height=0.2, radius=0.375, slices=20, stacks=20, color=[0.88, 1, 0.18]) mat = viz.Matrix() mat.postTrans(0, y, 0) grass.setMatrix(mat) y += 0.2 leaf = vizshape.addCube(size=0.6, color=[0.00, 0.46, 0.00]) mat = viz.Matrix() mat.postTrans(0, y, 0) leaf.setMatrix(mat) y += 0.2 grass.setParent(self.cyl4) leaf.setParent(self.cyl4) self.cyl4.setParent(self.tower4) self.cyl4.collideMesh() self.cyl4.enable(viz.COLLIDE_NOTIFY) self.barricade41 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade41.setParent(self.tower4) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, -0.48) self.barricade41.setMatrix(mat) self.barricade41.collideMesh() self.barricade41.enable(viz.COLLIDE_NOTIFY) self.barricade42 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade42.setParent(self.tower4) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.postTrans(0, 0.7, 0.48) self.barricade42.setMatrix(mat) self.barricade42.collideMesh() self.barricade42.enable(viz.COLLIDE_NOTIFY) self.barricade43 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade43.setParent(self.tower4) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(0.48, 0.7, 0) self.barricade43.setMatrix(mat) self.barricade43.collideMesh() self.barricade43.enable(viz.COLLIDE_NOTIFY) self.barricade44 = vizshape.addCube( size=0.2, color=[0.93, 0.82, 0.008]) self.barricade44.setParent(self.tower4) mat = viz.Matrix() mat.postScale(1, 1, 0.4) mat.setAxisAngle(0, 1, 0, 90) mat.postTrans(-0.48, 0.7, 0) self.barricade44.setMatrix(mat) self.barricade44.collideMesh() self.barricade44.enable(viz.COLLIDE_NOTIFY) #Pink track elif (self.maze[r][c] == 1): box = vizshape.addCube(size=1, color=[0.85, 0.44, .57]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) box.setMatrix(mat) #pink track with mesh elif (self.maze[r][c] == 10): box = vizshape.addCube(size=1, color=[0.85, 0.44, .57]) mat = viz.Matrix() mat.postScale(1, 0.5, 1) mat.postTrans(c + .5, 0.25, r + .5) box.setMatrix(mat) box.collideMesh() box.enable(viz.COLLIDE_NOTIFY) #Snow floor elif (self.maze[r][c] == 3): box = vizshape.addCube(size=1, color=[1, .98, .98]) mat = viz.Matrix() mat.postScale(1, .1, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) elif (self.maze[r][c] == 13): box = vizshape.addCube(size=1, color=[1, .98, .98]) mat = viz.Matrix() mat.postScale(1, 10, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) #City floor elif (self.maze[r][c] == 4): box = vizshape.addCube(size=1, color=[.43, .49, .50]) mat = viz.Matrix() mat.postScale(1, .1, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) elif (self.maze[r][c] == 12): box = vizshape.addCube(size=1, color=[.43, .49, .50]) mat = viz.Matrix() mat.postScale(1, 10, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) #Outside Forrest floor elif (self.maze[r][c] == 5): box = vizshape.addCube(size=1, color=[.27, .40, .20]) mat = viz.Matrix() mat.postScale(1, .1, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) elif (self.maze[r][c] == 14): box = vizshape.addCube(size=1, color=[.27, .40, .20]) mat = viz.Matrix() mat.postScale(1, 10, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) #Inside Forrest floor elif (self.maze[r][c] == 6): box = vizshape.addCube(size=1, color=[.325, .478, .239]) mat = viz.Matrix() mat.postScale(1, .1, 1) mat.postTrans(c + .5, 0.05, r + .5) box.setMatrix(mat) self.mode = "thirdperson"
group.disable(viz.LIGHTING) return group # Create walls of cave cave_walls = addCaveWall(cave) cave_walls.setParent(cave_origin) # Attach avatar to cave origin #avatar.setParent(cave_origin) # Add environment viz.add('piazza.osgb') cube = vizshape.addCube(size=2) cube.setPosition([0,1,3]) cube.setScale([0.5,0.5,0.5]) cubePosition = cube.getPosition() bottomLeft = [cubePosition[0] - 1, cubePosition[2] - 1] bottomRight = [cubePosition[0] + 1, cubePosition[2] - 1] topLeft = [cubePosition[0] - 1, cubePosition[2] + 1] topRight = [cubePosition[0] + 1, cubePosition[2] + 1] def changeCube(): hatPos = hatRigid.vizNode.getPosition() if(hatPos[0] >= bottomLeft[0] and hatPos[0] <= bottomRight[0]): if(hatPos[2] >= bottomLeft[1] and hatPos[2] <= topRight[1]):
def __init__(self): # base class constructor viz.EventClass.__init__(self) # set up keyboard and timer callback methods self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) self.listAlien = [] self.points = 0 # avatar's x,z location in maze and its rotation angle self.theta = 0 self.x = 2 self.z = 2 self.y = 1 self.monX = 2 self.monY = 1 self.monZ = 27 self.first = False self.bird = True self.birdX = 20 self.birdY = 15 self.birdZ = 5 self.EndGame = False # The 2D array below stores the representation of a maze. # Array entries containing a 2 represent 1 x 2 x 1 wall blocks. # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks. self.maze = [] #bottom left self.maze = [[ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 1, 1, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2, 0, 0, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0, 2, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2, 0, 4, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1, 1, 1, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2, 0, 2, 0, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 0, 4, 4, 1, 1, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0, 2, 4, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 1, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 0, 1, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 4 ]] + self.maze ################################################################################## self.maze = [[ 4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 0, 1, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 1, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0, 2, 4, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 0, 4, 4, 1, 1, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2, 0, 2, 0, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1, 1, 1, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2, 0, 4, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0, 2, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2, 0, 0, 4, 0, 2, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 1, 1, 4 ]] + self.maze self.maze = [[ 4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4 ]] + self.maze self.maze = [[ 4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4 ]] + self.maze self.maze = [[ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]] + self.maze view = viz.MainView mat = viz.Matrix() mat.postAxisAngle(0, 1, 0, 270) mat.postAxisAngle(0, 0, 1, 40) mat.postTrans(self.birdX, self.birdY, self.birdZ) view.setMatrix(mat) self.blocks = [] # Code to create blocks forming the maze goes here for row in range(0, len(self.maze)): for i in range(0, len(self.maze[row])): #* self.maze[i] if (self.maze[row][i] == 4): block = vizshape.addCube(size=1.0, color=viz.RED) elif (self.maze[row][i] == 1): block = vizshape.addCube(size=1.0, color=viz.BLUE) else: block = vizshape.addCube(size=1.0, color=viz.BLACK) m = viz.Matrix() xx = 1 yy = .5 zz = 1 if (row != 0): xx = xx + (row * 1) if (i != 0): zz = zz + (i * 1) m.postTrans(xx, yy, zz) if (self.maze[row][i] == 4): m.postScale(1, 4.0, 1) elif (self.maze[row][i] == 1): m.postScale(1, 1.5, 1) else: m.postScale(1, 1, 1) self.blocks = [[xx, zz]] + self.blocks block.setMatrix(m) for row in range(0, len(self.maze)): for i in range(0, len(self.maze[row])): if (self.maze[row][i] == 2): #self.sphere = vizshape.addSphere(.125,10,10) self.sphere = Sphere() m = viz.Matrix() xx = 1 yy = 1.5 zz = 1 if (row != 0): xx = xx + (row * 1) if (i != 0): zz = zz + (i * 1) m.postTrans(xx, yy, zz) self.sphere.setXZ(xx, zz) self.listAlien.append(self.sphere) self.sphere.vertices.setMatrix(m) self.avatar = viz.add('vcc_female.cfg') m = viz.Matrix() m.postTrans(self.x, self.y, self.z) m.postAxisAngle(0, 1, 0, self.theta) self.avatar.setMatrix(m) self.monster = viz.add('vcc_female.cfg') m = viz.Matrix() m.postTrans(self.monX, self.monY, self.monZ) m.postAxisAngle(0, 1, 0, self.theta) self.monster.setMatrix(m)
def __init__(self, participant): self.visual_maze_instruktionen = { 'baseline_start': 'Zu Beginn wird eine Zusatzmessung aufgenommen.\n' 'Es geht gleich automatisch weiter...', 'baseline_standing': 'Halten Sie Ihre Augen offen und\n' 'entspannen sich.\n' 'Mit einem Klick,\n' 'beginnt die Messung', 'baseline_thrusting': 'Halten Sie Ihre Augen offen und\n' 'tasten wiederholt nach vorne.\n' 'Mit einem Klick,\n' 'beginnt die Messung.', 'baseline_end': 'Bitte beim Versuchsleiter melden.' } # call constructor of superclass super(VisualMaze, self).__init__(participant) #ground = viz.add('tut_ground.wrl') # Add ground # create scene of the experiment self.subject_id = participant.id self.scene = VisualMazeScene(participant.maze_config, self.subject) self.maze = None self.light = vizfx.addDirectionalLight(euler=(0, 90, 0), color=viz.WHITE) self.hand_tracker_id = None self.arm_tracker_id = None self.torso_tracker_id = None # permuted list of all 4 trial mazes L Z U S, with 24 subjects 1 permutation cycle is complete self.trial_list_all = [['Z', 'L', 'U', 'S'], ['L', 'Z', 'U', 'S'], ['U', 'L', 'Z', 'S'], ['L', 'U', 'Z', 'S'], ['Z', 'U', 'L', 'S'], ['U', 'Z', 'L', 'S'], ['U', 'Z', 'S', 'L'], ['Z', 'U', 'S', 'L'], ['S', 'U', 'Z', 'L'], ['U', 'S', 'Z', 'L'], ['Z', 'S', 'U', 'L'], ['S', 'Z', 'U', 'L'], ['S', 'L', 'U', 'Z'], ['L', 'S', 'U', 'Z'], ['U', 'S', 'L', 'Z'], ['S', 'U', 'L', 'Z'], ['L', 'U', 'S', 'Z'], ['U', 'L', 'S', 'Z'], ['Z', 'L', 'S', 'U'], ['L', 'Z', 'S', 'U'], ['S', 'Z', 'L', 'U'], ['Z', 'S', 'L', 'U'], ['L', 'S', 'Z', 'U'], ['S', 'L', 'Z', 'U']] # permuted list of all 3 objects to test in rvd task (G = Global Landmark, L = Local, S = Start) with 24 subjects 4 permutation cycles are complete self.rvd_list_all = [['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G'], ['G', 'L', 'S'], ['L', 'G', 'S'], ['S', 'G', 'L'], ['G', 'S', 'L'], ['L', 'S', 'G'], ['S', 'L', 'G']] # # keys for video recording # vidname = str(participant.id) + '_' + str(participant.control_style) + '.avi' # viz.setOption('viz.AVIRecorder.fps','25') # viz.setOption('viz.AVIRecorder.maxWidth','1280') # viz.setOption('viz.AVIRecorder.maxHeight', '720') # vizact.onkeydown('b', viz.window.startRecording, vidname) # vizact.onkeydown('e', viz.window.stopRecording) # ---- collision event params ---- # # objects handling current state of visual maze experiment # wall enter and exit collision event callbacks self.hand_in_wall = False self.head_in_wall = False # placeholders for visual feedback functions self.feedback_hand = None self.feedback_start_time = 0 self.feedback_duration = 0 self.new_touch_allowed = True self.feedback = vizact.sequence(vizact.waittime(0.5), vizact.fadeTo( 0, time=.2)) # event is 700 ms self.help_sphere = vizshape.addSphere(.1) self.help_sphere.color(viz.GREEN) self.help_sphere.visible(viz.OFF) # ---- Bookkeeping variables for behavioral data collection ---- # self.current_maze = None self.current_trial_run = None # ---- Reward tracking variables ---- # self.hand_hits = 0 self.head_hits = 0 self.local_landmark_hits = 0 self.duration = 0 self.start_return = 0 # pointing task self.pointing_task_on = False # RVD task objects self.rvd_task_on = False self.in_rvd_table = False self.rvd_table = vizshape.addCube(1) self.rvd_table.alpha(0.3) # make surface barely visible self.rvd_table.visible(viz.OFF) self.start_sign = viz.add('resources/start.dae') self.start_sign.setScale(.02, .02, .02) self.start_sign.visible(viz.OFF)
def __init__(self, enable=False, hotkey=viz.KEY_F12): self._enable = enable self._hotkey = hotkey self._next_screenshot = 1 self._points = [] # Visualization parameters self.GRID_COLOR = [1, 1, 1] self.DEBUG_ALPHA = 0.6 self.LABEL_SCALE = 0.05 self.VALUE_SCALE = 0.015 self.MARKER_SIZE = 0.05 self.HUD_POS = [0.4, 0.3, 1] # Works for Vive / Vive Pro # SteamVR devices self.hmd = {} self.controllers = {} self.trackers = {} self.lighthouses = {} self.nodes = {} # Set up scene objects self._root = viz.addGroup() self._obj = [] self._obj.append(vizshape.addGrid((100, 100), color=self.GRID_COLOR, pos=[0.0, 0.001, 0.0], parent=self._root)) self._obj.append(vizshape.addAxes(pos=(0,0,0), scale=(0.5, 0.5, 0.5), parent=self._root)) # Set up possible marker objects self._markers = {'sphere_red': vizshape.addSphere(radius=self.MARKER_SIZE / 2, color=viz.RED, parent=self._root), 'sphere_green': vizshape.addSphere(radius=self.MARKER_SIZE / 2, color=viz.GREEN, parent=self._root), 'sphere_blue': vizshape.addSphere(radius=self.MARKER_SIZE / 2, color=viz.BLUE, parent=self._root), 'sphere_yellow': vizshape.addSphere(radius=self.MARKER_SIZE / 2, color=viz.YELLOW, parent=self._root), 'cube_red': vizshape.addCube(size=self.MARKER_SIZE, color=viz.RED, parent=self._root), 'cube_green': vizshape.addCube(size=self.MARKER_SIZE, color=viz.GREEN, parent=self._root), 'cube_blue': vizshape.addCube(size=self.MARKER_SIZE, color=viz.BLUE, parent=self._root), 'cube_yellow': vizshape.addCube(size=self.MARKER_SIZE, color=viz.YELLOW, parent=self._root) } for marker in self._markers.keys(): self._markers[marker].visible(False) # Note: X/Z axis rays moved up (y) by 1 mm to avoid z-fighting with the ground plane self._obj.append(addRayPrimitive(origin=[0,0.001,0], direction=[1, 0.001, 0], color=viz.RED, parent=self._root)) # x self._obj.append(addRayPrimitive(origin=[0,0.001,0], direction=[0, 0.001, 1], color=viz.BLUE, parent=self._root)) # z self._obj.append(addRayPrimitive(origin=[0,0,0], direction=[0, 1, 0], color=viz.GREEN, parent=self._root)) # y # Set up UI txt = 'Hotkeys:\nS - Save collected points data\nC - Clear point data\nL - Toggle Lighthouse rays\nX - Export debug scene\n\n' txt += 'Controller Buttons:\nTrigger - place point axes\nA - Save point data\nB - Take screenshot' self._ui = vizinfo.InfoPanel(txt, icon=True, align=viz.ALIGN_RIGHT_TOP, title='SteamVR Debug Tool') self._ui.renderToEye(viz.RIGHT_EYE) self._ui.addSeparator() self._obj.append(self._ui) # Register key callbacks self._callbacks = [] self._callbacks.append(vizact.onkeydown('s', self.savePoints)) self._callbacks.append(vizact.onkeydown('c', self.clearPoints)) self._callbacks.append(vizact.onkeydown('l', self.showLighthouseRays, viz.TOGGLE)) self._callbacks.append(vizact.onkeydown('x', self.saveDebugScene)) self.findDevices() self.enable(self._enable) self._hotkey_callback = vizact.onkeydown(self._hotkey, self.enable, viz.TOGGLE) self._ui_callback = vizact.onupdate(viz.PRIORITY_LINKS+1, self._updateUI) print('* SteamVR Debug Overlay initialized.')
def addDebugModel(self, node, label, model=None, color=None, size=None): """ Add a debug model, axes and label for any node3d object. Debug nodes are shown in UI and displayed/hidden together with the rest of the debug scene. Args: node: any Vizard node, group, or sensor object label (str): Brief text to identify the node in UI and VR model (str): One of: - 'sphere', 'cube', 'axes': use a vizshape primitive - a valid model file name ('test.osg'): load and use model color (3-tuple): RGB color, None for random (ignored for model files) size (float): Size of primitive, or scaling factor for model files """ if label in self.nodes.keys(): raise ValueError('Label already exists - node labels must be unique!') return None if color is None: color = colorsys.hsv_to_rgb(random.uniform(0.0, 1.0), random.uniform(0.4, 1.0), random.uniform(0.5, 1.0)) # Add model and label text objects if model is not None and os.path.isfile(model): if size is None: size = 1.0 _m = viz.addChild(model, parent=node) _m.setScale([size,] * 3) else: if size is None: size = 0.05 if model is None: _m = viz.addGroup(parent=node) elif model == 'sphere': _m = vizshape.addSphere(radius=size, color=color, parent=node) elif model == 'cube': _m = vizshape.addCube(size=size, color=color, parent=node) elif model == 'axes': _m = vizshape.addAxes(length=size, color=color, parent=node) _m.disable(viz.INTERSECTION) _text = viz.addText3D(str(label), scale=(self.VALUE_SCALE,) * 3, color=color, parent=_m, pos=(size * 1.1, 0.01, 0)) _text.alignment(alignment=viz.ALIGN_LEFT_CENTER) _text.setEuler(0, 45, 0) # Add UI section for debug nodes if this is the first one if len(self.nodes) == 0: self._ui.addSeparator() self._ui.addItem(viz.addText('Other Nodes')) _ui = viz.addText('N/A') lbl = self._ui.addLabelItem(str(label), _ui) lbl.label.color(color) self._obj.extend([_m, _text]) _m.visible(self._enable) _text.visible(self._enable) self.nodes[str(label)] = {'model': _m, 'text': _text, 'ui': _ui} print('* Added extra node entry: {:s}'.format(str(label))) return _m
def makeBodyBox(self, x, y, z): box = vizshape.addCube(1) box.setPosition([x, y, z]) box.color([128, 64, 0]) return box