Example #1
0
    def getMatrices(self, eye=None):
        # Ignores eye parameter

        #proj, _ = super(OrbitalCamera, self).getMatrices(eye)
        #mv = ..

        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)

        aspect = self.getAspect()

        if self.projection:
            # Perspective mode
            proj = matrix.perspective(self.fovAngle, aspect, self.nearPlane, self.farPlane)
        else:
            # Ortho mode
            height = self.getScale()
            width = height * aspect
            # Camera position around world origin
            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 point (target)
                    self.upX, self.upY, self.upZ)          # Up
        """

        mv = lookat(self.center[0], self.center[1], self.center[2] + self.radius,       # Eye
                    self.center[0], self.center[1], self.center[2], # Focus point (target)
                    self.upX, self.upY, self.upZ)          # Up

        return proj, mv
Example #2
0
    def getMatrices(self, eye=None):
        # Ignores eye parameter

        #proj, _ = super(OrbitalCamera, self).getMatrices(eye)
        #mv = ..

        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)

        aspect = self.getAspect()

        if self.projection:
            # Perspective mode
            proj = matrix.perspective(self.fovAngle, aspect, self.nearPlane, self.farPlane)
        else:
            # Ortho mode
            height = self.getScale()
            width = height * aspect
            # Camera position around world origin
            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 point (target)
                    self.upX, self.upY, self.upZ)          # Up
        """

        mv = lookat(self.center[0], self.center[1], self.center[2] + self.radius,       # Eye
                    self.center[0], self.center[1], self.center[2], # Focus point (target)
                    self.upX, self.upY, self.upZ)          # Up

        return proj, mv
Example #3
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
Example #4
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