def addMirror(mirror,mat=None,eye=viz.BOTH_EYE):

#If mirror matrix is not specifed, get matrix of mirror object
	if mat is None:
		mat = mirror.getMatrix()

        #Position of mirror
        pos = viz.Vector(mat.getPosition())

        #Direction mirror is pointing
        dir = viz.Vector(mat.getForward())
        dir.normalize()

        #Quaternion rotation of mirror
        quat = mat.getQuat()

        #Create render texture
        tex = viz.addRenderTexture()

        #Create render node for rendering reflection
        lens = viz.addRenderNode(size=[512,512])
        lens.attachTexture(tex)
        lens.setInheritView(True,viz.POST_MULT)
        lens.disable(viz.CULL_FACE,op=viz.OP_OVERRIDE)
        lens.setCullMask(REFLECT_MASK)
        if eye == viz.LEFT_EYE:
            lens.disable(viz.RENDER_RIGHT)
            mirror.setMask(REFLECT_MASK|viz.RIGHT_MASK,mode=viz.MASK_REMOVE)
        elif eye == viz.RIGHT_EYE:
            lens.disable(viz.RENDER_LEFT)
            mirror.setMask(REFLECT_MASK|viz.LEFT_MASK,mode=viz.MASK_REMOVE)
        else:
            mirror.setMask(REFLECT_MASK,mode=viz.MASK_REMOVE)

        #Setup reflection matrix
        rot = viz.Matrix.quat(quat)
        invRot = rot.inverse()
        lens.setMatrix(viz.Matrix.translate(-pos)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))

        #Setup reflection clip plane
        s = viz.sign(viz.Vector(dir) * viz.Vector(pos))
        plane = vizmat.Plane(pos=pos,normal=dir)
        dist = plane.distance([0,0,0])
        lens.clipPlane([dir[0],dir[1],dir[2],s*dist-0.01])

        #Project reflection texture onto mirror
        mirror.texture(tex)
        mirror.texGen(viz.TEXGEN_PROJECT_EYE)
Ejemplo n.º 2
0
    def logSubjpos(self):

        # concat log file
        logFile = os.path.join(ct.PATH_TO_LOGFILE, self.subjPosLogFile)

        # create file if non existent
        if not os.path.exists(logFile):
            f = open(logFile, 'w')
        else:
            f = open(logFile, 'a')

        # get current time stamp
        cTstamp = viz.tick()

        # get current pos
        cSubjPos = viz.Vector(viz.MainView.getPosition())

        str2write = "%s %s " % (round(cSubjPos.x, 2), round(cSubjPos.z, 2))

        # add timestamp and new line string
        str2write = "%s " % round(cTstamp, 2) + str2write + '\n'

        # write to file
        f.write(str2write)
        f.close()
Ejemplo n.º 3
0
    def getLastGazeMatrix(self, eye=viz.BOTH_EYE):
        """Returns the last received gaze matrix in HMD coordinate system"""
        m = viz.Matrix()
        s = self.getLastSample()
        if s:
            if eye == viz.LEFT_EYE:
                s = s.leftEye
            elif eye == viz.RIGHT_EYE:
                s = s.rightEye

            xoff = SCREEN_DISTANCE * math.tan(math.radians(
                FIELD_OF_VIEW / 2.0))
            yoff = SCREEN_DISTANCE * math.tan(math.radians(
                FIELD_OF_VIEW / 2.0))
            zoff = SCREEN_DISTANCE

            gx = ((s.por_x * 2.0 * xoff) / SCREEN_HRES - xoff)
            gy = -((s.por_y * 2.0 * yoff) / SCREEN_VRES - yoff)
            gz = zoff

            m.makeVecRotVec([0, 0, 1], viz.Vector(gx, gy, gz, normalize=True))

            #print 'Time: ' + str(s.timestamp)
            #print 'Time: ' + str(viz.getFrameElapsed())
        return m
Ejemplo n.º 4
0
 def UpdateMovement():
     elapsed = viz.getFrameElapsed()
     trans = device.getRawTranslation()
     rx, ry, rz = device.getRawRotation()
     viz.MainView.setAxisAngle(
         [0, 1, 0, ry * elapsed * ROTATE_SCALE], viz.HEAD_ORI,
         viz.REL_LOCAL)
     viz.MainView.move(viz.Vector(trans) * elapsed * MOVE_SCALE)
Ejemplo n.º 5
0
    def __init__(self, tracker):

        # Initialize using group node
        group = viz.addGroup()
        viz.VizNode.__init__(self, group.id)

        self._offset = viz.Vector()
        self._tracker = tracker
        self._velocity = 0.0

        # Update tracker every frame
        self._updater = vizact.onupdate(0, self.update)
Ejemplo n.º 6
0
def ShootBall():
    #Hide marker
    marker.visible(viz.OFF)
    #Convert the current mouse position from screen coordinates to world coordinates
    line = viz.MainWindow.screenToWorld(viz.mouse.getPosition())
    #Create a vector that points along the line the mouse is at
    vector = viz.Vector(line.dir)
    #Set length of vector based on the amount of power charged up
    vector.setLength(vizmat.Interpolate(MIN_POWER, MAX_POWER, power.get()))
    #Move the next ball to be fired to the begin point
    b = nextBall.next()
    b.setPosition(line.begin)
    #Reset the ball, set its velocity vector, and enable it
    b.reset()
    b.setVelocity(vector)
    b.enable(viz.PHYSICS)
    #Reset the power
    power.set(0)