Пример #1
0
	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)
Пример #2
0
    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)
Пример #3
0
    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 createPhysicalObjects():
	global midX
	minLineLength = 3
	maxLineGap = 0.5
	
	edge = cv2.Canny(gray,100,200)
	
	lines = cv2.HoughLinesP(edge,1,np.pi/180,100,minLineLength,maxLineGap)
	
	noOfLines = lines.size/4
	print noOfLines
	
	i = 0
	while(i < noOfLines):
		for x1,y1,x2,y2 in lines[i]:
			print x1,y1,x2,y2
			midX = (float(x1) + float(x2))/2
			midY = (float(y1) + float(y2))/2
			x = float(midX)/100
			y = -float(midY)/100
			angle = int(math.atan((y1-y2)/(x2-x1))*180/math.pi)
			#print angle
			box = vizshape.addBox(splitFaces=True)  
			box.setPosition(x,y,6.0)
			xDiff = math.fabs(x1-x2)
			yDiff = math.fabs(y1-y2)
			square = math.pow(xDiff,2) + math.pow(yDiff,2)
			boxSize = math.sqrt(square)/100
			box.setScale(boxSize,0.02,0.5)
			#box.enable(viz.SAMPLE_ALPHA_TO_COVERAGE)
			box.color(viz.SKYBLUE)
			box.collideBox()
			box.disable(viz.DYNAMICS)
			box.setEuler(0,0,angle)
		i+=2
Пример #5
0
	def __init__(self):
		viz.EventClass.__init__(self)
		
		self.zones = []
		for i in range(1, 101):
			self.zones.append(Zone(myId = i, center = [0, 0, i * 100], zoneRadius = 50.0, zoneHeight = 25))
		
		for obj in self.zones:
			obj.zone.color(r = 0, g = 1.0, b = 0)
			obj.zone.alpha(0.8)
			
			obj.zone.setPosition(obj.getCenter())
		
		self.player = vizshape.addBox(size = [5, 5, 5])
		self.player.color([1, 0, 0])
		
		self.playerX = 0
		self.playerY = 0
		self.playerZ = 0
		
		self.inId = 0
		
		self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)
		self.onKeyDown(' ')
		
		self.callback(viz.TIMER_EVENT, self.onTimer)
		self.starttimer(1, viz.FASTEST_EXPIRATION, viz.FOREVER)
Пример #6
0
def createCollisionBody(avatar):
    # create collision boxes around bones that matter
    global collisionLimbBoxes
    for limbName in COLLISION_LIMBS:
        limb = avatar.getBone(limbName)
        # create box for limb
        limbBox = vizshape.addBox(color=viz.WHITE)
        limbBox.disable(viz.RENDERING)
        # find the right size for the box
        size = findBoneSize(limbName)
        limbBox.setScale(size)
        # set up collision properties
        # BL:start
        limbBox.collideBox(bounce=0.0)
        if limbName == "Bip01 L Forearm":
            leftHandIDs.append(limbBox.id)
        elif limbName == "Bip01 R Forearm":
            rightHandIDS.append(limbBox.id)
        # 		if not (limbName == 'Bip01 L Forearm' or limbName == 'Bip01 R Forearm'):
        else:
            TouchCube.disabledTouchers.append(limbBox)

        # BL:end
        # only enable collide notify when animating bone
        # limbBox.enable(viz.COLLIDE_NOTIFY)
        limbBox.disable(viz.DYNAMICS)
        collisionLimbBoxes.append(limbBox)
    pptExtension.limbBoxes = collisionLimbBoxes
    vizact.onupdate(0, updateCollisionBoxes, avatar)
    return
Пример #7
0
    def createStandingBox(self):
        """
            Draw the standing box
            """
        boxSizeInfo = [
            self.standingBoxSize_WHL[0], self.standingBoxSize_WHL[1],
            self.standingBoxSize_WHL[2]
        ]

        self.standingBox = vizshape.addBox(boxSizeInfo,
                                           color=viz.GREEN,
                                           splitFaces=True,
                                           back=True)
        self.standingBox.emissive([0, 1, 0])
        self.standingBox.alpha(0.5)

        if (self.isLeftHanded): self.standingBoxOffset_X *= -1

        self.standingBox.setPosition(float(-self.standingBoxOffset_X),
                                     self.standingBoxSize_WHL[1] / 2, .01)

        self.standingBox.color(1, 0, 0, node='back')
        self.standingBox.emissive(1, 0, 0, node='back')
        self.standingBox.alpha(0.7, node='back')

        self.standingBox.setParent(self.objects)
        #self.standingBox.disable(viz.CULLING)
        self.standingBox.disable(viz.CULL_FACE)
	def __setupTracking__(self):
		
		#get mocap interface
		self.mocap = Connector.getMocapInterface()

		#Get the shutter-glass rigid body
		self.shutterGlass = self.mocap.returnPointerToRigid(Connector.SHUTTERGLASSES)
		self.head_tracker = viz.link(self.shutterGlass.vizNode,viz.NullLinkable,srcFlag=viz.ABS_PARENT)
		self.cave.setTracker(self.head_tracker)

		# Create cave view
		cave_origin = vizcave.CaveView(self.head_tracker)
		
		#In case you want to override & translate the physical location of cave, uncommnet this
		
		'''
		origin_tracker = viztracker.KeyboardMouse6DOF()
		origin_link = viz.link(origin_tracker, cave_origin)
		origin_link.setMask(viz.LINK_POS)
		'''
		
		#Foot rigidBodies
		leftFootRigid = self.mocap.returnPointerToRigid(Connector.L_FOOT)
		rightFootRigid = self.mocap.returnPointerToRigid(Connector.R_FOOT)
		
		#Foot visuals, make them 100% transparent when not in debug mode
		self.leftFootViz = vizshape.addBox(size=(.2,.2,.2))
		self.rightFootViz = vizshape.addBox(size=(.2,.2,.2))
		
		if(self.debug):
			self.leftFootViz.alpha(0.025)
			self.rightFootViz.alpha(0.025)
		else:
			self.leftFootViz.alpha(0.0075)
			self.rightFootViz.alpha(0.0075)
		
		#Foot class objects
		self.leftFoot = Foot(mocapFootObj = leftFootRigid, name="Left")
		self.rightFoot = Foot(mocapFootObj = rightFootRigid, name="Right")
		
		#setup buffer updates
		vizact.onupdate(0, self.leftFoot.populateNextBufferElement)
		vizact.onupdate(0, self.rightFoot.populateNextBufferElement)
		vizact.onupdate(0, self.updateBooties)
		viz.callback(viz.COLLIDE_BEGIN_EVENT, self.collideDetected)
def addOutsideLighting(model=MODEL, scene=viz.MainScene):
    scenery = vizshape.addBox([2.8, 2.8, 2.8])
    scenery.emissive(viz.SLATE)
    scenery.setPosition([1.15, 2.34, 4.73])
    tex = viz.addTexture("resources/images/sfview.png")
    scenery.texture(tex)
    scenery.disable(viz.SHADOW_CASTING)

    light = vizfx.addDirectionalLight(scene=SCENE)
    light.quadraticattenuation(1)
    light.intensity(0.2)
    light.setPosition([0.24, 2, 3.73])
    light.setEuler(144, 0, 0)
Пример #10
0
def define_table():
    """
        Zusammenbau des Tischs.
        Quelle: Herr Hofmann
    """
    table1_plate = vizshape.addBox(size=[2, 0.1, 2], pos=[0, 1, 5], alpha=1)
    table1_plate.collideBox()
    table1_plate.disable(viz.DYNAMICS)
    table1_foot1 = vizshape.addBox(size=[0.25, 1, 0.25],
                                   pos=[0.7, 0.5, 4.5],
                                   alpha=1)
    table1_foot1.collideBox()
    table1_foot1.disable(viz.DYNAMICS)
    table1_foot2 = vizshape.addBox(size=[0.25, 1, 0.25],
                                   pos=[-0.7, 0.5, 5.5],
                                   alpha=1)
    table1_foot2.collideBox()
    table1_foot2.disable(viz.DYNAMICS)
    table1_foot3 = vizshape.addBox(size=[0.25, 1, 0.25],
                                   pos=[-0.7, 0.5, 4.5],
                                   alpha=1)
    table1_foot3.collideBox()
    table1_foot3.disable(viz.DYNAMICS)
    table1_foot4 = vizshape.addBox(size=[0.25, 1, 0.25],
                                   pos=[0.7, 0.5, 5.5],
                                   alpha=1)
    table1_foot4.collideBox()
    table1_foot4.disable(viz.DYNAMICS)

    podest = vizshape.addBox(
        size=[1.3, 0.65, 1.7],  #Podest für omnRobh
        pos=[-1.9, 0, 5.0],
        alpha=1)
    podest.color(.5, .5, .7)

    #KUKA-Logo

    logo = vizshape.addBox(size=[2.4, 2.0, 0.01], pos=[0, 4.0, 7], alpha=1)
    logo.texture(viz.addTexture('logo.jpg'))

    # Textures
    table1_plate.texture(viz.addTexture('Maserung.jpg'))
    table1_foot1.texture(viz.addTexture('Maserung.jpg'))
    table1_foot2.texture(viz.addTexture('Maserung.jpg'))
    table1_foot3.texture(viz.addTexture('Maserung.jpg'))
    table1_foot4.texture(viz.addTexture('Maserung.jpg'))
def massMakeBoxes(boxList):
    print("massMakeBozes is a go!")

    # Make all of the boxes needed in the trail.
    for x in range(9):
        print("making box " + str(x))
        temp = vizshape.addBox([bSize, bSize, bSize],
                               right=True,
                               left=True,
                               top=True,
                               bottom=True,
                               front=True,
                               back=True,
                               splitFaces=False,
                               color=viz.GREEN)
        boxList.append(temp)

    massSetBoxPos(boxList)
    return boxList
Пример #12
0
    def createStandingBox(self):
        '''
        This creates a transparent box from which the subject starts each trial.
        Parameters of the box are typically stored in the experimetn config file.
        This function is typically called in room.init()
        '''

        # Draw the standing box
        boxSizeInfo = [ self.standingBoxSize_WHL[0], self.standingBoxSize_WHL[1],self.standingBoxSize_WHL[2]]

        self.standingBox = vizshape.addBox( boxSizeInfo,color=viz.GREEN,splitFaces = True,back=True)

        self.standingBox.setPosition([self.standingBoxOffset_X, 0.1, self.standingBoxOffset_negZ])
        
        self.standingBox.emissive([0,1,0])
        self.standingBox.alpha(0.5)

        # Fix Me: Kamran
        self.standingBox.setParent(self.objects)
        self.standingBox.disable(viz.CULL_FACE)
Пример #13
0
    def createStandingBox(self):
        
            
            # Draw the standing box
            
            boxSizeInfo = [ self.standingBoxSize_WHL[0], self.standingBoxSize_WHL[1],self.standingBoxSize_WHL[2]]
            
            self.standingBox = vizshape.addBox( boxSizeInfo,color=viz.GREEN,splitFaces = True,back=True)
            self.standingBox.emissive([0,1,0])
            self.standingBox.alpha(0.5)
            
            if( self.isLeftHanded ): self.standingBoxOffset_X *= -1;
            
            self.standingBox.setPosition(float(-self.standingBoxOffset_X),self.standingBoxSize_WHL[1]/2,.01)            

            self.standingBox.color(1,0,0,node='back')            
            self.standingBox.emissive(1,0,0,node='back')
            self.standingBox.alpha(0.7,node='back')

            self.standingBox.setParent(self.objects)
            #self.standingBox.disable(viz.CULLING)
            self.standingBox.disable(viz.CULL_FACE)
Пример #14
0
def setup(avatar):
	global headSphere, lhSphere, rhSphere, lfSphere, rfSphere;
	global rhPos, lhPos, rfPos, lfPos, bodyPos;
	
	rhPos = avatar.getBone('Bip01 R Hand').getPosition(viz.ABS_GLOBAL);
	lhPos = avatar.getBone('Bip01 L Hand').getPosition(viz.ABS_GLOBAL);
	rfPos = avatar.getBone('Bip01 R Foot').getPosition(viz.ABS_GLOBAL);
	lfPos = avatar.getBone('Bip01 L Foot').getPosition(viz.ABS_GLOBAL);
	bodyPos = avatar.getBone('Bip01').getPosition(viz.ABS_GLOBAL);
	
	viz.MainView.setPosition(2.2, 0.5, -1.7)
	viz.MainView.setEuler(-110, 0, 0)
	viz.MainWindow.fov(90)
	
	grid = vizshape.addGrid();
	grid.color([0.5] * 3);
	
	global bodyBox;
	bodyBox = vizshape.addBox();
	bodyBox.setScale(0.45, 1.2, 0.35);
	
	bodyBox.visible(viz.OFF);
	
	viz.callback(viz.KEYDOWN_EVENT, onKeyDown);
	
	#link = viz.link(avatar.getBone('Bip01 Head'), viz.MainView)
	#link = viz.link(viz.MainView, avatar.getBone('Bip01 Head'))
	#link.postTrans([0, 0, -0.2]);
	
	if(DEBUG_MODE):
		print "adding spheres";
		rhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		rfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		
		headSphere = vizshape.addSphere(radius = 0.1, color = viz.YELLOW);
	return;
Пример #15
0
def practice():
    practice_text = viz.addText3D('Practice trials', pos=[-2.5, 1.7, 20])
    practice_text.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    practice_text.remove()
    targets = [5, 12, 24]
    while len(targets) > 0:
        global k
        k = 0
        yield viztask.waitTime(.5)
        ready_text = viz.addText3D('Get ready!', pos=[-2, 1.7, 20])
        ready_text.color(0, 0, 0)
        yield viztask.waitTime(1)
        ready_text.remove()
        yield viztask.waitTime(2)
        yield room()
        doors = []
        D1 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D2 = random.choice([4.75, 5.75, 6.75, 7.75])
        D3 = random.choice([13.75, 14.75, 15.75, 16.75])
        D4 = random.choice([22.75, 23.75, 24.75, 25.75])
        D5 = random.choice([31.75, 32.75, 33.75, 34.75])
        L_doors = []
        L_doors.append(D1)
        L_doors.append(D2)
        L_doors.append(D3)
        L_doors.append(D4)
        L_doors.append(D5)
        D7 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D8 = random.choice([4.75, 5.75, 6.75, 7.75])
        D9 = random.choice([13.75, 14.75, 15.75, 16.75])
        D10 = random.choice([22.75, 23.75, 24.75, 25.75])
        D11 = random.choice([31.75, 32.75, 33.75, 34.75])
        R_doors = []
        R_doors.append(D7)
        R_doors.append(D8)
        R_doors.append(D9)
        R_doors.append(D10)
        R_doors.append(D11)
        people = []
        P1 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P2 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        L_people = []
        L_people.append(P1)
        L_people.append(P2)
        P3 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P4 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        R_people = []
        R_people.append(P3)
        R_people.append(P4)
        targ = random.choice(targets)
        if targ == 5:
            size = .102012
        if targ == 12:
            size = .24483
        if targ == 24:
            size = .48966
        sphere = vizshape.addSphere((size), 20, 20)
        sphere.color(1.02, .444, 0)
        sphere.setPosition([0, (size), (targ)])
        shadow = vizshape.addCircle((size), 20)
        shadow.color(
            [.05, .05, .05]
        )  #proportion of 1 for amount of each color (red, green, blue). 0,0,0 = black, 1,1,1 = white.
        shadow.setEuler([0, 90, 0])
        shadow.setPosition([0, .001, (targ)])
        for z in np.asarray(L_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([-4.9733, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(-4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(R_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([4.9683, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(L_people):
            x = random.choice([0, 90, 180])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([-4.25, 0, float(z)])
            person.state(1)
            people.append(person)
        for z in np.asarray(R_people):
            x = random.choice([0, 180, 270])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([4.5, 0, float(z)])
            person.state(1)
            people.append(person)
        targets.remove(targ)
        en_env()
        tic = time.time()
        yield viztask.waitTime(
            .01
        )  #this is necessary to keep the headset display on for the duration of time.sleep. Can't use time.sleep for any longer than 100 ms or so bc it pauses tracking
        time.sleep(
            .09
        )  #this is necessary to be as precise as possible in the display time. Still not perfect bc of unknown processing time of background functions
        toc = time.time()
        mask.enable(viz.RENDERING)
        dis_env()
        sphere.remove()
        shadow.remove()
        for door in np.asarray(doors):
            door.remove()
        for person in np.asarray(people):
            person.remove()
        yield viztask.waitTime(1)
        mask.disable(viz.RENDERING)
        print toc - tic
        viz.callback(
            viz.KEYDOWN_EVENT, KeyEvents
        )  #press Enter (main keyboard) if the participant misses the target and the target will be appended back into the list.
        yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
        if k == 1:
            targets.append(targ)
Пример #16
0
    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 createSensors():
	global firstNodeBox, secondNodeBox, thirdNodeBox, fourthNodeBox, fifthNodeBox, boxEntered1, boxEntered2, boxEntered3, boxEntered4, boxEntered5
	global firstProximityBox, secondProximityBox, thirdProximityBox, fourthProximityBox, fifthProximityBox
	#create sensors for text
	firstNodeBox = vizshape.addBox(size=(globals_oa.answerQuadSize),right=False,left=False,top=False,bottom=True,front=True,back=False,splitFaces=True,flipFaces=True)
	firstNodeBox.setPosition(globals_oa.firstQuadPosition)
	firstNodeBox.setEuler(globals_oa.firstQuadEuler)
	firstNodeBox.texture(handTexture, node='bottom')
	firstNodeBox.emissive(viz.WHITE)
	firstNodeBox.alpha(.7)
	firstProximityBox = vizproximity.Sensor(vizproximity.RectangleArea((.45,.45),(0,0)), source = (firstNodeBox))
	
	secondNodeBox = vizshape.addBox(size=(globals_oa.answerQuadSize),right=False,left=False,top=False,bottom=True,front=True,back=False,splitFaces=True,flipFaces=True)
	secondNodeBox.texture(handTexture, node='bottom')
	secondNodeBox.emissive(viz.WHITE)
	secondNodeBox.setPosition(globals_oa.secondQuadPosition)
	secondNodeBox.setEuler(globals_oa.secondQuadEuler)
	secondNodeBox.alpha(.7)
	secondProximityBox = vizproximity.Sensor(vizproximity.RectangleArea((.45,.45),(0,0)), source = (secondNodeBox))	
	
	thirdNodeBox = vizshape.addBox(size=(globals_oa.answerQuadSize),right=False,left=False,top=False,bottom=True,front=True,back=False,splitFaces=True,flipFaces=True)
	thirdNodeBox.setPosition(globals_oa.thirdQuadPosition)
	thirdNodeBox.texture(handTexture, node='bottom')
	thirdNodeBox.emissive(viz.WHITE)
	thirdNodeBox.alpha(.7)
	thirdProximityBox = vizproximity.Sensor(vizproximity.RectangleArea((.45,.45),(0,0)), source = (thirdNodeBox))
	
	fourthNodeBox = vizshape.addBox(size=(globals_oa.answerQuadSize),right=False,left=False,top=False,bottom=True,front=True,back=False,splitFaces=True,flipFaces=True)
	fourthNodeBox.texture(handTexture, node='bottom')
	fourthNodeBox.emissive(viz.WHITE)
	fourthNodeBox.setPosition(globals_oa.fourthQuadPosition)
	fourthNodeBox.setEuler(globals_oa.fourthQuadEuler)
	fourthNodeBox.alpha(.7)
	fourthProximityBox = vizproximity.Sensor(vizproximity.RectangleArea((.45,.45),(0,0)), source = (fourthNodeBox))
	
	fifthNodeBox = vizshape.addBox(size=(globals_oa.answerQuadSize),right=False,left=False,top=False,bottom=True,front=True,back=False,splitFaces=True,flipFaces=True)
	fifthNodeBox.setPosition(globals_oa.fifthQuadPosition)
	fifthNodeBox.setEuler(globals_oa.fifthQuadEuler)
	fifthNodeBox.texture(handTexture, node='bottom')
	fifthNodeBox.emissive(viz.WHITE)
	fifthNodeBox.alpha(.7)
	fifthProximityBox = vizproximity.Sensor(vizproximity.RectangleArea((.45,.45),(0,0)), source = (fifthNodeBox))

	#create targets

#	targetLeftHand = vizproximity.Target(globals_oa.lhViveTracker)
#	targetRightHand = vizproximity.Target(globals_oa.rhViveTracker)
	targetLeftHand = vizproximity.Target(globals_oa.lhModel)
	targetRightHand = vizproximity.Target(globals_oa.rhModel)
	
	#Create proximity manager 
	manager = vizproximity.Manager()

	#Add destination sensors to manager
	manager.addSensor(firstProximityBox)
	manager.addSensor(secondProximityBox)
	manager.addSensor(thirdProximityBox)
	manager.addSensor(fourthProximityBox)
	manager.addSensor(fifthProximityBox)

	#Add viewpoint target to manager
	manager.addTarget(targetLeftHand)
	manager.addTarget(targetRightHand)
	
	manager.onEnter(None, enterProximity)
	manager.onExit(None, exitProximity)

#	vizact.onkeydown('x',manager.setDebug,viz.TOGGLE)
	
#	firstNodeBox.disable(viz.RENDERING)
#	secondNodeBox.disable(viz.RENDERING)
#	thirdNodeBox.disable(viz.RENDERING)
#	fourthNodeBox.disable(viz.RENDERING)
#	fifthNodeBox.disable(viz.RENDERING)
	firstNodeBox.visible(False)
	secondNodeBox.visible(False)
	thirdNodeBox.visible(False)
	fourthNodeBox.visible(False)
	fifthNodeBox.visible(False)

	if globals_oa.rhViveTracker is not None: vizact.onsensordown(globals_oa.rhViveTracker, steamvr.BUTTON_TRIGGER,selectAnswer)
	if globals_oa.lhViveTracker is not None: vizact.onsensordown(globals_oa.lhViveTracker, steamvr.BUTTON_TRIGGER,selectAnswer)
Пример #18
0
    frodo = frodo + [randy2[1]] * 50
    frodo = frodo + [randy2[2]] * 50

    samwise = samwise + [1] * 25
    samwise = samwise + [0] * 25
    samwise = samwise + [1] * 25
    samwise = samwise + [0] * 25
    samwise = samwise + [1] * 25
    samwise = samwise + [0] * 25

global phaxxe
phaxxe = 0  #don't start at match ankles because there is no previous test to look at, indexing error in stepind

#experimental, add lines where alpha and X should be

alphal = vizshape.addBox(size=[1, 0.002, 0.001])
alphal.setPosition(0, targetUr, 0)
Xl = vizshape.addBox(size=[1, 0.002, 0.001])
Xl.setPosition(0, targetXr, 0)

#create latitudinal grid, "10" is the target step length, the grid expands above and belo
#lines = {}#create empty dictionary
#for x in range(1,12,1):
#	lines["Tp{0}".format(x)]=vizshape.addBox(size=[1,0.002,0.001])
#	lines["Tp{0}".format(x)].setPosition(0,targetmean+0.05*targetmean+(x-1)*0.1*targetmean,0)#each gap represents 20 percent of target?
#	lines["Tn{0}".format(x)]=vizshape.addBox(size=[1,0.002,0.001])
#	lines["Tn{0}".format(x)].setPosition(0,targetmean+0.05*targetmean-(x-1)*0.1*targetmean,0)
##	print((x-1)*0.02)
#global tnums
#tnums = {}
#for x in range(0,21,1):
viz.vertex(-4.8, 2.7, 18.9)
viz.vertex(4.8, -2.7, 18.9)
viz.vertex(-4.8, -2.7, 18.9)
viz.vertexColor(0, 1, 0)
viz.vertex(6.4, 0, 18.9)
viz.vertex(-6.4, 0, 18.9)
viz.vertex(0, 3.6, 18.9)
viz.vertex(0, -3.6, 18.9)
gridLines = viz.endLayer()

squares = {}
fbsquares = {}
for i in range(len(position)):
    if i <= 11 and i != 10:
        squares['square' + str(i)] = vizshape.addBox(size=(size, size, 0.01),
                                                     splitFaces=False,
                                                     pos=position[str(i)])
        #fbsquares['fbsquare'+str(i)] = vizshape.addQuad(size=(size+0.1,size+0.1), pos = position[str(i)],color = (0,0,0))
    else:
        squares['square' + str(i)] = vizshape.addBox(size=(keepsize, keepsize,
                                                           0.01),
                                                     splitFaces=False,
                                                     pos=position[str(i)])
        #fbsquares['fbsquare'+str(i)] = vizshape.addQuad(size=(keepsize+0.1,keepsize+0.1), pos = position[str(i)],color = (1,1,1 ))

texts = {}
#Set text showing on the squares
for i in range(len(position)):
    if i <= 11 and i != 10:
        texts['text' + str(i)] = viz.addText(textList[str(i)].encode('utf-8'),
                                             parent=squares['square' + str(i)],
Пример #20
0
def calibration():
	''' The heart of the calibration routine. Presents points and collects data. '''


	# start calibration routine and sample data
	n = {'subject':'calibration.should_start', 'hmd_video_frame_size':(2160,1200), 'outlier_threshold':35}
	print(send_recv_notification(n))


	ref_data = []
	
	yield showMessage('Zum Starten die Leertaste drücken')
	
	for p in norm_positions:
		
		print('calibration point: ', p)
	
		norm_x = p[0]
		norm_y = p[1]
		
		first_run = True
		
		if first_run:
			
			first_run = False
		
			'''set up a plane 'right in front of user' on which we want to project the dots'''
	
			# target the current center of view
			p_line = viz.MainWindow.screenToWorld(.5, .5)
		
			# let's modify the line and call it line 2. Here we let the line end at the "depth" value
			p_line_2 = viz.Line(begin=p_line.begin, end=p_line.end, dir=p_line.dir, length=depth)
						
			# Add the plane and apply the matrix of our viewpoint to the plane
			plane = vizshape.addBox(size=[3.6, 2, .1])
			mymat = viz.MainView.getMatrix()
			plane.setMatrix(mymat)
			
			# Reposition the plane to the end of line 2
			plane.setPosition(p_line_2.end)
			plane.color([.25,.25,.25])
			plane.alpha(.95)
			
			# Lock it to user
			plane_link = viz.grab(viz.MainView, plane)
		
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([norm_x, norm_y])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		
		# place a dot (at depth level of line) 
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		
		# lock dot to user
		view_link = viz.grab(viz.MainView, dot)
		
		print('ready')
		viz.playSound('beep500_200.wav')
		yield viztask.waitKeyDown(' ')
				
		for s in range(60):
			
			# get the current pupil time (pupil uses CLOCK_MONOTONIC with adjustable timebase).
			# You can set the pupil timebase to another clock and use that.
			t = get_pupil_timestamp()

			# here the left and right screen marker positions are identical.
			datum0 = {'norm_pos':p,'timestamp':t,'id':0}
			datum1 = {'norm_pos':p,'timestamp':t,'id':1}
			ref_data.append(datum0)
			ref_data.append(datum1)
			yield viztask.waitTime(1/60.)
			print(t)
		
		dot.color(viz.RED)
		
		print('waiting for next position...')
		
		yield viztask.waitKeyDown(' ')
		
		yield dot.remove()
		
	

	# send ref data to Pupil Capture/Service:
	# this notification can be sent once at the end or multiple times.
	# during one calibraiton all new data will be appended.
	n = {'subject':'calibration.add_ref_data','ref_data':ref_data}
	print(send_recv_notification(n))

	# stop calibration
	# pupil will correlate pupil and ref data based on timestamps,
	# compute the gaze mapping params, and start a new gaze mapper.
	n = {'subject':'calibration.should_stop'}
	print(send_recv_notification(n))

	time.sleep(2)
		
	showMessage('calibration done! - now validate!')

	plane.remove()
	
	yield viztask.waitTime(2)
Пример #21
0
    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)
Пример #22
0
def trial_down ():
	global k
	k = 0
	global x
	x = 0
	for i in range (100):
		yield viztask.waitTime(.5)
		ready_text = viz.addText3D('Get ready!',pos = [-2,1.7,20])	
		ready_text.color(0,0,0)
		yield viztask.waitTime(1)
		ready_text.remove ()
		yield viztask.waitTime(2)	
		yield room ()
		doors = []
		D1 = random.choice([-4.25,-3.25,-2.25,-1.25])
		D2 = random.choice([4.75,5.75,6.75,7.75])
		D3 = random.choice([13.75,14.75,15.75,16.75])
		D4 = random.choice([22.75,23.75,24.75,25.75])
		D5 = random.choice([31.75,32.75,33.75,34.75])
		L_doors = []
		L_doors.append(D1)
		L_doors.append(D2)
		L_doors.append(D3)
		L_doors.append(D4)
		L_doors.append(D5)
		D7 = random.choice([-4.25,-3.25,-2.25,-1.25])
		D8 = random.choice([4.75,5.75,6.75,7.75])
		D9 = random.choice([13.75,14.75,15.75,16.75])
		D10 = random.choice([22.75,23.75,24.75,25.75])
		D11 = random.choice([31.75,32.75,33.75,34.75])
		R_doors = []
		R_doors.append(D7)
		R_doors.append(D8)
		R_doors.append(D9)
		R_doors.append(D10)
		R_doors.append(D11)
		people = []
		P1 = random.choice([9.25,10.25,11.25,12.25,18.25,19.25,20.25,21.25])
		P2 = random.choice([27.25,28.25,29.25,30.25,36.25,37.25,38.25,39.25])
		L_people = []
		L_people.append(P1)
		L_people.append(P2)
		P3 = random.choice([9.25,10.25,11.25,12.25,18.25,19.25,20.25,21.25])
		P4 = random.choice([27.25,28.25,29.25,30.25,36.25,37.25,38.25,39.25])
		R_people = []
		R_people.append(P3)
		R_people.append(P4)
		targ = random.choice(targets)
		if targ == 2.5:
			size = .051006
		if targ == 3.5:
			size = .071409	
		if targ == 4.8:
			size = .097932
		if targ == 6.2:
			size = .126495
		if targ == 7.6:
			size = .155059
		if targ == 9:
			size = .183622
		if targ == 10.4:
			size = .212186
		if targ == 11.8:
			size = .240749
		if targ == 13.2:
			size = .269313
		if targ == 14.6:
			size = .297876
		if targ == 17.4:
			size = .355003
		if targ == 20.2:
			size = .41213
		if targ == 23:
			size = .469257
		if targ == 25.8:
			size = .526384
		if targ == 30:
			size = .612075
		if targ == 38:
			size = .775295
		print targ
		sphere = vizshape.addSphere((size),20,20)
		sphere.color(1.02,.444,0)
		sphere.setPosition([0,(size),(targ)])
		shadow = vizshape.addCircle((size),20)
		shadow.color([.05,.05,.05]) #proportion of 1 for amount of each color (red, green, blue). 0,0,0 = black, 1,1,1 = white.
		shadow.setEuler([0,90,0])
		shadow.setPosition([0,.001,(targ)])
		for z in np.asarray(L_doors):
			door = vizshape.addBox(size=[.04445,2.13,.91])  
			door.texture(wood)
			door.setPosition([-4.9733,1.065,float(z)])
			doors.append(door)
			doorknob = vizshape.addSphere(radius=.045,axis=vizshape.AXIS_X)
			doorknob.color(viz.YELLOW)
			doorknob.setPosition(-4.9396,1,(float(z)-.3364))
			doors.append(doorknob)
		for z in np.asarray(R_doors):
			door = vizshape.addBox(size=[.04445,2.13,.91])  
			door.texture(wood)
			door.setPosition([4.9683,1.065,float(z)])
			doors.append(door)
			doorknob = vizshape.addSphere(radius=.045,axis=vizshape.AXIS_X)
			doorknob.color(viz.YELLOW)
			doorknob.setPosition(4.9396,1,(float(z)-.3364))
			doors.append(doorknob)	
		for z in np.asarray(L_people):
			o = random.choice([0,90,180])
			person = viz.addAvatar('vcc_female.cfg',euler=(float(o),0,0))
			person.setPosition([-4.25,0,float(z)])
			person.state(1)
			people.append(person)
		for z in np.asarray(R_people):
			o = random.choice([0,180,270])
			person = viz.addAvatar('vcc_female.cfg',euler=(float(o),0,0))
			person.setPosition([4.5,0,float(z)])
			person.state(1)
			people.append(person)	
		en_env()
		tic = time.time()
		yield viztask.waitTime(.01) 
		time.sleep(.09+x)
		toc = time.time ()
		mask.enable(viz.RENDERING)
		dis_env()
		sphere.remove ()
		shadow.remove ()
		for door in np.asarray(doors):
			door.remove()
		for person in np.asarray(people):
			person.remove()
		yield viztask.waitTime(1)
		mask.disable(viz.RENDERING)
		print toc - tic
		viz.callback(viz.KEYDOWN_EVENT,KeyEvents)
		yield viztask.waitKeyDown(viz.KEY_KP_ENTER) 
		if k == 1:
			break
	times.append((toc - tic)+.01)		
	print times
Пример #23
0
    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)
Пример #24
0
global viewLink
viewLink = viz.link(navigationNode, viz.MainView)

global beltspeed
beltspeed = 1 #units must be meters/second

#hmrl = viz.addChild('HMRL8.osgb')
#hmrl.setPosition(0,0,0)
#hmrl.setEuler(90,270,0)
#hmrl.setScale(0.01,0.01,0.01)

#create optic flow
rt = {}
tlocs = {}
for x in range(1,50,1):
	rt["T{0}".format(x)]=vizshape.addBox(size=[0.1,0.1,0.1])
	rt["T{0}".format(x)].setPosition(0.462,0,2*x)
	tlocs["T{0}".format(x)]=2*x
	rt["T{0}".format(x)].color(1,1,1)
#	rt["T{0}".format(x)].disable(viz.LIGHTING)

r2t = {}
t2locs = {}
for x in range(1,50,1):
	r2t["T{0}".format(x)]=vizshape.addBox(size=[0.1,0.1,0.1])
	r2t["T{0}".format(x)].setPosition(0.462,3,2*x)
	t2locs["T{0}".format(x)]=2*x
	r2t["T{0}".format(x)].color(1,1,1)
	
r3t = {}
t3locs = {}
Пример #25
0
def addThirdArm(avatar):
	global isCube1, isCube2, thirdArm
	
	# For horn:
#	# EXTENSION: Add third arm
#	TAH_HEIGHT = 0.2
#	TAH_TOP_RADIUS = 0.02
#	TAH_BOTTOM_RADIUS = 0.01
#	TA_HEIGHT = 2.0
#	TA_POPPER_HEIGHT = 1.0
#	TA_RADIUS = 0.015
#	thirdArmCHorn = vizshape.addCylinder(height=TAH_HEIGHT, topRadius=TAH_TOP_RADIUS, bottomRadius=TAH_BOTTOM_RADIUS)
#	
#	# To attach arm to chest:
#	tahCLink = viz.link(avatar.getBone('Bip01 Spine'), thirdArmCHorn, mask=viz.LINK_POS)
#	tahCLink.preTrans([0, 0.3, 0.1], 0)
#	#tahCLink.preEuler([0, 90, 0], 1)
#	
#	thirdArmC = viz.addGroup()
#	thirdArmLimbC = vizshape.addCone(TA_RADIUS, TA_HEIGHT)
#	#thirdArmLimbC.setParent(thirdArmC)
#	tacLink = viz.link(thirdArmC, thirdArmLimbC, priority=1)
#	tacLink.preEuler([0,90,0], 0)
#	tacLink.preTrans([0, TA_HEIGHT / 2, 0], 1)
#	#thirdArmLimbC.setPosition(0, TA_HEIGHT / 2, 0, mode=viz.ABS_PARENT)
#	thirdArmC.setParent(thirdArmCHorn)
#	thirdArmC.setPosition(0, TAH_HEIGHT / 2, 0, mode=viz.ABS_PARENT)
#	thirdArmC.color(0,1,0)
#
#	# Add third arm collision box
#	thirdArmLimbC.collideBox()
#	thirdArmLimbC.disable(viz.DYNAMICS)
#	TouchCube.thirdArm = thirdArmLimbC


	# For Arm:
	thirdArmHorn = viz.addGroup()
	thirdArm = viz.addChild(resources.ARM_MODEL)
	thirdArm.setScale(resources.ARM_SCALE)
	thirdArm.setParent(thirdArmHorn)
	tahLink = viz.link(avatar.getBone('Bip01 Spine'), thirdArmHorn)
	tahLink.preTrans([0, 0.3, 0.1], 0)
	tahLink.preEuler([-90, 0, 0], 1)
	
	
	
	box = vizshape.addBox(size=(1, 1, 1))
	spherelink = viz.link(thirdArmHorn, box)
	#spherelink.preTrans([0, 0, -1], 1)
	
	
	# Add third arm collision box
#	collide = vizshape.addBox(thirdArm.getBoundingBox().getSize())
#	center = thirdArm.getBoundingBox().getCenter()
#	collide.setCenter(center[0] + 0.65, center[1] + 0.08, center[2])
#	#collide.setParent(thirdArm)
#	colLink1 = viz.link(avatar.getBone('Bip01 Spine'), collide, priority=0)
#	colLink2 = viz.link(thirdArm, collide, priority=1, mask=viz.LINK_ORI)
#	colLink1.preTrans([0, 0.3, 0.1], 0)
#	colLink2.postEuler([-90, 0, 0], 1)
#	collide.collideBox()
#	collide.alpha(0.5)

	thirdArm.collideBox()
	thirdArm.disable(viz.DYNAMICS)
	TouchCube.thirdArm = thirdArm
	
	# EXTENSION: Add third arm movement via intersense cube
	isense = viz.add('intersense.dle')
	isCube1 = isense.addTracker(port=4)
	isCube2 = isense.addTracker(port=5)
	
	# Link cubes
	pptextension.isCube1 = isCube1
	pptextension.isCube2 = isCube2
	
	# Setup thirdarm updating.
	vizact.onupdate(0, updateThirdArm)
Пример #26
0
global viewLink
viewLink = viz.link(navigationNode, viz.MainView)

global beltspeed
beltspeed = 1  #units must be meters/second

#hmrl = viz.addChild('HMRL8.osgb')
#hmrl.setPosition(0,0,0)
#hmrl.setEuler(90,270,0)
#hmrl.setScale(0.01,0.01,0.01)

#create optic flow
rt = {}
tlocs = {}
for x in range(1, 50, 1):
    rt["T{0}".format(x)] = vizshape.addBox(size=[0.1, 0.1, 0.1])
    rt["T{0}".format(x)].setPosition(0.462, 0, 2 * x)
    tlocs["T{0}".format(x)] = 2 * x
    rt["T{0}".format(x)].color(1, 1, 1)
#	rt["T{0}".format(x)].disable(viz.LIGHTING)

r2t = {}
t2locs = {}
for x in range(1, 50, 1):
    r2t["T{0}".format(x)] = vizshape.addBox(size=[0.1, 0.1, 0.1])
    r2t["T{0}".format(x)].setPosition(0.462, 3, 2 * x)
    t2locs["T{0}".format(x)] = 2 * x
    r2t["T{0}".format(x)].color(1, 1, 1)

r3t = {}
t3locs = {}
Пример #27
0
def view():
    yield room()
    doors = []
    D1 = random.choice([-4.25, -3.25, -2.25, -1.25])
    D2 = random.choice([4.75, 5.75, 6.75, 7.75])
    D3 = random.choice([13.75, 14.75, 15.75, 16.75])
    D4 = random.choice([22.75, 23.75, 24.75, 25.75])
    D5 = random.choice([31.75, 32.75, 33.75, 34.75])
    L_doors = []
    L_doors.append(D1)
    L_doors.append(D2)
    L_doors.append(D3)
    L_doors.append(D4)
    L_doors.append(D5)
    D7 = random.choice([-4.25, -3.25, -2.25, -1.25])
    D8 = random.choice([4.75, 5.75, 6.75, 7.75])
    D9 = random.choice([13.75, 14.75, 15.75, 16.75])
    D10 = random.choice([22.75, 23.75, 24.75, 25.75])
    D11 = random.choice([31.75, 32.75, 33.75, 34.75])
    R_doors = []
    R_doors.append(D7)
    R_doors.append(D8)
    R_doors.append(D9)
    R_doors.append(D10)
    R_doors.append(D11)
    people = []
    P1 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
    P2 = random.choice([9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
    P3 = random.choice(
        [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
    L_people = []
    L_people.append(P1)
    L_people.append(P2)
    L_people.append(P3)
    P4 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
    P5 = random.choice([9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
    P6 = random.choice(
        [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
    R_people = []
    R_people.append(P4)
    R_people.append(P5)
    R_people.append(P6)
    for z in np.asarray(L_doors):
        door = vizshape.addBox(size=[.04445, 2.13, .91])
        door.texture(wood)
        door.setPosition([-4.9733, 1.065, float(z)])
        doors.append(door)
        doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
        doorknob.color(viz.YELLOW)
        doorknob.setPosition(-4.9396, 1, (float(z) - .3364))
        doors.append(doorknob)
    for z in np.asarray(R_doors):
        door = vizshape.addBox(size=[.04445, 2.13, .91])
        door.texture(wood)
        door.setPosition([4.9683, 1.065, float(z)])
        doors.append(door)
        doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
        doorknob.color(viz.YELLOW)
        doorknob.setPosition(4.9396, 1, (float(z) - .3364))
        doors.append(doorknob)
    for z in np.asarray(L_people):
        object = random.choice([1, 2, 3])
        if object == 1:
            x = random.choice([0, 90, 180])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([-4.25, 0, float(z)])
            person.state(1)
            people.append(person)
        if object == 2:
            x = random.choice([0, 90, 180])
            person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
            person.setPosition([-4.25, 0, float(z)])
            person.state(1)
            people.append(person)
        if object == 3:
            x = random.choice([0, 90, 180])
            person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
            person.setPosition([-4.25, 0, float(z)])
            person.state(1)
            people.append(person)
    for z in np.asarray(R_people):
        object = random.choice([1, 2, 3])
        if object == 1:
            x = random.choice([0, 180, 270])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([4.5, 0, float(z)])
            person.state(1)
            people.append(person)
        if object == 2:
            x = random.choice([0, 180, 270])
            person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
            person.setPosition([4.5, 0, float(z)])
            person.state(1)
            people.append(person)
        if object == 3:
            x = random.choice([0, 180, 270])
            person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
            person.setPosition([4.5, 0, float(z)])
            person.state(1)
            people.append(person)
    en_env()
    tic = time.time()
    yield viztask.waitTime(10.5)
    toc = time.time()
    dis_env()
    print 'View length: ', (toc - tic)
    for door in np.asarray(doors):
        door.remove()
    for person in np.asarray(people):
        person.remove()
Пример #28
0
def startBoatIntro():
 global boatScene, ALL_GRABBED_EVENT, wheel, radius, wheelTimer, skipKey
# hideOceanScene()
# FADE_IN_TIME = 4
 globals_oa.user.setPosition([0,0,0])
# yield fader.fadeOutTask()
 yield fader.fadeInTask() #1.5
 yield viztask.waitTime(4) #4
 yield fader.fadeOutTask() #1.5
 yield crystalBallScene()
 yield cityScene()
 yield globals_oa.AUDIO_BOAT_AMBIENT_INTRO.play()
 yield fader.fadeInTask() #1.5
 yield viztask.waitTime(globals_oa.BETWEEN_FADING_TIME - 1) #4
 yield fader.fadeOutTask() #1.5
 yield viztask.waitTime(1)
 boatscene.unhideBoatAndIschia()
 yield fader.fadeInTask()
 
 # Next few blocks of code for making the steering wheel on the boat spin
 wheel = globals_oa.boat.getChild('steeringWheel')
 box = wheel.getBoundingBox()
 wheel.setCenter(box.center)
 radius = box.height / 2
 wheelTimer = vizact.ontimer(0.01, rotateWheel, radius)
 wheelManager = vizproximity.Manager()
 
 global rhandtar, lhandtar
 rhsphere = vizshape.addSphere(radius = 0.05) 
 rhsphere.setParent(globals_oa.rhModel)
 rhsphere.setPosition([0,0,.55])
 rhsphere.disable(viz.RENDERING)
 lhsphere = vizshape.addSphere(radius = 0.05) 
 lhsphere.setParent(globals_oa.lhModel)
 lhsphere.setPosition([0,0,.55])
 lhsphere.disable(viz.RENDERING)
 if globals_oa.rhModel is not None:rhandtar = vizproximity.Target(rhsphere)#globals_oa.rhModel)
 if globals_oa.lhModel is not None:lhandtar = vizproximity.Target(lhsphere)#globals_oa.lhModel)
 wheelManager.addTarget(rhandtar)
 wheelManager.addTarget(lhandtar)
 
 wheelSource = vizshape.addBox([box.width - 2, box.height, box.depth - 2])
 wheelSource.setPosition([box.center[0] - 3.65, box.center[1], box.center[2] + 0.83])
 wheelSource.visible(False)
 wheelSensor = vizproximity.addBoundingBoxSensor(wheelSource)
 wheelManager.addSensor(wheelSensor)
# wheelManager.setDebug(viz.ON)
 
 wheelManager.onEnter(wheelSensor, enterWheel)
 wheelManager.onExit(wheelSensor, exitWheel)
 
####new audio additions 
 yield viztask.waitAny([viztask.waitTime(globals_oa.INITIAL_WAIT_TIME), skipKey])
# yield globals_oa.BOAT_AUDIO_INTRO_1.play()
 playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_1)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_1), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.BOAT_AUDIO_INTRO_1.stop()
 else:
  yield viztask.waitAny([viztask.waitTime(2), skipKey])
### 
 loadDisabledZonesAndInitWorldvizCode()
 
 boatscene.Quad1()
# yield globals_oa.BOAT_AUDIO_INTRO_2.play()
 playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_2)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_2), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.BOAT_AUDIO_INTRO_2.stop()
 else:
  yield viztask.waitAny([viztask.waitTime(3), skipKey])
 boatscene.Quad2()
# yield globals_oa.BOAT_AUDIO_INTRO_3.play()
 playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_3)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_3), skipKey])
 if result.condition is skipKey:
  globals_oa.BOAT_AUDIO_INTRO_3.stop()
 else:
  yield viztask.waitAny([viztask.waitTime(3), skipKey])
 boatscene.Quad3()
# yield globals_oa.BOAT_AUDIO_INTRO_4.play()
 playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_4)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_4), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.BOAT_AUDIO_INTRO_4.stop()
 else:
  yield viztask.waitAny([viztask.waitTime(3), skipKey])
 yield globals_oa.CANVAS_QUAD.visible(False)
 globals_oa.CANVAS_QUAD_3_TEXTURE.remove()
 
 #grab on boat: start
 #init grab on boat
 initializeBoatGrabberAndPhysics()

# yield globals_oa.BOAT_AUDIO_INTRO_5.play() 
 playAudioAndSaveGlobalPointer(globals_oa.BOAT_AUDIO_INTRO_5)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_AUDIO_INTRO_5), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.BOAT_AUDIO_INTRO_5.stop()
 
 #adding a 1 min slot for grab testing on boat
 yield viztask.waitAny( [viztask.waitTime(1 * 60), viztask.waitEvent(ALL_GRABBED_EVENT), skipKey])

 #stop grabbing, now that you are going underwater!
 disableBoatGrabberAndPhysics()
 wheelTimer.setEnabled(0)
 #grab on boat: end
 
 yield fader.fadeOutTask()
 
 boatscene.hideScene()
 enableOceanScene()
 
 #hiding the tunnel boxes before diving underwater
 tunnelBox1 = globals_oa.terrainZone1.getChild('Box001')
 tunnelBox2 = globals_oa.terrainZone1.getChild('Box002')
 tunnelBox3 = globals_oa.terrainZone1.getChild('Box003')
 tunnelBox4 = globals_oa.terrainZone1.getChild('Box004')
 
 tunnelBox1.visible(False)
 tunnelBox2.visible(False)
 tunnelBox3.visible(False)
 tunnelBox4.visible(False)
 globals_oa.AUDIO_BOAT_AMBIENT_INTRO.stop()
# globals_oa.ZONE1_TRANSITION.play()
 playAudioAndSaveGlobalPointer(globals_oa.ZONE1_TRANSITION)
 globals_oa.AUDIO_BOAT_AMBIENT_SPLASH.play() 
 
# yield viztask.waitMediaEnd(globals_oa.AUDIO_BOAT_AMBIENT_SPLASH)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.ZONE1_TRANSITION), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.ZONE1_TRANSITION.stop()
 #viz.res.addPublishFile('data/speciesToFindZone1.txt')

 scavengerhunt.initialize(globals_oa.terrainZone1, globals_oa.filePathToSpeciesForScavengerHuntInZone1)
# transport_vhil.onKeyDown('g')
 viztask.schedule(swimFromZoneToZone())
 #the scheduling below is moved to swimFromZoneToZone
# viztask.schedule(startZone3Hunt())
 yield fader.fadeInTask()
# removeSphere()
# showOceanScene()
 globals_oa.AUDIO_ZONE1_AMBIENT.play()
 globals_oa.ZONE1_AUDIO_1.play()
Пример #29
0
import vizcam
import vizact
import __main__
import vizuniverse
import vizproximity
import viztracker2 as viztracker
import vizshape
import viz
import vizshape


import viz
import vizshape
viz.go()

#Create box with each face split into separate sub-node
box = vizshape.addBox([1,1,1],splitFaces=True,pos=(0,1.8,4))
box.addAction(vizact.spin(0,1,0,45))

#Create textures
t1 = viz.add('image1.jpg')
t2 = viz.add('image2.jpg')

#Apply first texture to front/back face
box.texture(t1,node='front')
box.texture(t1,node='back')

#Apply second texture to left/right face
box.texture(t2,node='left')
box.texture(t2,node='right')
Пример #30
0
 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)
Пример #31
0
def goCG():
	bgcolor = [0.15*1.2, 0.67*1.2, 0.95*1.2]
	viz.clearcolor(bgcolor)
	global skipKey, egg
	flagPile = globals_oa.terrainZone1.getChild('flagPile.OSGB', viz.CHILD_REPLACE_TRANSFORM)
	fishZone1 = schooling.initialize(1)
#	yield viztask.waitEvent(globals_oa.VIDEO_END_EVENT)
	
#	loadStuffAtStartAndHideThemALL()
	
	vizact.onsensorup(globals_oa.rhViveTracker, steamvr.BUTTON_TRIGGER, printRightHandPosition)
	vizact.onsensorup(globals_oa.lhViveTracker, steamvr.BUTTON_TRIGGER, printLeftHandPosition)
	
	globals_oa.terrainZone1.visible(viz.ON)
	globals_oa.ocean.visible(viz.ON)
#	schooling.hidePercentage(0)
#	schooling.chromis_chromis.hidePercentage(0)
#	schooling.diplodus_annularis.hidePercentage(0)
#	schooling.labrus_viridis.hidePercentage(0)
#	schooling.sarpa_salpa.hidePercentage(0)
	
#	schooling.show(fishZone1)
	
#	fog = vizfx.addFogEffect(colorRamp=viz.addTexture(globals_oa.MODEL_DIRECTORY + 'FogRamp.tif'), height=1, density=(.09))
#	fog = vizfx.addFogEffect(colorRamp=viz.addTexture(globals_oa.MODEL_DIRECTORY + 'FogRamp.tif'), height=1, density=(10))
#	vizfx.getComposer().addEffect(fog)
#	viz.MainScene.enable(viz.FOG, op=viz.OP_ROOT)
	
	viz.fogcolor(viz.AZURE)
	viz.fog(0.025)
	
#	worldvizcode.initVFXforDC(globals_oa.terrainZone1) # should moved into loadAndHide?
	worldvizcode.startEffects(globals_oa.terrainZone1) #not needed?
	
	#positioning the user on the terrain
#	offsetting the user on the terrain
	y_offset = -1.5
	userPos = globals_oa.user.getPosition(viz.ABS_GLOBAL)
	globals_oa.user.setPosition([userPos[0], y_offset, userPos[2]])
	
#####** Healthy CG zone fades in**
#	terrain1Child = globals_oa.terrainZone1.getChild('Terrain_Zone009')
#	posToMoveUserTo = terrain1Child.getBoundingBox().center
#	print "posToMoveUserTo = " + str(posToMoveUserTo)
	
	if globals_oa.fader is None: globals_oa.fader = View_Fader.addFader(fadeTime=5)
	globals_oa.fader.fadeIn()

#####	#This is a healthy reef, where carbon dioxide has not yet altered seawater chemistry. 
	#
#####	#When scientists measure the health and biodiversity of a reef, they perform something called a species count. 
#####	#Today, you will be counting the number of sea snails on this part of the reef. Look at your right hand
	#
	globals_oa.TRANSITION_TO_CG.play()
	yield viztask.waitAny([viztask.waitTime(10), skipKey])
	globals_oa.CG_SCENE1_1.play()
#	getAllChildrenZone1 = viz.MainScene.getChildren(all=True)
	def fadeAllZone1():
		globals_oa.terrainZone1.alpha(0)
		globals_oa.terrainZone1.visible(viz.ON)
		worldvizcode.stopEffects()
		viz.fog(0)
		fadeInZone1 = vizact.fadeTo(1, time=2)
		yield globals_oa.terrainZone1.addAction(fadeInZone1)
#		for child in getAllChildrenZone1: 
#			child.addAction(fadeInZone1)
			
	yield viztask.waitAny([viztask.waitTime(17), skipKey])	
#	globals_oa.CG_SCENE1_1.stop()
	
	#*participant sees 3D model of sea snail rotating like a hologram*
#	if globals_oa.rhViveTracker is not None:
#	vizact.ontimer2(0.004, 25, scavengerhunt.vibrateHandController, 2)
#	leftHandVibrateTimer.setEnabled(True)
#	rightHandVibrateTimer.setEnabled(True)
	
	
	rotatingSnail.visible(viz.ON)
	snailLink = None
	vizact.ontimer2(.004, 50, vibrateRightHand)
	if globals_oa.rhViveTracker is not None:
		snailLink = viz.link(globals_oa.rhViveTracker, rotatingSnail)
		snailLink.setOffset([0.0, y_offset, 0.0])
		snailLink.preTrans([0.01,-0.03,-0.13])
		snailLink.preEuler([0,0,180])

	
	yield viztask.waitTime(11)
	

#####	#*hologram disappears, species count begins*
	if snailLink is not None: snailLink.remove()
	rotatingSnail.visible(viz.OFF)
	rotatingSnail.remove()

##### flashing the flag pile ######
	egg.visible(viz.ON)
	flashOn = vizact.fadeTo(1, time=1, interpolate=vizact.easeInOut)
	flashOff = vizact.fadeTo(0, time=1, interpolate=vizact.easeInOut)
	flashSequence = vizact.sequence(flashOn, flashOff, 5)
	egg.add(flashSequence)
	
	
	yield viztask.waitTime(11)

	globals_oa.CG_SCENE1_2.play()
	print "playing CG_SCENE1_2 now"
#	yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.CG_SCENE1_2), skipKey])
	yield viztask.waitAny([viztask.waitTime(17), skipKey])
#	scavengerhunt.initialize(globals_oa.terrainZone1, globals_oa.filePathToSpeciesForScavengerHuntInZone1)
#	scavengerhunt.hideBasketAndStuffAttachedToIt()
	print "waiting for the species hunt end event, or for a timer to run out"
#	yield viztask.waitAny([viztask.waitEvent(scavengerhunt.ZONE1_OVER_EVENT), viztask.waitTime(60), skipKey])
	yield viztask.waitAny([viztask.waitTime(35), skipKey])
	print "species hunt is over"
#	leftHandVibrateTimer.setEnabled(False)
#	rightHandVibrateTimer.setEnabled(False)
#	scavengerhunt.endScavengerHunt()
#	yield viztask.waitEvent(scavengerhunt.ZONE1_OVER_EVENT)
#	scavengerhunt.disableGrabber()

	#waiting for the audio to end
	print "waiting for the narration to end"
	yield viztask.waitAny([viztask.waitTime(5), skipKey])

	#healthy zone fading out
#	print "fading out from zone-1 begin"
#	globals_oa.fader.fadeOutTask()
	globals_oa.fader.fadeOut()
#	print "fading out from zone-1 complete"
	
	yield viztask.waitAny([viztask.waitTime(5), skipKey])
	
#####	#**Unhealthy CG zone fades in**
#	globals_oa.terrainZone1.disable(viz.RENDERING)
	globals_oa.terrainZone1.visible(viz.OFF)
	if globals_oa.lhModelFlag is not None: globals_oa.lhModelFlag.visible(viz.OFF)
	if globals_oa.rhModelFlag is not None: globals_oa.rhModelFlag.visible(viz.OFF)
	schooling.hide(fishZone1)
	
#	userPos = globals_oa.user.getPosition()
#	globals_oa.user.setPosition(userPos[0] + globals_oa.zone3_X_offset, userPos[1], userPos[2])
#	globals_oa.user.setPosition(userPos[0], userPos[1], userPos[2])
#	globals_oa.basket.setPosition(globals_oa.basketPosInCGscene3)
#	globals_oa.terrainZone3.setPosition(-60.73, 0.0, 0.0)
#	scavengerhunt.hideBasketAndStuffAttachedToIt()
	
	globals_oa.terrainZone3.visible(viz.ON)
#	worldvizcode.stopEffects()
	worldvizcode.startEffects(globals_oa.terrainZone3)

#	schooling.show(fishZone2)	

#	print "fading into zone-3 begin"
#	globals_oa.fader.fadeInTask()
	globals_oa.fader.fadeIn()
#	print "fading into zone-3 complete"

#####	Observe the changes that have occurred as acidity has increased. Reach out and touch one of the streams of bubbles rising from the sea floor
	globals_oa.CG_SCENE2_1.play()
	print "playing CG_SCENE2_1 now"
#	yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.CG_SCENE2_1), skipKey])

#adding proximity handling for touching the bubbles
	global bubbleVibratorManager
	bubbleVibratorManager = vizproximity.Manager()
	
#	bubbleVibratorManager.setDebug(viz.ON)
	vizact.onkeydown('b', bubbleVibratorManager.setDebug, viz.TOGGLE)

	#adding bounding box sensors around the bubbles
	updateVibrationSensors()
#	vizact.onkeydown('u',updateVibrationSensors)

	#adding boxes around the hands as targets
	global rhandtar, lhandtar
#	rhsphere = vizshape.addSphere(radius = 0.07) 
	rhsphere = vizshape.addBox(size=(0.1,0.1,0.3))
	rhsphere.setParent(globals_oa.rightHand)
	rhsphere.setPosition([0,0,-0.15])
	rhsphere.disable(viz.RENDERING)
#	lhsphere = vizshape.addSphere(radius = 0.07) 
	lhsphere = vizshape.addBox(size=(0.1,0.1,0.3))
	lhsphere.setParent(globals_oa.leftHand)
	lhsphere.setPosition([0,0,-0.15])
	lhsphere.disable(viz.RENDERING)
#	if globals_oa.rhModel is not None:
	rhandtar = vizproximity.Target(rhsphere)#globals_oa.rhModel)
#	if globals_oa.lhModel is not None:
	lhandtar = vizproximity.Target(lhsphere)#globals_oa.lhModel)
	
	bubbleVibratorManager.addTarget(rhandtar)
	bubbleVibratorManager.addTarget(lhandtar)

	bubbleVibratorManager.onEnter(None, vibrateHandInBubbles)
	bubbleVibratorManager.onExit(None, stopVibrationOfHandInBubbles)
	
	print "*********************************** SENSORS ADDED FOR VIBRATING BUBBLES ***********************************"

	yield viztask.waitAny([viztask.waitTime(globals_oa.CG_SCENE2_1.getDuration()), skipKey])
	
#####	**wait until participant touches a stream of bubbles**
#####	** repeat last sentence until they do so**


#####The vents here in Ischia are releasing carbon dioxide, which is making the water more acidic. 
#####You study this part of the reef to predict how human carbon dioxide emissions will affect 
#####our world’s oceans and the species that live within them. 
#####Look at your right hand.
	globals_oa.CG_SCENE2_2.play()
	print "playing CG_SCENE2_2 now"
	
	yield viztask.waitAny([viztask.waitTime(16), skipKey])
	
	if globals_oa.rhViveTracker is not None:
		corrodedRotatingSnail.visible(viz.ON)
		vizact.ontimer2(.004, 50, vibrateRightHand)
		print '***********linking cooroded snail'
		snailLink = viz.link(globals_oa.rhViveTracker, corrodedRotatingSnail)
		snailLink.setOffset([0.0, y_offset, 0.0])
		snailLink.preTrans([0.01, -0.03, -0.13])
		snailLink.preEuler([0, 0, 180])
		snailLink.setMask(viz.LINK_POS)
		spinForever = vizact.spin(0,1,0, 90, dur = viz.FOREVER)
		corrodedRotatingSnail.runAction(spinForever)
	yield viztask.waitTime(10)
	corrodedRotatingSnail.visible(viz.OFF)
	
	yield viztask.waitAny([viztask.waitTime(40), skipKey])
	if bubbleVibratorManager is not None:
		bubbleVibratorManager.clearSensors()
		bubbleVibratorManager.clearTargets()

	if rightHandVibrateTimer is not None: rightHandVibrateTimer.setEnabled(False)
	if leftHandVibrateTimer is not None: leftHandVibrateTimer.setEnabled(False)
	globals_oa.finalTransitionSound.play()
#	yield viztask.waitTime(1)
	bubbleStreams = globals_oa.terrainZone3.getChild('zone2_smaller.OSGB')
	bubbleStreams.setAnimationSpeed(0.1)
	globals_oa.UNDERWATER_AMBIENT.stop()
	yield viztask.waitTime(3)
	globals_oa.FINAL_SCENE.play()
	yield viztask.waitAny([viztask.waitTime(10), skipKey])
	fadeInSphere = vizact.fadeTo(0, time=2)
	fadeOutSphere = vizact.fadeTo(1, time=2)
	def fadingFadeThing():
		yield viztask.waitTime(1)
		globals_oa.fadingSphere.addAction(fadeOutSphere)
		yield viztask.waitActionEnd(globals_oa.fadingSphere, fadeOutSphere)
		globals_oa.terrainZone3.visible(viz.OFF)
		globals_oa.ocean.visible(viz.OFF)
#		globals_oa.terrainZone1.visible(viz.ON)
		globals_oa.globeScene.enable(viz.RENDERING)
		globals_oa.user.setPosition(0.0,-0.05,0.0)
		viz.fogcolor(viz.BLACK)
		viz.fog(0.2)
		viz.clearcolor(viz.BLACK)
		globals_oa.fader.fadeOutTask()
		globals_oa.fader.fadeInTask()
#		yield viztask.waitTime(2)
		yield globals_oa.fadingSphere.addAction(fadeInSphere)
	viztask.schedule(fadingFadeThing)
	globals_oa.fader.fadeOutTask()
global targettol
targettol = 0.02

global circleL #slow leg circle marker
circleL = vizshape.addSphere(0.01,50,50,color=viz.GREEN)
circleL.setPosition(-0.03,targetL,0)
circleL.disable(viz.LIGHTING)#no shading, we don't want depth perception here

global circleR #slow leg circle marker
circleR = vizshape.addSphere(0.01,50,50)
circleR.color(1,0.7,0)
circleR.setPosition(0.04,targetR,0)
circleR.disable(viz.LIGHTING)#no shading, we don't want depth perception here

global highlightr
highlightr = vizshape.addBox(size=[0.25,0.0175,0.001])
highlightr.color(0,0,1)
highlightr.setPosition(0.145,targetmean,0)
highlightr.disable(viz.LIGHTING)

global highlightl
highlightl = vizshape.addBox(size=[0.25,0.0175,0.001])
highlightl.color(0,0,1)
highlightl.setPosition(-0.135,targetmean,0)
highlightl.disable(viz.LIGHTING)

#setup order of highlights
short = -0.2*targetmean
long = 0.2*targetmean
med = 0
global frodo
Пример #33
0
import viz
from vhil_devkit import *
import keyboardcontrol

vhilGo()
keyboardcontrol.control(MainView)

ball = viz.add('ball.wrl')
ball.setPosition([0,1.82,5])
box = ball.getBoundingBox()
boxSize = box.size

print str(boxSize)
print 'center:',box.center

import vizshape
#sphere = vizshape.addSphere(1, flipFaces=True)
prism = vizshape.addBox(size=boxSize, flipFaces=True)
prism.setPosition(box.center)

#import vizproximity
#sensor = vizproximity.addBoundingBoxSensor(ball)
grass3.setPosition(0, -0.01, 50)

#create a divider line
global divider
divider = vizshape.addQuad(size=(0.01, walkdistance * 50),
                           axis=-vizshape.AXIS_Y,
                           cullFace=False,
                           cornerRadius=0)
divider.setPosition(0, 0.001, (walkdistance * 50) / 2)
divider.color(255, 255, 255)

#make the Right targets
rt = {}
for x in range(1, int((walkdistance * 50) / (targetSL * 2)), 1):
    #	rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
    rt["T{0}".format(x)] = vizshape.addBox(size=[0.25, 0.02, 2 * targettol])
    rt["T{0}".format(x)].setPosition(0.2, 0.011, x * 2 * targetSL)
    rt["T{0}".format(x)].color(0, 0, 0)

lt = {}
for x in range(1, int((walkdistance * 50) / (targetSL * 2)), 1):
    #	rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
    lt["T{0}".format(x)] = vizshape.addBox(size=[0.25, 0.02, 2 * targettol])
    lt["T{0}".format(x)].setPosition(-0.2, 0.011, targetSL + x * 2 * targetSL)
    lt["T{0}".format(x)].color(0, 0, 0)

#load avatar Mark
#global man
#man = viz.add('mark.cfg')
#rfoot = man.getBone('Bip01 R Foot')
#rfoot.lock()
#declare the total number of steps to attempt each target
global STEPNUM
STEPNUM =50

global hmd
view = viz.addView
hmd = oculus.Rift()
hmd.getSensor
profile = hmd.getProfile()
hmd.setIPD(profile.ipd)

viz.MainView.setPosition(0, 0.1, -0.47)
viz.MainView.setEuler(0,0,0)

global sagt
sagt = vizshape.addBox(size=[0.04,0.02,0.01])
sagt.setPosition(0,0.1,0)
#sagt.color(0,0.7,1)
sagt.color(viz.GRAY)
sagt.disable(viz.LIGHTING)

global origin
#origin = vizshape.addSphere(0.01,20,20)
origin = viz.add('box3.obj',scale = [0.02,0.02,0.001],cache=viz.CACHE_NONE)
#origin.color(20,20,20)
origin.color(viz.GRAY)
origin.disable(viz.LIGHTING)
origin.setPosition(0,-0.01,0)

global latt
latt = vizshape.addBox(size=[0.02,0.04,0.01])
Пример #36
0
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)
manager.addTarget(target)


def writing(trialNo):
    record = open('PBpath_P' + subject_no + '_Trial_' + str(trialNo) +
                  time.strftime('_%Y-%m-%d_%H-%M-%S') + '.csv',
Пример #37
0
 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)
#declare the total number of steps to attempt each target
global STEPNUM
STEPNUM = 30

global hmd
view = viz.addView
hmd = oculus.Rift()
hmd.getSensor
profile = hmd.getProfile()
hmd.setIPD(profile.ipd)

viz.MainView.setPosition(0, 0.1, -0.47)
viz.MainView.setEuler(0, 0, 0)

global sagt
sagt = vizshape.addBox(size=[0.04, 0.02, 0.01])
sagt.setPosition(0, 0.1, 0)
#sagt.color(0,0.7,1)
sagt.color(viz.GRAY)
sagt.disable(viz.LIGHTING)

global origin
#origin = vizshape.addSphere(0.01,20,20)
origin = viz.add('box3.obj', scale=[0.02, 0.02, 0.001], cache=viz.CACHE_NONE)
#origin.color(20,20,20)
origin.color(viz.GRAY)
origin.disable(viz.LIGHTING)
origin.setPosition(0, -0.01, 0)

global latt
latt = vizshape.addBox(size=[0.02, 0.04, 0.01])
Пример #39
0
    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)
Пример #40
0
def swimFromZoneToZone():
 global SWIM_ZONE_TO_ZONE_COMPLETE_EVENT, LOOKED_OPENING_EVENT, lookingOpeningTimer, skipKey
 yield viztask.waitEvent(scavengerhunt.ZONE1_OVER_EVENT)
 scavengerhunt.disableGrabber()
 globals_oa.ZONE1_AUDIO_1.stop()
 globals_oa.basket.disable(viz.RENDERING)
 
 # Uncomment next block for immediately fading to zone 3 from zone 1; comment out lines 783 to 881 to skip swimming through the trench
# yield fader.fadeOutTask()
# for school in schooling.all_fish_schools:
#  school.hidePercentage(50)
# globals_oa.currentZoneNumber = 2
# transport_vhil.cycleZones()
# yield fader.fadeInTask()

 #get the child of the zone1 to hide
 stuffToHide1 = globals_oa.terrainZone1.getChild('RemoveThisWall')
 stuffToHide1.visible(False)

 playAudioAndSaveGlobalPointer(globals_oa.ZONE3_TRANSITION)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.ZONE3_TRANSITION), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.ZONE3_TRANSITION.stop()
 #playAudioAndSaveGlobalPointer(globals_oa.ZONE3_TRANSITION2)
 #yield viztask.waitMediaEnd(globals_oa.ZONE3_TRANSITION2)
 #markAudioPlayAsEnded()
 
 vizact.onkeydown('q', shootForward)
# viz.phys.disable()
 
 # Waits until the user has looked at the opening for 2 seconds before it starts swimming instructions
 viz.setCollectRenderStats(True)
 lookingOpeningTimer = vizact.ontimer(0.1, lookingAtOpening)
 yield viztask.waitAny([viztask.waitEvent(LOOKED_OPENING_EVENT), skipKey])

 
 #create proximity sensor for the swimming between zones
 swimBetweenZonesProximityManager = vizproximity.Manager()
# swimBetweenZonesProximityManager.setDebug(viz.ON)
 
 swimBetweenZonesProximityTarget = vizproximity.Target(viz.MainView)
 swimBetweenZonesProximityManager.addTarget(swimBetweenZonesProximityTarget)
 
 #create a box to act as the end of tunnel sensor, for zone-to-zone swimming
 endOfTunnelBox = vizshape.addBox(size = [3.0, 3.0, 3.0])
 endOfTunnelBox.setPosition(globals_oa.CURRENT_ABS_POS_OF_END_OF_ZONE_TO_ZONE_TUNNEL)
 endOfTunnelBox.visible(False)
 zone3Sensor = vizproximity.addBoundingBoxSensor(endOfTunnelBox)
 swimBetweenZonesProximityManager.addSensor(zone3Sensor)
 
 swimBetweenZonesProximityManager.onEnter(zone3Sensor, EnterZone3Proximity)
 
 #create a sensor around the tube through the tunnel
 tunnelBox1 = globals_oa.terrainZone1.getChild('Box001')
 tunnelBox2 = globals_oa.terrainZone1.getChild('Box002')
 tunnelBox3 = globals_oa.terrainZone1.getChild('Box003')
 tunnelBox4 = globals_oa.terrainZone1.getChild('Box004')
 
 tunnelBox1.visible(False)
 tunnelBox2.visible(False)
 tunnelBox3.visible(False)
 tunnelBox4.visible(False)

 tunnelBoxSensor1 = vizproximity.addBoundingBoxSensor(tunnelBox1)
 tunnelBoxSensor2 = vizproximity.addBoundingBoxSensor(tunnelBox2)
 tunnelBoxSensor3 = vizproximity.addBoundingBoxSensor(tunnelBox3)
 tunnelBoxSensor4 = vizproximity.addBoundingBoxSensor(tunnelBox4)
 
 boundingBox = stuffToHide1.getBoundingBox()
 trackerLink = viz.link(stuffToHide1, viz.NullLinkable)
 tunnelOpeningSensor = vizproximity.Sensor(vizproximity.Box([boundingBox.width * 0.6, boundingBox.height * 0.3, boundingBox.depth * 1.2], 
 [boundingBox.center[0] + 2.2, boundingBox.center[1], boundingBox.center[2] + 2]), trackerLink)
 
 swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor1)
 swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor2)
 swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor3)
 swimBetweenZonesProximityManager.addSensor(tunnelBoxSensor4)
 swimBetweenZonesProximityManager.addSensor(tunnelOpeningSensor)
 swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor1, EnterTunnelTube)
 swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor2, EnterTunnelTube)
 swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor3, EnterTunnelTube)
 swimBetweenZonesProximityManager.onEnter(tunnelBoxSensor4, EnterTunnelTube)
 swimBetweenZonesProximityManager.onEnter(tunnelOpeningSensor, EnterTunnelOpening)
 swimBetweenZonesProximityManager.onExit(tunnelBoxSensor1, ExitTunnelTube)
 swimBetweenZonesProximityManager.onExit(tunnelBoxSensor2, ExitTunnelTube)
 swimBetweenZonesProximityManager.onExit(tunnelBoxSensor3, ExitTunnelTube)
 swimBetweenZonesProximityManager.onExit(tunnelBoxSensor4, ExitTunnelTube)
 swimBetweenZonesProximityManager.onExit(tunnelOpeningSensor, ExitTunnelOpening)
 
 #turning on swimming
 transport_vhil.onKeyDown('g')
 
 playAudioAndSaveGlobalPointer(globals_oa.SWIMMING_INSTRUCTIONS)
 viztask.schedule(swimTutorial)
 viztask.schedule(removeGhostHands)
 result = yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.SWIMMING_INSTRUCTIONS), skipKey])
 markAudioPlayAsEnded()
 if result.condition is skipKey:
  globals_oa.SWIMMING_INSTRUCTIONS.stop()
 
# print "waiting for swimming to end"
 yield viztask.waitAny([viztask.waitEvent(SWIM_ZONE_TO_ZONE_COMPLETE_EVENT), skipKey])
 viztask.schedule(startZone3Hunt())
Пример #41
0
#def printViewPointPos():
#	print "viz.MainView.getPosition() = " + str(viz.MainView.getPosition())
#
#vizact.ontimer(1, printViewPointPos)

#ground = viz.add('tut_ground.wrl')
#ground.setPosition( 0, 1, 0 )
#Create a plane along the x and z axis intersecting the y axis at 1
#ground.collidePlane( 0, 1, 0, 1 )

#print "globals_oa.terrain1Floor.getPosition() = " + str(globals_oa.terrain1Floor.getPosition())
#oceanFloorPlane = vizshape.addPlane(size = [globals_oa.OCEAN_COLLISION_BOX_SIDE, globals_oa.OCEAN_COLLISION_BOX_SIDE], axis = vizshape.AXIS_Y, cullFace = False)
#oceanFloorPlane = vizshape.addBox(size = [globals_oa.OCEAN_COLLISION_BOX_SIDE, 1.0, globals_oa.OCEAN_COLLISION_BOX_SIDE])
#oceanFloorPlane = vizshape.addBox(size = [globals_oa.OCEAN_COLLISION_BOX_LENGTH, 1.0, globals_oa.OCEAN_COLLISION_BOX_WIDTH])
oceanFloorPlane = vizshape.addBox(size = [globals_oa.UNDERWATER_ROCK_LENGTH, globals_oa.UNDERWATER_ROCK_HEIGHT, globals_oa.UNDERWATER_ROCK_BREADTH])
oceanFloorPlane.color(0.0, 0.0, 1.0)
#oceanFloorPlane.visible(False)
#oceanFloorPlane.alpha(0.4)
#oceanFloorPlane.setPosition(30.0, -2.0, 0.0)
#oceanFloorPlane.setPosition(globals_oa.OCEAN_FLOOR_PLANE_POS)
oceanFloorPlane.setPosition(globals_oa.UNDERWATER_ROCK_POSITION)
#oceanFloorPlane.setPosition(globals_oa.OCEAN_SURFACE_PLANE_POS)
#oceanFloorPlane.setAxisAngle(globals_oa.OCEAN_FLOOR_PLANE_AXIS_ANGLE)
#oceanFloorPlane.setAxisAngle(globals_oa.UNDERWATER_ROCK_AXIS_ANGLE)
#oceanFloorPlane.setAxisAngle(globals_oa.OCEAN_SURFACE_PLANE_AXIS_ANGLE)
#oceanFloorPlane.setEuler(30.0, 0.0, 0.0)

def onKeyDown(key):
	global oceanFloorPlane
#	shift = 0.1
Пример #42
0
def Block3():
    datafile.write('\n')
    datafile.write('Block3')
    global dum3
    if dum == 2.5 and dum2 == 3.5:
        dum3 = 38
    if dum == 2.5 and dum2 == 38:
        dum3 = 3.5
    if dum == 3.5 and dum2 == 2.5:
        dum3 = 38
    if dum == 3.5 and dum2 == 38:
        dum3 = 2.5
    if dum == 38 and dum2 == 2.5:
        dum3 = 3.5
    if dum == 38 and dum2 == 3.5:
        dum3 = 2.5
    targets = [
        4.8, 6.2, 7.6, 9, 10.4, 11.8, 13.2, 14.6, 17.4, 20.2, 23, 25.8, 30,
        float(dum3),
        float(dum3)
    ]
    while len(targets) > 0:
        global k
        k = 0
        yield viztask.waitTime(.5)
        ready_text = viz.addText3D('Get ready!', pos=[-2, 1.7, 20])
        ready_text.color(0, 0, 0)
        yield viztask.waitTime(1)
        ready_text.remove()
        yield viztask.waitTime(2)
        yield room()
        doors = []
        D1 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D2 = random.choice([4.75, 5.75, 6.75, 7.75])
        D3 = random.choice([13.75, 14.75, 15.75, 16.75])
        D4 = random.choice([22.75, 23.75, 24.75, 25.75])
        D5 = random.choice([31.75, 32.75, 33.75, 34.75])
        L_doors = []
        L_doors.append(D1)
        L_doors.append(D2)
        L_doors.append(D3)
        L_doors.append(D4)
        L_doors.append(D5)
        D7 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D8 = random.choice([4.75, 5.75, 6.75, 7.75])
        D9 = random.choice([13.75, 14.75, 15.75, 16.75])
        D10 = random.choice([22.75, 23.75, 24.75, 25.75])
        D11 = random.choice([31.75, 32.75, 33.75, 34.75])
        R_doors = []
        R_doors.append(D7)
        R_doors.append(D8)
        R_doors.append(D9)
        R_doors.append(D10)
        R_doors.append(D11)
        people = []
        P1 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
        P2 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P3 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        L_people = []
        L_people.append(P1)
        L_people.append(P2)
        L_people.append(P3)
        P4 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
        P5 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P6 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        R_people = []
        R_people.append(P4)
        R_people.append(P5)
        R_people.append(P6)
        targ = random.choice(targets)
        if targ == 2.5:
            size = .051006
        if targ == 3.5:
            size = .071409
        if targ == 4.8:
            size = .097932
        if targ == 6.2:
            size = .126495
        if targ == 7.6:
            size = .155059
        if targ == 9:
            size = .183622
        if targ == 10.4:
            size = .212186
        if targ == 11.8:
            size = .240749
        if targ == 13.2:
            size = .269313
        if targ == 14.6:
            size = .297876
        if targ == 17.4:
            size = .355003
        if targ == 20.2:
            size = .41213
        if targ == 23:
            size = .469257
        if targ == 25.8:
            size = .526384
        if targ == 30:
            size = .612075
        if targ == 38:
            size = .775295
        print targ
        datafile.write('\n')
        datafile.write('%f' % (targ))
        sphere = vizshape.addSphere((size), 20, 20)
        sphere.color(1.02, .444, 0)
        sphere.setPosition([0, (size), (targ)])
        shadow = vizshape.addCircle((size), 20)
        shadow.color([.05, .05, .05])
        shadow.setEuler([0, 90, 0])
        shadow.setPosition([0, .001, (targ)])
        for z in np.asarray(L_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([-4.9733, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(-4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(R_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([4.9683, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(L_people):
            object = random.choice([1, 2, 3])
            if object == 1:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_female.cfg',
                                       euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 2:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 3:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
        for z in np.asarray(R_people):
            object = random.choice([1, 2, 3])
            if object == 1:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_female.cfg',
                                       euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 2:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 3:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
        targets.remove(targ)
        en_env()
        tic = time.time()
        yield viztask.waitTime(5.5)  #Actually is closer to 5 seconds
        toc = time.time()
        mask.enable(viz.RENDERING)
        dis_env()
        sphere.remove()
        shadow.remove()
        for door in np.asarray(doors):
            door.remove()
        for person in np.asarray(people):
            person.remove()
        yield viztask.waitTime(1)
        mask.disable(viz.RENDERING)
        print toc - tic
        datafile.write(' %f' % (toc - tic))
        viz.callback(viz.KEYDOWN_EVENT, KeyEvents)
        yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
        if k == 1:
            targets.append(targ)
            datafile.write(' targ missed')
Пример #43
0
#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)
end_box=(vizshape.addBox([.06,.06,.06],right=True,left=True,top=True,bottom=True, front=True,back=True, splitFaces=False, color=viz.RED))
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)
#CHANGE: changed start_box's dimensions to max_size from .06 did the same w/ the start_sensor
table= vizshape.addBox([50,.775,50],right=True,left=True,top=True,bottom=True, front=True,back=True, splitFaces=False, color= viz.PURPLE)
start_node= vizshape.addBox([.00001, .000001, .0000001],right=True,left=True,top=True,bottom=True, front=True,back=True, splitFaces=False, color=viz.BLUE)
if x>0:
	left_plane1= vizshape.addBox([control_array[0],.00001,control_array[0]],right=True,left=True,top=True,bottom=True, front=True,back=True, splitFaces=False, color= viz.GREEN)
	left_plane1.setPosition(-x_translate1,y_height1,z_depth1)
	right_plane1= vizshape.addBox([control_array[0],.00001,control_array[0]],right=True,left=True,top=True,bottom=True, front=True,back=True, splitFaces=False, color= viz.GREEN)
Пример #44
0
    def addTrench(self):
        trench = viz.addGroup()

        leftWall = vizshape.addBox(size=[200, 200, 20000])
        rightWall = vizshape.addBox(size=[200, 200, 20000])
        floor = vizshape.addBox(size=[200, 2, 20000])
        ceiling = vizshape.addBox(size=[200, 2, 20000])

        m = viz.Matrix()
        m.postTrans(-200, 50, 2500)
        leftWall.setMatrix(m)

        m = viz.Matrix()
        m.postTrans(200, 50, 2500)
        rightWall.setMatrix(m)

        m = viz.Matrix()
        m.postTrans(0, -50, 2500)
        floor.setMatrix(m)

        m = viz.Matrix()
        m.postTrans(0, 125, 2000)
        ceiling.setMatrix(m)

        trenchTex = viz.addTexture('trench2.jpg')
        leftWall.texture(trenchTex)
        rightWall.texture(trenchTex)
        floor.texture(trenchTex)

        ceiling.visible(viz.OFF)

        leftWall.setParent(trench)
        rightWall.setParent(trench)
        floor.setParent(trench)
        ceiling.setParent(trench)

        obs1 = vizshape.addBox(size=[400, 175, 50])
        obs1.setPosition(0, 60, 650)
        obs1.texture(trenchTex)
        obs1.setParent(trench)

        obs2 = vizshape.addBox(size=[250, 150, 50])
        obs2.setPosition(-60, 0, 750)
        obs2.texture(trenchTex)
        obs2.setParent(trench)

        obs3 = vizshape.addBox(size=[400, 125, 50])
        obs3.setPosition(0, -60, 950)
        obs3.texture(trenchTex)
        obs3.setParent(trench)

        obs4_1 = vizshape.addBox(size=[400, 100, 50])
        obs4_1.setPosition(0, 100, 1100)
        obs4_1.texture(trenchTex)
        obs4_1.setParent(trench)

        obs4_2 = vizshape.addBox(size=[400, 75, 50])
        obs4_2.setPosition(0, -10, 1100)
        obs4_2.texture(trenchTex)
        obs4_2.setParent(trench)

        obs5_1 = vizshape.addBox(size=[75, 200, 1000])
        obs5_1.setPosition(50, 0, 2000)
        obs5_1.texture(trenchTex)
        obs5_1.setParent(trench)

        obs5_2 = vizshape.addBox(size=[75, 200, 1000])
        obs5_2.setPosition(-50, 0, 2000)
        obs5_2.texture(trenchTex)
        obs5_2.setParent(trench)

        obs6_1 = vizshape.addBox(size=[400, 100, 1000])
        obs6_1.setPosition(0, 100, 3000)
        obs6_1.texture(trenchTex)
        obs6_1.setParent(trench)

        obs6_2 = vizshape.addBox(size=[400, 50, 1000])
        obs6_2.setPosition(0, -10, 3000)
        obs6_2.texture(trenchTex)
        obs6_2.setParent(trench)

        obs7_1 = vizshape.addBox(size=[75, 200, 1000])
        obs7_1.setPosition(50, 0, 4000)
        obs7_1.texture(trenchTex)
        obs7_1.setParent(trench)

        obs7_2 = vizshape.addBox(size=[75, 200, 1000])
        obs7_2.setPosition(-50, 0, 4000)
        obs7_2.texture(trenchTex)
        obs7_2.setParent(trench)

        obs8_1 = vizshape.addBox(size=[400, 100, 1000])
        obs8_1.setPosition(0, 100, 5000)
        obs8_1.texture(trenchTex)
        obs8_1.setParent(trench)

        obs8_2 = vizshape.addBox(size=[400, 50, 1000])
        obs8_2.setPosition(0, -10, 5000)
        obs8_2.texture(trenchTex)
        obs8_2.setParent(trench)

        obs9 = vizshape.addBox(size=[200, 200, 1000])
        obs9.setPosition(-50, 0, 6000)
        obs9.texture(trenchTex)
        obs9.setParent(trench)

        obs10 = vizshape.addBox(size=[200, 200, 1000])
        obs10.setPosition(0, 100, 7000)
        obs10.texture(trenchTex)
        obs10.setParent(trench)

        obs11 = vizshape.addBox(size=[200, 200, 1000])
        obs11.setPosition(50, 0, 8000)
        obs11.texture(trenchTex)
        obs11.setParent(trench)

        obs12_1 = vizshape.addBox(size=[200, 200, 1000])
        obs12_1.setPosition(0, -100, 9000)
        obs12_1.texture(trenchTex)
        obs12_1.setParent(trench)

        obs12_2 = vizshape.addBox(size=[200, 100, 1000])
        obs12_2.setPosition(0, 100, 9000)
        obs12_2.texture(trenchTex)
        obs12_2.setParent(trench)

        obs13_1 = vizshape.addBox(size=[200, 200, 1000])
        obs13_1.setPosition(0, -100, 10000)
        obs13_1.texture(trenchTex)
        obs13_1.setParent(trench)

        obs13_2 = vizshape.addBox(size=[150, 100, 1000])
        obs13_2.setPosition(50, 50, 10000)
        obs13_2.texture(trenchTex)
        obs13_2.setParent(trench)

        obs13_1 = vizshape.addBox(size=[200, 200, 1000])
        obs13_1.setPosition(0, -100, 11000)
        obs13_1.texture(trenchTex)
        obs13_1.setParent(trench)

        obs13_2 = vizshape.addBox(size=[150, 100, 1000])
        obs13_2.setPosition(60, 50, 11000)
        obs13_2.texture(trenchTex)
        obs13_2.setParent(trench)

        obs13_3 = vizshape.addBox(size=[200, 100, 1000])
        obs13_3.setPosition(0, 100, 11000)
        obs13_3.texture(trenchTex)
        obs13_3.setParent(trench)

        return trench
Пример #45
0
	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)
mylight.intensity(0.5)

# disable headlight
headLight = viz.MainView.getHeadLight()
headLight.disable()

# environment #

x = [0, -5, 0, 5]
z = [5, 0, -5, 0]
rot = [0, 90, 0, 90]
for n in range(4):
    wall = vizshape.addBox(size=(10.0, 3.0, 1.0),
                           right=True,
                           left=True,
                           top=True,
                           bottom=True,
                           front=True,
                           back=True,
                           splitFaces=False)
    wall.setEuler(rot[n], 0, 0)
    wall.setPosition(x[n], 1.5, z[n])
    wall.color(0.85, 0.85, 0.85)

roof = vizshape.addBox(size=(10.0, 1.0, 10.0),
                       right=True,
                       left=True,
                       top=True,
                       bottom=True,
                       front=True,
                       back=True,
                       splitFaces=False)

#create a divider line
global divider
divider = vizshape.addQuad(size=(0.01,walkdistance*50),
	axis=-vizshape.AXIS_Y,
	cullFace=False,
	cornerRadius=0)
divider.setPosition(0,0.001,(walkdistance*50)/2)
divider.color(255,255,255)

#make the Right targets
rt = {}
for x in range(1,int((walkdistance*50)/(targetSL*2)),1):
#	rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
	rt["T{0}".format(x)]=vizshape.addBox(size=[0.25,0.02,2*targettol])
	rt["T{0}".format(x)].setPosition(0.2,0.011,x*2*targetSL)
	rt["T{0}".format(x)].color(0,0,0)
	
lt = {}
for x in range(1,int((walkdistance*50)/(targetSL*2)),1):
#	rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
	lt["T{0}".format(x)]=vizshape.addBox(size=[0.25,0.02,2*targettol])
	lt["T{0}".format(x)].setPosition(-0.2,0.011,targetSL+x*2*targetSL)
	lt["T{0}".format(x)].color(0,0,0)
	
#load avatar Mark
global man
#man = viz.add('mark.cfg')
man = viz.add('vcc_male.cfg')
man.disable(viz.LIGHTING)
Пример #48
0
def validation():
	'''
	Show same calibration points and compare calulated gaze point to ground truth. 
	(Displays both + angular error)
	'''
	
	# ask for the sub port
	req.send_string('SUB_PORT')
	sub_port = req.recv_string()

	# open a sub port to listen to pupil
	sub = ctx.socket(zmq.SUB)
	sub.connect("tcp://{}:{}".format(addr, sub_port))
	sub.setsockopt_string(zmq.SUBSCRIBE, u'gaze')

	# add gaze marker
	m_gaze = vizshape.addSphere(radius=sphere_size, color=viz.GREEN)
	m_gaze.disable(viz.INTERSECTION)
	if not gaze_marker_visible:
		m_gaze.disable(viz.RENDER) # invisible but phyisically present



	def get_gaze(eye_number):
		'''
		checks gaze stream for confident measures of the eye (eye_number) until it finds them
		Args:    eye_number (int): 1=left, 0=right
		Returns: [x, y] (float): normalized x and y values range [0,1]
		'''
		found_confident_val = False
		
		while found_confident_val == False:

			topic = sub.recv_string() # unused
			msg = sub.recv()
			msg = loads(msg, encoding='utf-8')
			
			confidence = msg['confidence']
			
			if msg['id'] == eye_number:
				
				if confidence > confidence_level:
				
					found_confident_val = True
					
					t = msg['timestamp'] # unused
					npx = msg['norm_pos'][0]
					npy = msg['norm_pos'][1]
					
					return [npx, npy]


	def updateGaze():	
		'''
		calls 'get_gaze function' and takes the average of two
		eyes for the normal values - they will be used to project a 
		sphere on where subjects look at
		'''
		
		# get gaze data
		norm_pos_x = np.mean([get_gaze(1)[0], get_gaze(0)[0]])
		norm_pos_y = np.mean([get_gaze(1)[1], get_gaze(0)[1]])
				
		# find the intersection and project sphere
		line = viz.MainWindow.screenToWorld([norm_pos_x, norm_pos_y])
		intersection = viz.intersect(line.begin, line.end)
		m_gaze.setPosition(intersection.point)
		
	# update cursor location on every sample		
	vizact.onupdate(viz.PRIORITY_LINKS+1, updateGaze)


	dot_norm_pos=[]
	gaze_norm_pos=[]
	ang_error = []


	yield showMessage('Zum Starten der Validierung die Leertaste drücken')
	
	for p in norm_positions:
		
		print('calibration point: ', p)
	
		norm_x = p[0]
		norm_y = p[1]
		
		first_run = True
		
		if first_run:
			
			first_run = False
		
			'''set up a plane 'right in front of user' on which we want to project the dots'''
	
			# target the current center of view
			p_line = viz.MainWindow.screenToWorld(.5, .5)
		
			# let's modify the line and call it line 2. Here we let the line end at the "depth" value
			p_line_2 = viz.Line(begin=p_line.begin, end=p_line.end, dir=p_line.dir, length=depth)
						
			# Add the plane and apply the matrix of our viewpoint to the plane
			plane = vizshape.addBox(size=[3.6, 2, .1])
			mymat = viz.MainView.getMatrix()
			plane.setMatrix(mymat)
			
			# Reposition the plane to the end of line 2
			plane.setPosition(p_line_2.end)
			plane.color([.25,.25,.25])
			plane.alpha(.95)
			
			# Lock it to user
			plane_link = viz.grab(viz.MainView, plane)
		
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([norm_x, norm_y])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		
		# place a dot (at depth level of line) 
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		
		# lock dot to user
		view_link = viz.grab(viz.MainView, dot)
		
		print('ready')
		viz.playSound('beep500_200.wav')
		yield viztask.waitKeyDown(' ')
				
		for s in range(60):
			
			# get the current pupil time (pupil uses CLOCK_MONOTONIC with adjustable timebase).
			# You can set the pupil timebase to another clock and use that.
			t = get_pupil_timestamp()

			dot_norm_pos.append(p)
			gaze_norm_pos.append(viz.MainWindow.worldToScreen(m_gaze.getPosition()))

			yield viztask.waitTime(1/60.)
			print(t)
		
		dot.color(viz.RED)
		
		print('waiting for next position...')
		
		yield viztask.waitKeyDown(' ')
		
		yield dot.remove()
				
	time.sleep(2)
		
	showMessage('validation done!')
	
	for p in norm_positions:
		
		i = norm_positions.index(p)
		chunk = range(i*60, (i+1)*60)
		print(i)
		dmx = np.mean([gaze_norm_pos[x][0] for x in chunk])
		dmy = np.mean([gaze_norm_pos[y][1] for y in chunk])
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([p[0], p[1]])
		line_v = viz.MainWindow.screenToWorld([dmx, dmy])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		intersection_v = viz.intersect(line_v.begin, line_v.end)
		
		# place a dots (at depth level of line) for both ground truth and gaze point
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		dot.color(viz.BLUE)
		
		dot_v = vizshape.addSphere(radius=sphere_size*0.75)
		dot_v.setPosition(intersection_v.point)
		dot_v.color(viz.YELLOW_ORANGE)
		
		# lock dots to user
		view_link = viz.grab(viz.MainView, dot)
		viel_link2 = viz.grab(viz.MainView, dot_v)
		
		# calculate angular error
		error = vizmat.AngleBetweenVector(line.dir, line_v.dir)
#		cosangle = np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b))
#		angle = np.arccos(cosangle)
#		error = np.degrees(angle)
		
		ang_error.append(error)
		
		print('angle is: ', error, 'for ', p)

	
	showMessage('mean angular error is: {}'.format(np.mean(ang_error)))
	
	print('mean angular error is: ', np.mean(ang_error), ' deg/ visual angle')
global targettol
targettol = 0.02

global circleL  #slow leg circle marker
circleL = vizshape.addSphere(0.01, 50, 50, color=viz.GREEN)
circleL.setPosition(-0.03, targetL, 0)
circleL.disable(viz.LIGHTING)  #no shading, we don't want depth perception here

global circleR  #slow leg circle marker
circleR = vizshape.addSphere(0.01, 50, 50)
circleR.color(1, 0.7, 0)
circleR.setPosition(0.04, targetR, 0)
circleR.disable(viz.LIGHTING)  #no shading, we don't want depth perception here

global highlightr
highlightr = vizshape.addBox(size=[0.25, 0.0175, 0.001])
highlightr.color(0, 0, 1)
highlightr.setPosition(0.145, targetmean, 0)
highlightr.disable(viz.LIGHTING)

global highlightl
highlightl = vizshape.addBox(size=[0.25, 0.0175, 0.001])
highlightl.color(0, 0, 1)
highlightl.setPosition(-0.135, targetmean, 0)
highlightl.disable(viz.LIGHTING)

#setup order of highlights
short = -0.06
long = 0.06
med = 0
global frodo