Exemplo n.º 1
0
    def getMatrices(self, eye):
        def lookat(ex, ey, ez, tx, ty, tz, ux, uy, uz):
            e = np.array([ex, ey, ez])
            t = np.array([tx, ty, tz])
            u = np.array([ux, uy, uz])
            return matrix.lookat(e, t, u)

        stereoMode = 0
        if eye:
            stereoMode = self.stereoMode

        aspect = float(max(1, G.windowWidth)) / float(max(1, G.windowHeight))

        if stereoMode == 0:
            # No stereo
            if self.projection:
                proj = matrix.perspective(self.fovAngle, aspect,
                                          self.nearPlane, self.farPlane)
            else:
                height = self.scale
                width = self.scale * aspect
                proj = matrix.ortho(-width, width, -height, height,
                                    self.nearPlane, self.farPlane)

            mv = lookat(
                self.eyeX,
                self.eyeY,
                self.eyeZ,  # Eye
                self.focusX,
                self.focusY,
                self.focusZ,  # Focus
                self.upX,
                self.upY,
                self.upZ)  # Up
        elif stereoMode == 1:
            # Toe-in method, uses different eye positions, same focus point and projection
            proj = matrix.perspective(self.fovAngle, aspect, self.nearPlane,
                                      self.farPlane)

            if eye == 1:
                mv = lookat(
                    self.eyeX - 0.5 * self.eyeSeparation,
                    self.eyeY,
                    self.eyeZ,  # Eye
                    self.focusX,
                    self.focusY,
                    self.focusZ,  # Focus
                    self.upX,
                    self.upY,
                    self.upZ)  # Up
            elif eye == 2:
                mv = lookat(
                    self.eyeX + 0.5 * self.eyeSeparation,
                    self.eyeY,
                    self.eyeZ,  # Eye
                    self.focusX,
                    self.focusY,
                    self.focusZ,  # Focus
                    self.upX,
                    self.upY,
                    self.upZ)  # Up
        elif stereoMode == 2:
            # Off-axis method, uses different eye positions, focus points and projections
            widthdiv2 = math.tan(
                math.radians(self.fovAngle) / 2) * self.nearPlane
            left = -aspect * widthdiv2
            right = aspect * widthdiv2
            top = widthdiv2
            bottom = -widthdiv2

            if eye == 1:  # Left
                eyePosition = -0.5 * self.eyeSeparation
            elif eye == 2:  # Right
                eyePosition = 0.5 * self.eyeSeparation
            else:
                eyePosition = 0.0

            left -= eyePosition * self.nearPlane / self.eyeZ
            right -= eyePosition * self.nearPlane / self.eyeZ

            # Left frustum is moved right, right frustum moved left
            proj = matrix.frustum(left, right, bottom, top, self.nearPlane,
                                  self.farPlane)

            # Left camera is moved left, right camera moved right
            mv = lookat(
                self.eyeX + eyePosition,
                self.eyeY,
                self.eyeZ,  # Eye
                self.focusX + eyePosition,
                self.focusY,
                self.focusZ,  # Focus
                self.upX,
                self.upY,
                self.upZ)  # Up

        return proj, mv
Exemplo n.º 2
0
    def getMatrices(self, eye):
        def lookat(ex, ey, ez, tx, ty, tz, ux, uy, uz):
            e = np.array([ex, ey, ez])
            t = np.array([tx, ty, tz])
            u = np.array([ux, uy, uz])
            return matrix.lookat(e, t, u)

        stereoMode = 0
        if eye:
            stereoMode = self.stereoMode

        aspect = float(max(1, G.windowWidth)) / float(max(1, G.windowHeight))

        if stereoMode == 0:
            # No stereo
            if self.projection:
                proj = matrix.perspective(self.fovAngle, aspect, self.nearPlane, self.farPlane)
            else:
                height = self.scale
                width = self.scale * aspect
                proj = matrix.ortho(-width, width, -height, height, self.nearPlane, self.farPlane)

            mv = lookat(
                self.eyeX,
                self.eyeY,
                self.eyeZ,  # Eye
                self.focusX,
                self.focusY,
                self.focusZ,  # Focus
                self.upX,
                self.upY,
                self.upZ,
            )  # Up
        elif stereoMode == 1:
            # Toe-in method, uses different eye positions, same focus point and projection
            proj = matrix.perspective(self.fovAngle, aspect, self.nearPlane, self.farPlane)

            if eye == 1:
                mv = lookat(
                    self.eyeX - 0.5 * self.eyeSeparation,
                    self.eyeY,
                    self.eyeZ,  # Eye
                    self.focusX,
                    self.focusY,
                    self.focusZ,  # Focus
                    self.upX,
                    self.upY,
                    self.upZ,
                )  # Up
            elif eye == 2:
                mv = lookat(
                    self.eyeX + 0.5 * self.eyeSeparation,
                    self.eyeY,
                    self.eyeZ,  # Eye
                    self.focusX,
                    self.focusY,
                    self.focusZ,  # Focus
                    self.upX,
                    self.upY,
                    self.upZ,
                )  # Up
        elif stereoMode == 2:
            # Off-axis method, uses different eye positions, focus points and projections
            widthdiv2 = math.tan(math.radians(self.fovAngle) / 2) * self.nearPlane
            left = -aspect * widthdiv2
            right = aspect * widthdiv2
            top = widthdiv2
            bottom = -widthdiv2

            if eye == 1:  # Left
                eyePosition = -0.5 * self.eyeSeparation
            elif eye == 2:  # Right
                eyePosition = 0.5 * self.eyeSeparation
            else:
                eyePosition = 0.0

            left -= eyePosition * self.nearPlane / self.eyeZ
            right -= eyePosition * self.nearPlane / self.eyeZ

            # Left frustum is moved right, right frustum moved left
            proj = matrix.frustum(left, right, bottom, top, self.nearPlane, self.farPlane)

            # Left camera is moved left, right camera moved right
            mv = lookat(
                self.eyeX + eyePosition,
                self.eyeY,
                self.eyeZ,  # Eye
                self.focusX + eyePosition,
                self.focusY,
                self.focusZ,  # Focus
                self.upX,
                self.upY,
                self.upZ,
            )  # Up

        return proj, mv