示例#1
0
    def _generateViewport(self, fov, width, height, znear):
        """
        Generates a viewport from the dimensions.

        @param fov    The Field of View angle (in degrees).
        @param width  The screen width (in pixels).
        @param height The screen height (in pixels).
        @param znear  The z position of the near clipping plane.
        @returns      A tuple of (left, right, bottom, top) of the viewing frustrum at znear.
        """
        # Figure out the viewport rectangle that contains the conocircle along it's shortest
        # dimensions; maintain the ratio of the otherdimension.
        if width < height:
            znear_width  = conicwidth(fov, znear)
            znear_height = znear_width * height / width
        else:
            znear_height = conicwidth(fov, znear)
            znear_width  = znear_height * width / height

        # Center the viewport
        zleft   = - 0.5 * znear_width
        zright  =   0.5 * znear_width
        zbottom = - 0.5 * znear_height
        ztop    =   0.5 * znear_height

        return (zleft, zright, zbottom, ztop)
示例#2
0
    def dolly( self, delta ):
        """
        Executes a translate operation the z-axis.

        This is equivalent of moving the camera along the z-axis; to reflect the change in view the camera will be translated by the additive inverse of the delta.

        @param delta The translation delta (the change in distance along the direction vector)
        """
        # We need to calculation a ratio of pixels to world units for speed.
        # Get the direction vector (normalized) and the distance.
        direction = self._target - self._position
        distance  = direction.length()
        direction = direction.normalized()

        # Get the view width at the point along the z-axis and build a pixels to unit ratio
        viewwidth = conicwidth(self._fov, distance)
        factor = viewwidth / self._screenminsize

        # Calculate the translation along the direction vector
        translation = direction * (- delta * factor)

        # Move the Position only; the look at point reamins unchanged.
        self._position += translation

        self._updateProjectionMatrix()
示例#3
0
    def track( self, hdelta, vdelta ):
        """
        Executes a translate operation the x-y axis.

        This is equivalent of moving the scene along the x-y axis; to reflect the change in view the camera will be translated by the additive inverse of the deltas.

        @param hdelta The horizontal delta (the change in distance along the right vector)
        @param vdelta The vertical delta (the change in distance along the up vector)
        """
        # We need to calculation a ratio of pixels to world units for speed.
        # Get the direction vector (normalized) and the distance.
        direction = self._target - self._position
        distance  = direction.length()
        direction = direction.normalized()

        # Get the view width at the point along the z-axis and build a pixels to unit ratio
        viewwidth = conicwidth(self._fov, distance)
        factor = viewwidth / self._screenminsize

        # Update the right vector
        right = direction ^ self._up

        # Calcaulte the x-y axis translation vector
        translation = right * (- hdelta * factor) + self._up * (- vdelta * factor)

        # Move the Position and Target
        self._position += translation
        self._target += translation

        self._updateProjectionMatrix()