def createCalibrationCylinders(self): ############################################################## ############################################################## ## left eye and calib grid self.leftEyeProbeCylinder = vizshape.addCylinder(height=self.eyeProbeCylLength,radius=self.eyeProbeRadius,top=False,bottom=False,axis = vizshape.AXIS_X,color=viz.BLUE) self.leftEyeProbeCylinder.disable(viz.CULL_FACE) self.leftEyeProbeCylinder.visible( viz.OFF ) self.leftEyeCylinderBack = vizshape.addCircle(self.eyeProbeRadius,axis=vizshape.AXIS_X,color=viz.GREEN) self.leftEyeCylinderBack.disable(viz.CULL_FACE) self.leftEyeCylinderBack.setParent(self.leftEyeProbeCylinder) self.leftEyeCylinderBack.setPosition(self.eyeProbeCylLength/2,0,0) #self.leftEyeProbeCylinder) self.lGridVertBar = vizshape.addBox([self.probeBarWidthMM,self.eyeProbeRadius*2,self.probeBarWidthMM]) self.lGridVertBar.setParent(self.leftEyeCylinderBack) ############################################################## ############################################################## ## Draw right eye components self.rightEyeProbeCylinder = vizshape.addCylinder(height=self.eyeProbeCylLength,radius=self.eyeProbeRadius,top=False,bottom=False,axis = vizshape.AXIS_X,color=viz.BLUE) self.rightEyeProbeCylinder.disable(viz.CULL_FACE) self.rightEyeProbeCylinder.visible( viz.OFF ) self.rightEyeCylinderBack = vizshape.addCircle(self.eyeProbeRadius,axis=vizshape.AXIS_X,color=viz.GREEN) self.rightEyeCylinderBack.disable(viz.CULL_FACE) self.rightEyeCylinderBack.setParent(self.rightEyeProbeCylinder) self.rightEyeCylinderBack.setPosition(self.eyeProbeCylLength/2,0,0) #self.leftEyeProbeCylinder) self.rGridHorzBar = vizshape.addBox([self.probeBarWidthMM,self.probeBarWidthMM,self.eyeProbeRadius*2]) self.rGridHorzBar.setParent(self.rightEyeCylinderBack)
def doorway(height, width, radius): doorway = viz.addGroup() cylinder1 = vizshape.addCylinder(height=height + radius * 2 - 0.01, radius=radius) cylinder2 = vizshape.addCylinder(height=height + radius * 2 - 0.01, radius=radius) cylinder3 = vizshape.addCylinder(height=width, radius=radius, axis=vizshape.AXIS_X) cylinder4 = vizshape.addCylinder(height=width, radius=radius, axis=vizshape.AXIS_X) cylinder1.setParent(doorway) cylinder2.setParent(doorway) cylinder3.setParent(doorway) cylinder4.setParent(doorway) cylinder1.setPosition([-width / 2, height / 2, 0], mode=viz.REL_PARENT) cylinder2.setPosition([width / 2, height / 2, 0], mode=viz.REL_PARENT) cylinder3.setPosition([0, height, 0], mode=viz.REL_PARENT) cylinder4.setPosition([0, 0, 0], mode=viz.REL_PARENT) return doorway
def createCalibrationCylinders(self): ############################################################## ############################################################## ## left eye and calib grid self.leftEyeProbeCylinder = vizshape.addCylinder( height=self.eyeProbeCylLength, radius=self.eyeProbeRadius, top=False, bottom=False, axis=vizshape.AXIS_X, color=viz.BLUE) self.leftEyeProbeCylinder.disable(viz.CULL_FACE) self.leftEyeProbeCylinder.visible(viz.OFF) self.leftEyeCylinderBack = vizshape.addCircle(self.eyeProbeRadius, axis=vizshape.AXIS_X, color=viz.GREEN) self.leftEyeCylinderBack.disable(viz.CULL_FACE) self.leftEyeCylinderBack.setParent(self.leftEyeProbeCylinder) self.leftEyeCylinderBack.setPosition(self.eyeProbeCylLength / 2, 0, 0) #self.leftEyeProbeCylinder) self.lGridVertBar = vizshape.addBox([ self.probeBarWidthMM, self.eyeProbeRadius * 2, self.probeBarWidthMM ]) self.lGridVertBar.setParent(self.leftEyeCylinderBack) ############################################################## ############################################################## ## Draw right eye components self.rightEyeProbeCylinder = vizshape.addCylinder( height=self.eyeProbeCylLength, radius=self.eyeProbeRadius, top=False, bottom=False, axis=vizshape.AXIS_X, color=viz.BLUE) self.rightEyeProbeCylinder.disable(viz.CULL_FACE) self.rightEyeProbeCylinder.visible(viz.OFF) self.rightEyeCylinderBack = vizshape.addCircle(self.eyeProbeRadius, axis=vizshape.AXIS_X, color=viz.GREEN) self.rightEyeCylinderBack.disable(viz.CULL_FACE) self.rightEyeCylinderBack.setParent(self.rightEyeProbeCylinder) self.rightEyeCylinderBack.setPosition(self.eyeProbeCylLength / 2, 0, 0) #self.leftEyeProbeCylinder) self.rGridHorzBar = vizshape.addBox([ self.probeBarWidthMM, self.probeBarWidthMM, self.eyeProbeRadius * 2 ]) self.rGridHorzBar.setParent(self.rightEyeCylinderBack)
def makeRail(self): rail = viz.addGroup() # Cylinders to act as the wheel tracks leftCyl = vizshape.addCylinder(height=20, radius=5, axis=vizshape.AXIS_Y, slices=20, bottom=True, top=True) m = viz.Matrix() m.postTrans(-10) leftCyl.setMatrix(m) rightCyl = vizshape.addCylinder(height=20, radius=5, axis=vizshape.AXIS_Y, slices=20, bottom=True, top=True) m = viz.Matrix() m.postTrans(10) rightCyl.setMatrix(m) # Slats slat1 = vizshape.addBox(size=(40, 5, 5), right=True, left=True, top=True, bottom=True, front=True, back=True, splitFaces=False) m = viz.Matrix() m.postTrans(0, 5, 0) slat1.setMatrix(m) slat2 = vizshape.addBox(size=(40, 5, 5), right=True, left=True, top=True, bottom=True, front=True, back=True, splitFaces=False) m = viz.Matrix() m.postTrans(0, -5, 0) slat2.setMatrix(m) leftCyl.setParent(rail) rightCyl.setParent(rail) slat1.setParent(rail) slat2.setParent(rail) return rail
def __init__(self, pos_vector, fin_depth, shoulder, TTC, color_vector, radius, height): super(Cylinder,self).__init__(pos_vector.x,pos_vector.y,pos_vector.z, fin_depth, shoulder, TTC) self.radius = radius self.height = height self.cyl_Left = vizshape.addCylinder(self.height, self.radius) self.cyl_Right = vizshape.addCylinder(self.height, self.radius) self.cyl_Left.color (color_vector.x, color_vector.y, color_vector.z) self.cyl_Right.color (color_vector.x, color_vector.y, color_vector.z) self.cyl_Left.setPosition(self.position1) self.cyl_Right.setPosition(self.position2) self.disapr()
def bambooForest(self): # Add the ground plane ground = viz.addChild('ground.osgb') # Bamboo sticks bambooForest1 = [] bambooForest2 = [] # add 200 bamboo trees to each forest for i in range(0, 400, 1): bambooForest1.append(vizshape.addCylinder(random.randint(10,16),0.1)) bambooForest2.append(vizshape.addCylinder(random.randint(10,16),0.1)) bambooForest1[i].setPosition(random.randint(-16,-3),0.5,random.randint(-20,20)) bambooForest2[i].setPosition(random.randint(3,16),0.5,random.randint(-20,20)) bambooForest1[i].color(0.3,0.8,0.3) bambooForest2[i].color(0.3,0.8,0.3)
def addStreetlights(scene=viz.MainScene): global sphere, sphere2; # pic = viz.addTexture('streetlamp.jpg'); # sphere = vizshape.addQuad(size=[15, 4],scene=scene) # sphere2 = vizshape.addQuad(size=[15, 4],scene=scene) # sphere.setPosition([5, 2.5, 5]); # sphere2.setPosition([5,2.5,-5]); # pic = viz.addTexture('streetlamp.jpg') # sphere.texture(pic) # sphere.emissive(viz.WHITE) # sphere2.texture(pic) # sphere2.emissive(viz.WHITE) cylinder = vizshape.addCylinder(height=5.0,radius=11, topRadius=None, bottomRadius=None, axis=vizshape.AXIS_Y, slices=20, bottom=True,top=True, flipFaces = True) cylinder2 = vizshape.addCylinder(height=5.0,radius=11, topRadius=None, bottomRadius=None, axis=vizshape.AXIS_Y, slices=20, bottom=False,top=False, flipFaces = True) cylinder.setPosition([0, 2.5, -3]) cylinder2.setPosition([0, 2.5, 3]) pic = viz.addTexture('resources/images/streetlamp.jpg') cylinder.texture(pic) cylinder.emissive(viz.WHITE) cylinder.addAction(vizact.spin(0, 1, 0, -40)) cylinder2.texture(pic) cylinder2.emissive(viz.WHITE) cylinder2.addAction(vizact.spin(0, 1, 0, 40)) global timeToMove, origPOS, endPOS timeToMove = 2 origPOS = [ [5, 2.5, 5] , [5,2.5,-5] ] endPOS = [ [-11,2.5,5] , [-11,2.5,-5] ] leftLight = makeLight(scene) rightLight = makeLight(scene)
def __init__(self,use_keyboard = True, desktop_mode = False): """Initialization function.""" # viz.phys.enable() self.view = viz.MainView; caveapp.CaveApplication.__init__(self,desktop_mode) #call constructor of super class, you have to do this explicitly in Python self.wand = vizshape.addAxes()#load axis model to represent the wand\ self.cylinder = vizshape.addCylinder(15,0.002,axis=vizshape.AXIS_X) self.cylinder.setEuler([0,0,0]) #self.cylinder.setCenter([0,0,-1]) self.cylinder.setPosition(7.5,0.08,0) self.stuff = vizshape.addSphere(0.0001) self.cylinder.setParent(self.stuff) # temp = vizshape.addSphere(0.05) # temp.setParent(self.cylinder) # temp.setPosition(self.cylinder.getCenter()) self.wand = self.stuff # self.wand.setPosition(.5,-1,0) # self.cm = self.wand.getMatrix() # self.Room = viz.addChild('D:\Cave software\NFI Cave\Scene\ScannedRoom.3DS') # self.Room.collidePlane() # self.Room.setScale([1.25,1.25,1.25]) # self.Room.setEuler([90,0,0]) # self.Room.setPosition([-1.5,0,1.55]) self.Room = viz.addChild('scene/ScannedRoom.3DS') self.Room.collidePlane() self.Room.setScale([0.002,0.002,0.002]) self.Room.setEuler([90,0,0]) self.Room.setPosition([-1.5,0.015,1.58]) """ mylight = viz.addLight() mylight.enable() mylight.position(0, 1, 0) mylight.spread(180) mylight.intensity(2) # vizact.onkeydown('f', dance) """ viz.disable(viz.LIGHTING) self.headLight = viz.MainView.getHeadLight() #disable the headlight self.headLight.disable() #the headlight is disabled because the piazza.osgb is already shaded self.use_keyboard = use_keyboard #store if we want to use the keyboard self.time = 0.0 #note that to 0.0 is important because it is a double precision floating point number
def CreateVisualObjects(): global ball, Head, Hand, GazeLine, EyeBallLine; #creats a sphere(the ball) with radius of 5cm ball = vizshape.addSphere(radius = .05) #colors the ball red ball.color(viz.YELLOW) ball.visible(True) Origin = vizshape.addAxes() Origin.setPosition(0,0,0) #creats a sphere(the ball) with radius of 5cm #Head = vizshape.addCone( radius = 0.5, height = 0.8) Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE) #colors the ball red Head.color(viz.PURPLE) Head.visible(True) Head.setScale(.2,.2,.3) #creats a sphere(the hand) with radius of 10cm Hand = vizshape.addCylinder( height = 0.02, radius = 0.2) #colors the hand red Hand.color(viz.RED) Hand.visible(True) # Creating a Line to represent Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.GREEN) GazeLine = viz.endLayer() # Object will contain both points and lines GazeLine.visible(True) GazeLine.setScale(5,5,5) # Creating a Line to represent Eye-Ball Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.YELLOW) EyeBallLine = viz.endLayer() # Object will contain both points and lines EyeBallLine.visible(True) EyeBallLine.setScale(5,5,5)
def targetCreator(h, targetColor, rad=0.02): global Target # Target = viz.addGroup() Target = vizshape.addCylinder(height = h, radius=rad, yAlign=vizshape.ALIGN_MIN) #Change the diameter of the target Target.color(targetColor) #Generate random values for position and orientation # disk_rad=0.25; segment_no = 36 # viz.startLayer(viz.POLYGON) # viz.pointSize(1) # for i in range(segment_no): # pt_z = disk_rad * math.cos(2*math.pi*i/segment_no) # pt_x = disk_rad * math.sin(2*math.pi*i/segment_no) # viz.vertex([pt_x, 0, pt_z]) # disk = viz.endLayer() # disk.zoffset(-1) # disk.color(targetColor) return Target #, disk
def __setupWorld__(self): #Initialize cave and load the powerwall# self.cave = vizcave.Cave() #This line of code opens the file if a filename is provided and loads the corner co-ordinates from it, else uses the default co-ordinates# self.cave.load(self.caveWallFileName) if None is not self.caveWallFileName else self.cave.addWall(self.powerwall) # TODO: Pair every obstacle with an invisible "hat" object to detect when the obstacle was avoided. # Create a seperate module that does this automatically for each object added. # Like from a config file. self.crate = viz.addChild( 'crate.osgb' ) self.crate.setScale([.2,.2,.2]) self.crate.setPosition([-.45, 0, -.10]) self.cratePole = vizshape.addCylinder(height = .5, radius = 0.025) self.cratePole.setPosition( [-.45, .3, -.10] ) self.cratePole.alpha(0.5) self.avatar = viz.addAvatar('duck.cfg') self.avatar.setScale(.2, .2, .2) self.avatar.setPosition([-1, .1, -.10]) #self.floor = viz.addChild('lab.osgb') self.floor = viz.addChild('piazza.osgb')
Y = viz.addText3D('Y',pos=[0,1.1,0],color=viz.GREEN,scale=[0.3,0.3,0.3],align=viz.ALIGN_CENTER_BASE,parent=world_axes) Z = viz.addText3D('Z',pos=[0,0,1.1],color=viz.BLUE,scale=[0.3,0.3,0.3],align=viz.ALIGN_CENTER_BASE,parent=world_axes) #grids are good grid = vizshape.addGrid(color=[0.2]*3) viz.clearcolor(viz.GRAY) #Create proximity manager manager = vizproximity.Manager() manager.setDebug(viz.ON) #create our bisecting plane mid_plane= vizshape.addPlane(size=(.00001,.00001),axis=vizshape.AXIS_X, cullFace=False) start_node= vizshape.addCylinder(height1, radius=.00000000005,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) end_node= vizshape.addCylinder(height1, radius=.00000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_node1=vizshape.addCylinder(height1, radius= .000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_node2=vizshape.addCylinder(height1, radius= .000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_node3=vizshape.addCylinder(height1, radius= .000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) right_node1=vizshape.addCylinder(height1, radius=.00000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) right_node2=vizshape.addCylinder(height1, radius=.00000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) right_node3=vizshape.addCylinder(height1, radius=.00000001,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_plane1= vizshape.addPlane(size=(1*scale_x1,1*scale_x1,),axis=vizshape.AXIS_Y, cullFace=False) right_plane1= vizshape.addPlane(size=(1*scale_x1,1*scale_x1,),axis=vizshape.AXIS_Y, cullFace=False) left_plane2= vizshape.addPlane(size=(1*scale_x2,1*scale_x2,),axis=vizshape.AXIS_Y, cullFace=False)
import viztask import VectorBasics as v MAX_RAD_VAR = .1 # TODO: Some other way of specifying # movement details, so that each # school can have different movement class MovementSettings: yAxisOfRotation = [-.5,.5] speed = 10 clockwise = True # Current axis of rotation for all the fish import vizshape cyl = vizshape.addCylinder(5,.03) cyl.setPosition([-.5,0,.5]) # This function is the same as # node3d.setCenter, except it translates # the new center so that the node # appears to be in the same position as # it was with its original center. # The node's euler is preserved. # Caution: only tested for xz-plane # center changes and adjusts for the # yaw, but not any pitch or roll. # This function works regardless of node scale. # Uses transforms (matrices) def setCenterInPlace(node, centerPos): x,y,z = centerPos
def makeBasicVisNode(self): # Returns a pointer to a vizshape object # This is added to the room.objects parent new_vis_node = [] if self.shape == 'box': # print 'Making box visNode' if type(self.size) == float or len(self.size) != 3: print '**********Invalid size for box' print 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000, 250) lwh = [self.size[1], self.size[2], self.size[0]] new_vis_node = vizshape.addBox(lwh, alpha=self.alpha, color=viz.RED) elif self.shape == 'sphere': if type(self.size) == list and len(self.size) == 1: self.size = float(self.size[0]) if type(self.size) != float: # accept a float print '**********Invalid size for sphere' print 'Check rigidBodySizesString. Expected 1 val for sphere: radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000, 250) # print 'Making sphere visNode' new_vis_node = vizshape.addSphere(radius=float(self.size), alpha=self.alpha, color=viz.BLUE, slices=10, stacks=10) elif 'cylinder' in self.shape: if type(self.size) == float or len(self.size) != 2: print '**********Invalid size for cylinder' print 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000, 250) # print 'Making cylinder visNode' if self.shape[-2:] == '_X' or self.shape[-2:] == '_Y' or self.shape[-2:] == '_Z': axis_string = 'vizshape.AXIS' + self.shape[-2:] print axis_string + axis_string + axis_string + axis_string eval_string = 'vizshape.addCylinder(height=self.size[0],radius=self.size[1], ' \ 'alpha = self.alpha,color=viz.BLUE,axis=' + axis_string + ')' new_vis_node = eval(eval_string) else: new_vis_node = vizshape.addCylinder(height=self.size[0], radius=self.size[1], alpha=self.alpha, color=viz.BLUE, axis=vizshape.AXIS_Y) if new_vis_node: self.vis_node = new_vis_node else: print 'vizEnv.room.makeBasicVisNode(): Unable to create visNode' import winsound winsound.Beep(1000, 250) # if(self.parentRoom): new_vis_node.setParent(self.parent_room.objects)
def __init__(self): # must call constructor of EventClass first!! viz.EventClass.__init__(self) #Luxo instance variables that describe configuration self.x = 0 # location of base in world self.y = 0 self.z = 0 self.a = 30 # rotation angle of lower arm self.b = 20 # spin angle of lower arm self.c = -30 # rotation angle of upper arm self.d = 0 # rotation angle of shade self.e = 0 # spin angle of shade self.animationCounter = 0 self.base = vizshape.addCylinder(height = 5, radius = 20, axis = vizshape.AXIS_Y, slices = 20, bottom = True, top = True) m = viz.Matrix() m.postTrans(0,2.5,0) self.base.setMatrix(m) self.baseGroup = viz.addGroup() self.base.setParent(self.baseGroup) self.lowerArmGroup = viz.addGroup() self.lowerSphere = vizshape.addSphere(radius = 5, slices = 20, stacks = 20) self.lowerCyl = vizshape.addCylinder(height = 40, radius = 2.5, axis = vizshape.AXIS_Y, slices = 20, bottom = True, top = True) m = viz.Matrix() m.postTrans(0, 20, 0) self.lowerCyl.setMatrix(m) self.lowerSphere.setParent(self.lowerArmGroup) self.lowerCyl.setParent(self.lowerArmGroup) self.lowerArmGroup.setParent(self.baseGroup) self.upperArmGroup = viz.addGroup() self.upperSphere = vizshape.addSphere(radius = 5, slices = 20, stacks = 20) self.upperCyl = vizshape.addCylinder(height = 40, radius = 2.5, axis = vizshape.AXIS_Y, slices = 20, bottom = True, top = True) m = viz.Matrix() m.postTrans(0, 20, 0) self.upperCyl.setMatrix(m) self.upperSphere.setParent(self.upperArmGroup) self.upperCyl.setParent(self.upperArmGroup) self.upperArmGroup.setParent(self.lowerArmGroup) self.shadeGroup = viz.addGroup() self.shadeSphere = vizshape.addSphere(radius = 5, slices = 20, stacks = 20) self.shade = vizshape.addCone(radius = 20, height = 30) m = viz.Matrix() m.postTrans(0, -15, 0) m.postAxisAngle(0, 0, 1, 180) self.shade.setMatrix(m) self.shadeSphere.setParent(self.shadeGroup) self.shade.setParent(self.shadeGroup) self.shadeGroup.setParent(self.upperArmGroup) # set transformation group matrices of nodes to give # desired configuration self.transform() # setup callback methods self.callback(viz.KEYDOWN_EVENT,self.onKeyDown) self.callback(viz.TIMER_EVENT,self.onTimer)
import vizshape grid = vizshape.addGrid(color=[0.2]*3) viz.clearcolor(viz.GRAY) #align the right side of the box with X = 0 #bottom of the box with Y = 0 #front of the box with Z = 0 cylinder = vizshape.addCylinder(height=1.0, radius=0.5, topRadius=None,bottomRadius=None, axis=vizshape.AXIS_Y, slices=10, bottom=True,top=True) cylinder.setposition(0,0,1) import vizcam vizcam.PivotNavigate(center=[0,2,0],distance=10) viz.go()
serverName = 'srushton-PC' labNetwork = viz.addNetwork(serverName) # Setup VRPN vrpn = viz.add('vrpn7.dle') head = vrpn.addTracker('Tracker0@localhost', 9) body = vrpn.addTracker('Tracker0@localhost', 10) tracker = vrpn.addTracker('Tracker0@localhost', 4) head.swapPos([1, 2, -3]) head.swapQuat([-1, -2, 3, 4]) body.swapPos([1, 2, -3]) body.swapQuat([-1, -2, 3, 4]) ground = viz.add('ground.osgb') target_1 = vizshape.addCylinder(height=3, radius=0.02) target_1.color(viz.RED) target_1.setPosition([0, 0, 0]) target_2 = vizshape.addCylinder(height=3, radius=0.02) target_2.color(viz.RED) target_2.setPosition([0, 0, 7]) head_rep = vizshape.addBox([0.2, 0.2, 0.2]) head_rep.color(viz.PURPLE) body_rep = vizshape.addBox([0.2, 0.2, 0.2]) body_rep.color(viz.YELLOW_ORANGE) headlink = viz.link(head, head_rep) bodylink = viz.link(body, body_rep) manager = vizproximity.Manager() target = vizproximity.Target(headlink)
trackerLocationB = '[email protected]' # Now add all trackers and link a shape to it for i in range(0,24): t = vrpn.addTracker(trackerLocationA, i) s = vizshape.addSphere(radius = 0.1) l = viz.link(t,s) trackers.append(t) links.append(l) shapes.append(s) if i == HEAD: s.color(viz.GREEN) elif i == TORSO: s.color(viz.RED) # Add an arrow pointing from the torso in the direction the body is facing arrow = vizshape.addCylinder(1,0.05,topRadius=0) arrow.parent(s) arrow.setEuler([0,-90,0]) arrow.setPosition([0,0,-0.5]) arrow.color(viz.RED) elif i in [LEFTSHOULDER,RIGHTSHOULDER,LEFTHIP,RIGHTHIP]: s.color(viz.BLUE) # Trackers for specified bodyparts RF = vrpn.addTracker(trackerLocationA, RIGHTFOOT) LF = vrpn.addTracker(trackerLocationA, LEFTFOOT) RK = vrpn.addTracker(trackerLocationA, RIGHTKNEE) LK = vrpn.addTracker(trackerLocationA, LEFTKNEE) RH = vrpn.addTracker(trackerLocationA, RIGHTHIP) LH = vrpn.addTracker(trackerLocationA, LEFTHIP)
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!'
# # Apply user profile eye height to view profile = hmd.getProfile() if profile: height = profile.eyeHeight - 0.1 else: height = float(viz.input('Height?')) # Set up the instruction beforeExp = """That's the practice. Ready for the experiment? """ ReqResp = 'Left or Right?' # GotResp = 'Next Trial' # Set up the target Target = vizshape.addCylinder(height=3, radius=0.02, yAlign=vizshape.ALIGN_MIN) Target.color(viz.ORANGE) Target.visible(viz.OFF) # Set up view movement view = viz.MainView sensor = hmd.getSensor() link = viz.link(hmd.getSensor(), view, mask=viz.LINK_ORI) vizact.onkeydown('r', sensor.reset) view.eyeheight(height) MODE = viz.SPEED ROTATE_MODE = viz.NO_ROTATE # Set up the cross at the centre of the visual field def cross(eyeHeight):
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"
def __init__(self): # must call constructor of EventClass first!! viz.EventClass.__init__(self) #Luxo instance variables that describe configuration self.x = 0 # location of base in world self.y = 0 self.z = 0 self.a = 30 # rotation angle of lower arm self.b = 20 # spin angle of lower arm self.c = -30 # rotation angle of upper arm self.d = 0 # rotation angle of shade self.e = 0 # spin angle of shade self.base = vizshape.addCylinder(5, 20) mat = viz.Matrix() mat.postTrans(0, 2.5, 0) self.base.setMatrix(mat) #World Group self.group = viz.addGroup() self.base.setParent(self.group) # Create Lower Arm and its socket self.lowerArmBall = vizshape.addSphere(3) self.lowerArm = vizshape.addCylinder(20, 2) # Lower Arm Standard Position mat = viz.Matrix() mat.postTrans(0, 10, 0) self.lowerArm.setMatrix(mat) # Create Upper Arm and Socket self.upperArmBall = vizshape.addSphere(3) self.upperArm = vizshape.addCylinder(20, 2) # Upper Arm Standard Position mat = viz.Matrix() mat.postTrans(0, 10, 0) self.upperArm.setMatrix(mat) # Create Shade and socket self.shadeBall = vizshape.addSphere(3) self.shade = vizshape.addCone(15, 20) # Shade Standard Position mat = viz.Matrix() mat.postAxisAngle(0, 0, 1, 90) mat.postTrans(10, 0, 0) self.shade.setMatrix(mat) # Lower Arm Group self.lowerArmGroup = viz.addGroup() self.lowerArmGroup.setParent(self.group) self.lowerArmBall.setParent(self.lowerArmGroup) self.lowerArm.setParent(self.lowerArmGroup) # Upper Arm Group self.upperArmGroup = viz.addGroup() self.upperArmGroup.setParent(self.lowerArmGroup) self.upperArmBall.setParent(self.upperArmGroup) self.upperArm.setParent(self.upperArmGroup) # Shade Group self.shadeGroup = viz.addGroup() self.shadeGroup.setParent(self.upperArmGroup) self.shadeBall.setParent(self.shadeGroup) self.shade.setParent(self.shadeGroup) # set transformation group matrices of nodes to give # desired configuration self.transform() # setup callback methods self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) self.callback(viz.TIMER_EVENT, self.onTimer)
def _createVizNode(self, shape, size): if (shape == 'box'): print 'Making box vizNode' if (type(size) == float or len(size) != 3): print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' print 'Got: ' + str(size) import winsound winsound.Beep(1000, 250) self.vizNode = vizshape.addBox(size, alpha=0.7, color=viz.RED) return elif (shape == 'sphere'): if (type(size) != float): # accept a float print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 1 val for sphere: radius' print 'Got: ' + str(size) import winsound winsound.Beep(1000, 250) print 'Making sphere vizNode' self.vizNode = vizshape.addSphere(radius=float(size), alpha=0.7, color=viz.BLUE) elif (shape == 'cylinder'): if (type(size) == float or len(size) != 2): print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' print 'Got: ' + str(size) import winsound winsound.Beep(1000, 250) print 'Making cylinder vizNode' # height, rad, self.vizNode = vizshape.addCylinder(height=size[0], radius=size[1], alpha=0.3, color=viz.YELLOW, axis=vizshape.AXIS_X) #self.vizNode.setAxisAngle(1,0,0,90) if (self.vizNode): self.vizNode.disable(viz.CULL_FACE) if (self.isVisible): self.vizNode.visible(viz.ON) #Make the object visible. else: self.vizNode.visible(viz.OFF) #Make the object invisible. print self.fileName + ' vizNode created, but not set as visible' self.physNode = self.vizNode.collideMesh() else: print 'Problem creating viz node' import winsound winsound.Beep(1000, 250)
def TargetCreator(high, rad): global Target Target = vizshape.addCylinder( height=high, radius=rad, yAlign=vizshape.ALIGN_MIN) #Change the diameter of the target return Target
def _createVizNode(self,shape,size): if(shape == 'box' ): print 'Making box vizNode' if( type(size) == float or len(size) !=3): print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' print 'Got: ' + str(size) import winsound winsound.Beep(1000,250) self.vizNode = vizshape.addBox(size,alpha = 0.7,color=viz.RED) return elif(shape == 'sphere'): if( type(size) != float): # accept a float print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 1 val for sphere: radius' print 'Got: ' + str(size) import winsound winsound.Beep(1000,250) print 'Making sphere vizNode' self.vizNode = vizshape.addSphere(radius = float(size), alpha = 0.7,color=viz.BLUE) elif(shape == 'cylinder'): if( type(size) == float or len(size) !=2): print '**********Invalid size for ' + self.fileName print 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' print 'Got: ' + str(size) import winsound winsound.Beep(1000,250) print 'Making cylinder vizNode' # height, rad, self.vizNode = vizshape.addCylinder(height=size[0],radius=size[1], alpha = 0.3,color=viz.YELLOW,axis=vizshape.AXIS_X) #self.vizNode.setAxisAngle(1,0,0,90) if( self.vizNode ) : self.vizNode.disable(viz.CULL_FACE) if( self.isVisible ): self.vizNode.visible( viz.ON ) #Make the object visible. else: self.vizNode.visible( viz.OFF ) #Make the object invisible. print self.fileName + ' vizNode created, but not set as visible' self.physNode = self.vizNode.collideMesh() else: print 'Problem creating viz node' import winsound winsound.Beep(1000,250)
# Setup navigation node and link to main view view = viz.MainView viewLink = viz.link(ori_marker, view, mask=viz.LINK_ORI) def UpdatePos(): pos = pos_marker.getPosition() view.setPosition([pos[0], pos[1] - 0.2, -pos[2] + 0.2], viz.ABS_GLOBAL) updateView = vizact.ontimer(0, UpdatePos) ######################################################################################################## # Set up Target Target = vizshape.addCylinder(height=3, radius=0.02) #Change the diameter of the target Target.setPosition([0, 1.5, distance], viz.ABS_GLOBAL) Target.visible(viz.OFF) info = hmd.addMessagePanel(' ', pos=(0, 0, 3)) info.visible(viz.OFF) # Setup metronome sound = viz.addAudio('Bottle_80.mp3') sound.loop(viz.ON) sound.volume(1) sub_rt = open( 'VRrt_' + id + '_Seq-' + Sequence + '_Offset-' + side + '_' + time.strftime("%d-%b-%y_%H-%M") + '.csv', 'a')
def __init__(self): viz.EventClass.__init__(self) self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) self.callback(viz.KEYUP_EVENT, self.onKeyUp) self.callback(viz.TIMER_EVENT, self.onTimer) self.starttimer(1, 1.0 / 25.0, viz.FOREVER) # avatar's x,z location in space and its rotation angle self.theta = 0 self.alpha = 0 self.x = 10 self.z = 45 self.y = 20 self.dtheta = 0 self.dalpha = 0 self.moving = False #number of catches made self.catches = 0 #create models self.quadribol = Model('quadribol' + os.sep + 'model.osgb') self.snitch = vizshape.addSphere(radius=0.5, slices=20, stacks=20, axis=vizshape.AXIS_Y, color=[0.7, 0.5, 0]) self.broom = vizshape.addCylinder(height=10, radius=.25) #texture mapping on sky cube for background sky = viz.add(viz.ENVIRONMENT_MAP, 'mountsky\mount.jpg') skybox = viz.add('skydome.dlc') skybox.texture(sky) #texture mapping for broom self.woodTex = viz.addTexture('woodtex.jpg') self.broom.texture(self.woodTex) #score message displayed on the screen self.text = viz.addText('Score: ' + str(self.catches), viz.SCREEN, pos=[0.01, 0.92, 0]) self.text.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM) self.text.color(0.95, 0.95, 0.95) self.text.disable(viz.LIGHTING) #lighting self.mylight = viz.addLight() self.mylight.enable() self.mylight.color(1, 1, 1) mat = viz.Matrix() mat.postAxisAngle(1, 0, 0, 110) self.mylight.setMatrix(mat) #viz.MainView.getHeadLight().disable() self.snitch.specular([1, 1, .9]) #choose a snitch path pathNum = random.randint(0, 3) self.snitchPath(pathNum) #collision detection self.broom.collideSphere(radius=10) self.broom.disable(viz.DYNAMICS) self.snitch.collideMesh() self.snitch.disable(viz.DYNAMICS) self.snitch.enable(viz.COLLIDE_NOTIFY) self.callback(viz.COLLIDE_BEGIN_EVENT, self.onCollideBegin) viz.playSound('Harry_Potter_Theme.wav')
self.cyl_Right.alpha(1) viz.setMultiSample(4) viz.fov(60) viz.go() # Add the ground plane ground = viz.addChild('ground.osgb') ##################FOREST bambooForest1 = [] bambooForest2 = [] # add 200 bamboo trees to each forest for i in range(0, 200, 1): bambooForest1.append(vizshape.addCylinder(random.randint(10,16),0.1)) bambooForest2.append(vizshape.addCylinder(random.randint(10,16),0.1)) bambooForest1[i].setPosition(random.randint(-16,-3),0.5,random.randint(-20,20)) bambooForest2[i].setPosition(random.randint(3,16),0.5,random.randint(-20,20)) bambooForest1[i].color(0.3,0.8,0.3) bambooForest2[i].color(0.3,0.8,0.3) ################FOREST # Move back cam to see shape immediately viz.MainView.move([0,0,-10]) col = vector.vector(0.8, 0.4, 0.4) position = vector.vector(8, 2, 8) # values must be float #Cylinder(pos_vector, fin_depth, shoulder, TTC, color_vector, radius, height) sample = Cylinder(position, 3.0, 1,2.5, col, 0.2, 10)
def createVisualObjects(self): #creats a sphere(the ball) with radius of 5cm self.ball = vizshape.addSphere(radius = .05) #colors the ball red self.ball.color(viz.YELLOW) self.ball.visible(True) self.Origin = vizshape.addAxes() self.Origin.setPosition(-5.5,0.1,8) # #creats a sphere(the ball) with radius of 5cm # #Head = vizshape.addCone( radius = 0.5, height = 0.8) # Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE) # #colors the ball red # Head.color(viz.PURPLE) # Head.visible(True) # Head.setScale(.2,.2,.3) #creats a sphere(the hand) with radius of 10cm self.Hand = vizshape.addCylinder( height = 0.02, radius = 0.2, axis = vizshape.AXIS_Z) #colors the hand red self.Hand.color(viz.RED) self.Hand.visible(True) self.IOD = 0.06 # create a node3D leftEyeNode self.cyclopEyeNode = vizshape.addSphere(0.015, color = viz.GREEN) #cyclopEyeNode.visible(viz.OFF) self.cyclopEyeNode.setPosition(*self.rawDataStruct['view_Pos_XYZ'][:,0]) self.cyclopEyeNode.setQuat(*self.rawDataStruct['view_Quat_WXYZ'][:,0]) # create a node3D rightEyeNode self.rightEyeNode = vizshape.addSphere(0.015, color = viz.RED) #rightEyeNode.visible(viz.OFF) self.rightEyeNode.setParent(self.cyclopEyeNode) self.rightEyeNode.setPosition(self.IOD/2, 0, 0.0,viz.ABS_PARENT) # right_sphere = gazeSphere(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],sphereColor=viz.ORANGE) # rightGazeVector = gazeVector(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],gazeVectorColor=viz.ORANGE) # right_sphere.toggleUpdate() # rightGazeVector.toggleUpdate() # right_sphere.node3D.alpha(0.7) # create a node3D leftEyeNode self.leftEyeNode = vizshape.addSphere(0.015, color = viz.BLUE) #leftEyeNode.visible(viz.OFF) self.leftEyeNode.setParent(self.cyclopEyeNode) self.leftEyeNode.setPosition(-self.IOD/2, 0, 0.0,viz.ABS_PARENT) # left_sphere = gazeSphere(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],sphereColor=viz.YELLOW) # leftGazeVector = gazeVector(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],gazeVectorColor=viz.YELLOW) # left_sphere.toggleUpdate() # leftGazeVector.toggleUpdate() # left_sphere.node3D.alpha(0.7) # Creating a Line to represent Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.GREEN) self.eyeGazeVector = viz.endLayer() # Object will contain both points and lines self.eyeGazeVector.visible(True) self.eyeGazeVector.setParent(self.cyclopEyeNode) self.eyeGazeVector.pointSize(10) #rightGazeVector.setScale(5,5,5) self.eyeGazeSphere = vizshape.addSphere(0.02, color = viz.GREEN) self.eyeGazeSphere.setParent(self.cyclopEyeNode) # Creating a Line to represent Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.RED) self.rightGazeVector = viz.endLayer() # Object will contain both points and lines self.rightGazeVector.visible(True) #rightGazeVector.setParent(rightEyeNode) self.rightGazeVector.pointSize(10) #rightGazeVector.setScale(5,5,5) self.rightGazeSphere = vizshape.addSphere(0.02, color = viz.RED) self.rightGazeSphere.setParent(self.rightEyeNode) # Creating a Line to represent Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.BLUE) self.leftGazeVector = viz.endLayer() # Object will contain both points and lines self.leftGazeVector.visible(True) #leftGazeVector.setParent(leftEyeNode) #leftGazeVector.setScale(5,5,5) self.leftGazeSphere = vizshape.addSphere(0.02, color = viz.BLUE) self.leftGazeSphere.setParent(self.leftEyeNode) # Creating a Line to represent Eye-Ball Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.YELLOW) self.EyeBallLine = viz.endLayer() # Object will contain both points and lines self.EyeBallLine.visible(True)
def poleCreator(node, length, width, h, number, rad = 0.05): # pole colors poleColours = [[0.51, 0.79, 0.98], [0.84, 0.96, 0.96], [0.8, 0.998, 0.36], [1, 1, 0], [1, 0.9, 0.71], [1, 0.8, 0.64], [0.9, 0.4, 0.09], [0.77, 0.54, 0.09], [0.68, 0.66, 0.43], [0.98, 0.59, 0.42],[0.58, 0.27, 0.21], [0.49, 0.02, 0.32], [0.91, 0.68, 0.67], [0.99, 0.87, 1], [0.74, 0.23, 0.56], [0.37, 0.35, 0.5], [0.57, 0.45, 0.93], [0.91, 0.81, 0.93], [0.31, 0.54, 0.46], [0.29, 0.63, 0.17]] polePaper = viz.addTexture("walltex-w.jpg") a = np.arange(rad, width, 2*rad) x = np.repeat(a, len(a)) - width/2 z = np.tile(a, len(a)/2 - 1) - rad x_right = x[ np.where( x> 0.1 ) ] x_left = x[ np.where( x < -0.05) ] pool_right = np.vstack((x_right, z)) pool_right = np.transpose(pool_right) pool_left = np.vstack((x_left, z)) pool_left = np.transpose(pool_left) # ind = np.random.choice(len(pool_right), number/2, replace=False) ind = np.round(np.random.uniform(0, 1, number/2) * len(x_right)) ind = ind.astype( int ) positions_right = pool_right[ind] ind = np.round(np.random.uniform(0, 1, number/2) * len(x_left)) ind = ind.astype( int ) positions_left = pool_left[ind] poles = viz.addGroup() polelist = [] #add poles on the left side for i in range(number/2): # position for this pole thisX = positions_right[i, 0] thisZ = positions_right[i, 1] #Load a pole pole= vizshape.addCylinder(height=h, radius=rad, yAlign=vizshape.ALIGN_MIN) pole.setParent(node) # Set the color pole.color(poleColours[i]) pole.texture(polePaper) pole.appearance(viz.TEXMODULATE) #Set position pole.setPosition( [thisX, 0, thisZ] ) #Append the pole to a list of poles pole.setParent(poles) #add poles on the left side for i in range(number/2): # position for this pole thisX = positions_left[i, 0] thisZ = positions_left[i, 1] #Load a pole pole= vizshape.addCylinder(height=h, radius=rad, yAlign=vizshape.ALIGN_MIN) pole.setParent(node) # Set the color pole.color(poleColours[i + number/2]) pole.texture(polePaper) pole.appearance(viz.TEXMODULATE) #Set position pole.setPosition( [thisX, 0, thisZ] ) #Append the pole to a list of poles pole.setParent(poles) polelist.append(pole) poles.setParent(node) return (poles, polelist)
def __init__(self, myId, center, zoneRadius, zoneHeight): self.zone = vizshape.addCylinder(height = zoneHeight, radius = zoneRadius, slices = 500) self.x, self.y, self.z = center[0], center[1], center[2] self.radius = zoneRadius self.id = myId self.occupied = False
def makeBasicVizShape(self): # TODO: Move this functionality to a shape subclass. # There is already mocapMarkerSphere subclass. It is confusing to have functionality split # between a subclass and class method. # Returns a pointer to a vizshape object # This is added to the room.objects parent newnode3D = [] if (self.shape == 'box'): #print 'Making box node3D' if (type(self.size) == float or len(self.size) != 3): print('**********Invalid size for box') print( 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' ) print('Got: ' + str(self.size)) import winsound winsound.Beep(1000, 250) lwh = [self.size[1], self.size[2], self.size[0]] newnode3D = vizshape.addBox(lwh, alpha=self.alpha, color=viz.RED) elif self.shape == 'sphere': if type(self.size) == list and len(self.size) == 1: self.size = float(self.size[0]) if type(self.size) != float: # accept a float print('**********Invalid size for sphere') print( 'Check rigidBodySizesString. Expected 1 val for sphere: radius' ) print('Got: ' + str(self.size)) import winsound winsound.Beep(1000, 250) #print 'Making sphere node3D' newnode3D = vizshape.addSphere(radius=float(self.size), alpha=self.alpha, color=viz.BLUE, slices=20, stacks=20) elif ('cylinder' in self.shape): if (type(self.size) == float or len(self.size) != 2): print('**********Invalid size for cylinder') print( 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' ) print('Got: ' + str(self.size)) import winsound winsound.Beep(1000, 250) #print 'Making cylinder node3D' if (self.shape[-2:] == '_X' or self.shape[-2:] == '_Y' or self.shape[-2:] == '_Z'): axisString = 'vizshape.AXIS' + self.shape[-2:] print(axisString + axisString + axisString + axisString) evalString = 'vizshape.addCylinder(height=self.size[0],radius=self.size[1], alpha = self.alpha,color=viz.BLUE,axis=' + axisString + ')' newnode3D = eval(evalString) else: newnode3D = vizshape.addCylinder(height=self.size[0], radius=self.size[1], alpha=self.alpha, color=viz.BLUE, axis=vizshape.AXIS_Y) if newnode3D: self.node3D = newnode3D else: print('vizEnv.room.makeBasicVizShape(): Unable to create node3D') import winsound winsound.Beep(1000, 250) #if(self.parentRoom): newnode3D.setParent(self.parentRoom.objects)
def __init__(self): viz.EventClass.__init__(self) # curve that represents the track self.track = CoasterCurve() # controls the camera's view in 3rd person self.rotateView = 0 self.distView = -200 self.view = 3 # Environment map - puts the scene inside a large box and # texture maps sky images onto the six box sides. sky = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg') skybox = viz.add('skydome.dlc') skybox.texture(sky) # Create a coaster car consisting of a box with a spherical cap in front. # The front of the car faces down the -Z axis. self.car = viz.addGroup() c1 = vizshape.addBox([2, 2, 4], color=viz.GREEN) m = viz.Matrix() m.postTrans(0, 1, 0) # raise bottom of box to XY plane c1.setMatrix(m) c1.setParent(self.car) c1 = vizshape.addBox([1, 2, 1.9], color=viz.BLACK) m = viz.Matrix() m.postTrans(0, 1.5, 1) c1.setMatrix(m) c1.setParent(self.car) c2 = vizshape.addSphere(radius=1, color=viz.YELLOW) m = viz.Matrix() m.postTrans(0, 1, -2) # move to front of box c2.setMatrix(m) c2.setParent(self.car) viz.startLayer(viz.LINE_STRIP) viz.vertexColor(viz.BLACK) for i in range(1, 928): temp = self.track.getLocationAtDist(i) viz.vertex(temp) self.lineStrip = viz.endLayer() self.tunnel = vizshape.addCylinder(height=75, radius=10, bottom=False, top=False, cullFace=False) m = viz.Matrix() m.postAxisAngle(1, 0, 0, 90) m.postMult(self.track.getCurOrient()) m.postTrans(self.track.getCurLocation()) m.postTrans(75, 0, 0) self.tunnel.setMatrix(m) self.tunnelText = viz.addTexture('tunnel.jpg') self.tunnel.texture(self.tunnelText) # set key board callback function self.callback(viz.KEYDOWN_EVENT, self.onKeyDown) # call keyboard callback to initialize the view to 3rd person self.onKeyDown("3")
def makeBasicVisNode(self): # Returns a pointer to a vizshape object # This is added to the room.objects parent newvisNode = [] if(self.shape == 'box' ): #print 'Making box visNode' if( type(self.size) == float or len(self.size) !=3): print '**********Invalid size for box' print 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) lwh = [self.size[1],self.size[2],self.size[0]] newvisNode = vizshape.addBox(lwh ,alpha = self.alpha,color=viz.RED) elif(self.shape == 'sphere'): if( type(self.size) == list and len(self.size) == 1 ): self.size = float(self.size[0]) if( type(self.size) != float): # accept a float print '**********Invalid size for sphere' print 'Check rigidBodySizesString. Expected 1 val for sphere: radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) #print 'Making sphere visNode' newvisNode = vizshape.addSphere(radius = float(self.size), alpha = self.alpha,color=viz.BLUE,slices=10, stacks=10) elif('cylinder' in self.shape): if( type(self.size) == float or len(self.size) !=2): print '**********Invalid size for cylinder' print 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) #print 'Making cylinder visNode' if( self.shape[-2:] == '_X' or self.shape[-2:] == '_Y' or self.shape[-2:] == '_Z' ): axisString = 'vizshape.AXIS' + self.shape[-2:] print axisString + axisString + axisString + axisString evalString = 'vizshape.addCylinder(height=self.size[0],radius=self.size[1], alpha = self.alpha,color=viz.BLUE,axis=' + axisString + ')' newvisNode = eval(evalString) else: newvisNode = vizshape.addCylinder(height=self.size[0],radius=self.size[1], alpha = self.alpha,color=viz.BLUE, axis = vizshape.AXIS_Y ) if( newvisNode ) : self.visNode = newvisNode else: print 'vizEnv.room.makeBasicVisNode(): Unable to create visNode' import winsound winsound.Beep(1000,250) #if(self.parentRoom): newvisNode.setParent(self.parentRoom.objects)
def createVisualObjects(self): self.IOD = 0.06 # create a node3D leftEyeNode self.cyclopEyeNode = vizshape.addSphere(0.015, color = viz.GREEN) self.cyclopEyeNode.alpha(0.3) #cyclopEyeNode.visible(viz.OFF) self.cyclopEyeNode.setPosition(*self.rawDataStruct['view_Pos_XYZ'][:,0]) self.cyclopEyeNode.setQuat(*self.rawDataStruct['view_Quat_WXYZ'][:,0]) # create a node3D rightEyeNode self.rightEyeNode = vizshape.addSphere(0.015, color = viz.RED) #rightEyeNode.visible(viz.OFF) self.rightEyeNode.setParent(self.cyclopEyeNode) self.rightEyeNode.setPosition(self.IOD/2, 0, 0.0,viz.ABS_PARENT) self.rightEyeNode.alpha(0.3) # right_sphere = gazeSphere(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],sphereColor=viz.ORANGE) # rightGazeVector = gazeVector(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],gazeVectorColor=viz.ORANGE) # right_sphere.toggleUpdate() # rightGazeVector.toggleUpdate() # right_sphere.node3D.alpha(0.7) # create a node3D leftEyeNode self.leftEyeNode = vizshape.addSphere(0.015, color = viz.BLUE) #leftEyeNode.visible(viz.OFF) self.leftEyeNode.setParent(self.cyclopEyeNode) self.leftEyeNode.setPosition(-self.IOD/2, 0, 0.0,viz.ABS_PARENT) self.leftEyeNode.alpha(0.3) # left_sphere = gazeSphere(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],sphereColor=viz.YELLOW) # leftGazeVector = gazeVector(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],gazeVectorColor=viz.YELLOW) # left_sphere.toggleUpdate() # leftGazeVector.toggleUpdate() # left_sphere.node3D.alpha(0.7) self.hmdDisplay = vizshape.addPlane([0.126, 0.071], axis = -vizshape.AXIS_Z, color = viz.GRAY) self.hmdDisplay.alpha(0.3) self.hmdDisplay.setParent(self.cyclopEyeNode) self.hmdDisplay.setPosition([0,0,0.0725], viz.ABS_PARENT) # 0.0725 self.pixelatedBall = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.WHITE) self.pixelatedBall.setParent(self.hmdDisplay) self.pixelatedBall.setPosition([0,0,0]) self.pixelatedBall.alpha(1) self.eyePOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.GREEN) self.eyePOR.setParent(self.hmdDisplay) self.eyePOR.setPosition([0,0,0]) self.eyePOR.alpha(1) self.rightPOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.RED) self.rightPOR.setParent(self.hmdDisplay) self.rightPOR.setPosition([0,0,0]) self.rightPOR.alpha(1) self.leftPOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.BLUE) self.leftPOR.setParent(self.hmdDisplay) self.leftPOR.setPosition([0,0,0]) self.leftPOR.alpha(1) #creats a sphere(the ball) with radius of 5cm self.ball = vizshape.addSphere(radius = .08) #colors the ball red self.ball.color(viz.YELLOW) self.ball.visible(True) self.ball.setParent(self.cyclopEyeNode) self.Origin = vizshape.addAxes() self.Origin.setPosition(-5.5,0.1,8) # #creats a sphere(the ball) with radius of 5cm # #Head = vizshape.addCone( radius = 0.5, height = 0.8) # Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE) # #colors the ball red # Head.color(viz.PURPLE) # Head.visible(True) # Head.setScale(.2,.2,.3) #creats a sphere(the hand) with radius of 10cm self.Hand = vizshape.addCylinder( height = 0.02, radius = 0.2, axis = vizshape.AXIS_Z) #colors the hand red self.Hand.color(viz.RED) self.Hand.visible(True) # Creating a Line to represent Cyclopean Eye Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.GREEN) self.eyeGazeVector = viz.endLayer() # Object will contain both points and lines self.eyeGazeVector.visible(True) self.eyeGazeVector.setParent(self.cyclopEyeNode) self.eyeGazeVector.pointSize(10) #rightGazeVector.setScale(5,5,5) self.eyeGazeSphere = vizshape.addSphere(0.02, color = viz.GREEN) self.eyeGazeSphere.setParent(self.cyclopEyeNode) # Creating a Line to represent Right Eye Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.RED) self.rightGazeVector = viz.endLayer() # Object will contain both points and lines self.rightGazeVector.visible(True) #rightGazeVector.setParent(rightEyeNode) self.rightGazeVector.pointSize(10) #rightGazeVector.setScale(5,5,5) self.rightGazeSphere = vizshape.addSphere(0.02, color = viz.RED) self.rightGazeSphere.setParent(self.rightEyeNode) self.rightGazeSphere.visible(False) # Creating a Line to represent Left Eye Gaze Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.BLUE) self.leftGazeVector = viz.endLayer() # Object will contain both points and lines self.leftGazeVector.visible(True) #leftGazeVector.setParent(leftEyeNode) #leftGazeVector.setScale(5,5,5) self.leftGazeSphere = vizshape.addSphere(0.02, color = viz.BLUE) self.leftGazeSphere.setParent(self.leftEyeNode) self.leftGazeSphere.visible(False) # Creating a Line to represent Eye-Ball Vector viz.startLayer(viz.LINES) viz.vertex(0,0,0) viz.vertex(0,0,3) viz.vertexColor(viz.YELLOW) self.EyeBallLine = viz.endLayer() # Object will contain both points and lines self.EyeBallLine.visible(False) #EyeBallLine.setScale(5,5,5) self.male = viz.add('ktex.obj') #male.state(1) #looping idle animation #self.headBone = self.male.getBone('Bip01 Head') #self.headBone.lock() self.male.setParent(self.cyclopEyeNode)
def CreateTheRoom(room): viz.disable(viz.LIGHT0) room.topLight = viz.addLight() room.topLight.setPosition(0, 4, 0) room.topLight.setEuler(-45, 90, 0) room.topLight.spread(270) room.topLight.intensity(2) room.sideLight = viz.addLight() room.sideLight.setPosition(0, 1, 0) room.sideLight.setEuler(45, 0, -90) #see if needs to be put to 360 -room.sideLight.spread(270) room.sideLight.intensity(1.2) #room.backLight = viz.addLight() #room.backLight.setPosition(0,1,0) #room.backLight.setEuler(180,0,0) #room.backLight.spread(270) #room.backLight.intensity(2) #creates the floor plane to be 35x80 #rotated around the Z axis(perpendicular to Y axis) room.floor = vizshape.addPlane(size=(35.0, 80.0), axis=vizshape.AXIS_Y, cullFace=False) #makes the floor look like wood room.floor.texture(viz.addTexture('images/tile_wood.jpg')) #moves the floor +20 meters in the z direction room.floor.setPosition(0, 0, 20) #adds the wall(plane) farthest from the hand/person #35x10 meters**2 #rotated around the X axis (perpendicular to Z axis) room.frontWall = vizshape.addPlane(size=(35, 10), axis=-vizshape.AXIS_Z, cullFace=False) #makes the front wall look like wall #room.frontWall.texture(viz.addTexture('images/tile_gray.jpg')) #moves the wall to match the edge of the room.frontWall.setPosition(0, 5, 25) #makes the wall appear white room.frontWall.color(viz.GRAY) #adds the wall(plane) that when facing the frontWall, is to the camera's left #wall is 80x10 meters**2 #wall is rotated about the Y axis(perpendicular to X axis) room.leftWall = vizshape.addPlane(size=(80, 10), axis=-vizshape.AXIS_X, cullFace=False) #makes the left wall look like wall room.leftWall.texture(viz.addTexture('images/tile_gray.jpg')) #shifts the wall to match the edge of the floor room.leftWall.setPosition(-17.5, 5, 20) #makes the wall appear white room.leftWall.color(viz.GRAY) #adds a wall(plane) that when facing the frontWall is to the camera's right #wall is 80x10 meters**2 #wall is rotated about the Y axis(perpendicular to X axis) room.rightWall = vizshape.addPlane(size=(80, 10), axis=-vizshape.AXIS_X, cullFace=False) #makes the right wall look like wall room.rightWall.texture(viz.addTexture('images/tile_gray.jpg')) #shifts the wall to match the edge of the floor room.rightWall.setPosition(17.5, 5, 20) #makes the wall appear white room.rightWall.color(viz.GRAY) #adds a wall(plane) that when facing the frontWall is to the camera's back #wall is 35x10 meters**2 #wall is rotated about the X axis(perpendicular to Z axis) room.backWall = vizshape.addPlane(size=(35, 10), axis=vizshape.AXIS_Z, cullFace=False) #shifts the wall to match the edge of the floor room.backWall.setPosition(0, 5, -20) room.backWall.color(viz.GRAY) #adds texture to backWall #room.backWall.texture(viz.addTexture('images/tile_slate.jpg')) #makes the wall appear white room.backWall.color(viz.GRAY) #adds a ceiling(plane) that when facing the frontWall is to the camera's topside #wall is 35x80 meters**2 #wall is rotated about the Z axis(perpendicular to Y axis) room.ceiling = vizshape.addPlane(size=(35.0, 80.0), axis=vizshape.AXIS_Y, cullFace=False) #makes the ceiling appear Skyblue in color room.ceiling.color(viz.SKYBLUE) #shifts the ceiling to rest on top of the four walls room.ceiling.setPosition(0, 10, 20) #add a meter marker at 0 meters along the z axis of the room #meter0 = vizshape.addPlane(size = (5,.3), axis = vizshape.AXIS_Y, cullFace = False) #meter0.setPosition(0,.3, 0) #makes the meter marker appear yellow #meter0.color(viz.WHITE) #adds a wall(plane) that when facing the frontWall is to the camera's back #wall is 35x10 meters**2 #wall is rotated about the X axis(perpendicular to Z axis) room.ballPlane = vizshape.addPlane(size=(2, 2), axis=vizshape.AXIS_Z, cullFace=False) #shifts the wall to match the edge of the floor room.ballPlane.setPosition(0, 5, -20) #makes the wall appear white room.ballPlane.color(viz.WHITE) room.ballPlane.alpha(0.0) room.ball = vizshape.addSphere(radius=0.04, color=viz.RED) room.paddle = vizshape.addCylinder(height=0.03, radius=0.15, color=viz.RED, axis=vizshape.AXIS_Z) room.paddle.alpha(1) room.cycEyeNode = vizshape.addCone(radius=0.05, height=0.17, color=viz.PURPLE, axis=vizshape.AXIS_Z) room.cycEyeNode.alpha(1) if (room.visualizeModelOutput == True): room.paddleCloneA = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneA.alpha(.80) room.paddleCloneB = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneB.alpha(.70) room.paddleCloneC = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneC.alpha(.60) room.paddleCloneD = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneD.alpha(.50) room.paddleCloneE = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneE.alpha(.40) room.paddleCloneF = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneF.alpha(.30) room.paddleCloneG = vizshape.addCylinder(height=0.05, radius=0.15, color=viz.ORANGE, axis=vizshape.AXIS_Z) room.paddleCloneG.alpha(.20) if (room.renderGaze == True): room.gazePoint = vizshape.addSphere(radius=0.0005, color=viz.GREEN) room.gazePoint.setParent(room.cycEyeNode) room.male = viz.add('vcc_male.cfg') room.male.alpha(0.0) armBone = room.male.getBone('Bip01 R UpperArm') armBone.lock() #armBone.setEuler(0, 0, 0) armBone = room.male.getBone('Bip01 L UpperArm') armBone.lock() armBone.setEuler(-70, 0, 0) ForearmBone = room.male.getBone('Bip01 R Forearm') ForearmBone.lock() ForearmBone.setEuler(100, -90, 155) hand = room.male.getBone('Bip01 R Hand') hand.lock() hand.setEuler(0, -90, 0.0) room.squash = viz.addChild('Squash_Racquet.3ds') room.squash.scale(0.01, 0.01, 0.01) room.squash.setPosition(*hand.getPosition(mode=viz.ABS_GLOBAL) - np.array([.55, -0.2, -0.2]), mode=viz.ABS_GLOBAL) room.squash.setEuler([0, 0, 15]) #room.squash.setQuat(hand.getQuat()) return room
Y = viz.addText3D('Y',pos=[0,1.1,0],color=viz.GREEN,scale=[0.3,0.3,0.3],align=viz.ALIGN_CENTER_BASE,parent=world_axes) Z = viz.addText3D('Z',pos=[0,0,1.1],color=viz.BLUE,scale=[0.3,0.3,0.3],align=viz.ALIGN_CENTER_BASE,parent=world_axes) #grids are good grid = vizshape.addGrid(color=[0.2]*3) viz.clearcolor(viz.GRAY) #Create proximity manager manager = vizproximity.Manager() manager.setDebug(viz.ON) #create our bisecting plane mid_plane= vizshape.addPlane(size=(.00001,.00001),axis=vizshape.AXIS_X, cullFace=False) start_node= right_node=vizshape.addCylinder(height, radius=2,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_node=vizshape.addCylinder(height, radius= 3,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) right_node=vizshape.addCylinder(height, radius=2,topRadius= None,bottomRadius= None, axis=vizshape.AXIS_Y,slices=20,bottom=True,top=True) left_plane1= vizshape.addPlane(size=(1*scale_x,1*scale_y,),axis=vizshape.AXIS_Y, cullFace=False) left_plane2= vizshape.addPlane(size=(1*scale_x,1*scale_y,),axis=vizshape.AXIS_Y, cullFace=False) box_and_sensor_parameters=[x_translate,y_height,z_depth] box_and_sensor_parameters2= [-x_translate,y_height,z_depth] left_plane=left_plane1.translate(x_translate,y_height,z_depth) left_plane2.translate(-x_translate,y_height,z_depth) #left_plane=plane(list_pos_ori_left) #right_plane=plane(list_pos_ori_right)
def makeBasicVizShape(self): # Returns a pointer to a vizshape object # This is added to the room.objects parent newnode3D = [] if(self.shape == 'box' ): #print 'Making box node3D' if( type(self.size) == float or len(self.size) !=3): print '**********Invalid size for box' print 'Check rigidBodySizesString. Expected 3 val for box: height,width,length.' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) lwh = [self.size[1],self.size[2],self.size[0]] newnode3D = vizshape.addBox(lwh ,alpha = self.alpha,color=viz.RED) elif(self.shape == 'sphere'): if( type(self.size) == list and len(self.size) == 1 ): self.size = float(self.size[0]) if( type(self.size) != float): # accept a float print '**********Invalid size for sphere' print 'Check rigidBodySizesString. Expected 1 val for sphere: radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) #print 'Making sphere node3D' newnode3D = vizshape.addSphere(radius = float(self.size), alpha = self.alpha,color=viz.BLUE,slices=10, stacks=10) elif('cylinder' in self.shape): if( type(self.size) == float or len(self.size) !=2): print '**********Invalid size for cylinder' print 'Check rigidBodySizesString. Expected 2 val for cylinder: height,radius' print 'Got: ' + str(self.size) import winsound winsound.Beep(1000,250) #print 'Making cylinder node3D' if( self.shape[-2:] == '_X' or self.shape[-2:] == '_Y' or self.shape[-2:] == '_Z' ): axisString = 'vizshape.AXIS' + self.shape[-2:] print axisString + axisString + axisString + axisString evalString = 'vizshape.addCylinder(height=self.size[0],radius=self.size[1], alpha = self.alpha,color=viz.BLUE,axis=' + axisString + ')' newnode3D = eval(evalString) else: newnode3D = vizshape.addCylinder(height=self.size[0],radius=self.size[1], alpha = self.alpha,color=viz.BLUE, axis = vizshape.AXIS_Y ) elif ('arrow' in self.shape): print 'Making an arrow' newnode3D = vizshape.addArrow(alpha = self.alpha,color=viz.BLUE, axis = vizshape.AXIS_X, length=0.2,radiusRatio=0.05 ) newnode3D.setPosition(pos) if( newnode3D ) : self.node3D = newnode3D else: print 'vizEnv.room.makeBasicVizShape(): Unable to create node3D' import winsound winsound.Beep(1000,250) #if(self.parentRoom): newnode3D.setParent(self.parentRoom.objects)