Class ViewUtil


  • public class ViewUtil
    extends java.lang.Object
    • Constructor Detail

      • ViewUtil

        public ViewUtil()
    • Method Detail

      • createHeadingAnimator

        public static AngleAnimator createHeadingAnimator​(View view,
                                                          Angle begin,
                                                          Angle end)
        Create an animator to animate heading.
        Parameters:
        view - View to animate
        begin - starting heading
        end - final heading
        Returns:
        An Animator to animate heading.
      • createPitchAnimator

        public static AngleAnimator createPitchAnimator​(View view,
                                                        Angle begin,
                                                        Angle end)
        Create an animator to animate pitch.
        Parameters:
        view - View to animate
        begin - starting pitch
        end - final pitch
        Returns:
        An Animator to animate pitch.
      • createRollAnimator

        public static AngleAnimator createRollAnimator​(View view,
                                                       Angle begin,
                                                       Angle end)
        Create an animator to animate roll.
        Parameters:
        view - View to animate
        begin - starting roll
        end - final roll
        Returns:
        An Animator to animate roll.
      • createHeadingPitchRollAnimator

        public static CompoundAnimator createHeadingPitchRollAnimator​(View view,
                                                                      Angle beginHeading,
                                                                      Angle endHeading,
                                                                      Angle beginPitch,
                                                                      Angle endPitch,
                                                                      Angle beginRoll,
                                                                      Angle endRoll)
        Create an animator to animate heading, pitch, and roll.
        Parameters:
        view - View to animate
        beginHeading - staring heading
        endHeading - final heading
        beginPitch - starting pitch
        endPitch - final pitch
        beginRoll - starting roll
        endRoll - final roll
        Returns:
        A CompoundAnimator to animate heading, pitch, and roll.
      • subtract

        public static java.awt.Point subtract​(java.awt.Point a,
                                              java.awt.Point b)
      • computePositionTransform

        public static Matrix computePositionTransform​(Globe globe,
                                                      Position center)
      • computeModelViewMatrix

        public static Matrix computeModelViewMatrix​(Globe globe,
                                                    Vec4 eyePoint,
                                                    Vec4 centerPoint,
                                                    Vec4 up)
      • getUpVector

        public static Vec4 getUpVector​(Globe globe,
                                       Vec4 lookAtPoint)
      • computeHeading

        public static Angle computeHeading​(Matrix headingPitchZoomTransform)
      • computePitch

        public static Angle computePitch​(Matrix transform)
      • computeRoll

        public static Angle computeRoll​(Matrix transform)
      • validateViewState

        public static boolean validateViewState​(ViewUtil.ViewState viewState)
      • normalizedEyePosition

        public static Position normalizedEyePosition​(Position unnormalizedPosition)
      • normalizedHeading

        public static Angle normalizedHeading​(Angle unnormalizedHeading)
      • normalizedPitch

        public static Angle normalizedPitch​(Angle unnormalizedPitch)
      • normalizedRoll

        public static Angle normalizedRoll​(Angle unnormalizedRoll)
      • computeRayFromScreenPoint

        public static Line computeRayFromScreenPoint​(View view,
                                                     double x,
                                                     double y,
                                                     Matrix modelview,
                                                     Matrix projection,
                                                     java.awt.Rectangle viewport)
      • computePixelSizeAtDistance

        public static double computePixelSizeAtDistance​(double distance,
                                                        Angle fieldOfView,
                                                        java.awt.Rectangle viewport)
      • computeHorizonDistance

        public static double computeHorizonDistance​(Globe globe,
                                                    double elevation)
      • computeVerticalFieldOfView

        public static Angle computeVerticalFieldOfView​(Angle horizontalFieldOfView,
                                                       java.awt.Rectangle viewport)
        Computes a View's vertical field-of-view given a View's horizontal field-of-view and the viewport window dimensions.
        Parameters:
        horizontalFieldOfView - the angle between the view frustum's left and right clipping planes.
        viewport - the viewport dimensions, in window coordinates (screen pixels).
        Returns:
        the angle between the view frustum's bottom and top clipping planes.
        Throws:
        java.lang.IllegalArgumentException - if the horitontal-field-of-view is null, or if the viewport rectangle is null.
      • computeElevationAboveSurface

        public static double computeElevationAboveSurface​(DrawContext dc,
                                                          Position position)
      • computePerspectiveNearDistance

        public static double computePerspectiveNearDistance​(Angle fieldOfView,
                                                            double distanceToObject)
        Computes the maximum near clip distance for a perspective projection that avoids clipping an object at a given distance from the eye point. The given distance should specify the smallest distance between the eye and the object being viewed, but may be an approximation if an exact clip distance is not required.
        Parameters:
        fieldOfView - The viewport rectangle, in OpenGL screen coordinates.
        distanceToObject - The distance from the perspective eye point to the nearest object, in model coordinates.
        Returns:
        The maximum near clip distance, in model coordinates.
        Throws:
        java.lang.IllegalArgumentException - if the field of view is null, or if the distance is negative.
      • computePerspectiveNearDistance

        public static double computePerspectiveNearDistance​(double farDistance,
                                                            double farResolution,
                                                            int depthBits)
        Computes the near clip distance that corresponds to a specified far clip distance and a resolution at the far clip distance. This returns zero if either the distance or the resolution are zero.
        Parameters:
        farDistance - The far clip distance, in model coordinates.
        farResolution - The depth resolution at the far clip plane, in model coordinates.
        depthBits - The number of bitplanes in the depth buffer. This is typically 16, 24, or 32 for OpenGL depth buffers.
        Returns:
        The near clip distance, in model coordinates.
        Throws:
        java.lang.IllegalArgumentException - if either the distance or the resolution are negative, or if the depthBits is less than one.
      • project

        public static Vec4 project​(Vec4 modelPoint,
                                   Matrix modelview,
                                   Matrix projection,
                                   java.awt.Rectangle viewport)
        Transforms a point in model coordinates to a point in screen coordinates. The returned x and y coordinates are relative to the screen's lower left hand screen corner, and the returned z coordinate defines the point's depth in screen coordinates (in the range [0, 1]). This returns null if the specified combination of modelview matrix, projection matrix, and viewport cannot produce a transformation.
        Parameters:
        modelPoint - the point in model coordinates to transform into window coordinates.
        modelview - the modelview matrix.
        projection - the projection matrix.
        viewport - the viewport rectangle.
        Returns:
        the point in window coordinates, or null if the point cannot be transformed.
        Throws:
        java.lang.IllegalArgumentException - if any of the model point, modelview matrix, projection matrix, or viewport rectangle are null.
      • unProject

        public static Vec4 unProject​(Vec4 windowPoint,
                                     Matrix modelview,
                                     Matrix projection,
                                     java.awt.Rectangle viewport)
        Transforms a point in screen coordinates to a point in model coordinates. The input x and y are relative to the screen's lower left hand screen corner, while the z-value denotes the point's depth in screen coordinates (in the range [0, 1]). This returns null if the specified combination of modelview matrix, projection matrix, and viewport cannot produce a transformation.
        Parameters:
        windowPoint - the point in screen coordinates to transform into model coordinates.
        modelview - the modelview matrix.
        projection - the projection matrix.
        viewport - the viewport rectangle.
        Returns:
        the point in model coordinates, or null if the point cannot be transformed.
        Throws:
        java.lang.IllegalArgumentException - if any of the model point, modelview matrix, projection matrix, or viewport rectangle are null.