Announcement

Collapse
No announcement yet.

Position of Center of Screen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Position of Center of Screen

    Hey, in my program I need to display the coordinates of the center of the screen.. But I can't seem to get a hold of that. The closest I can get so far is:
    Code:
    Position position = worldWindow.getCurrentPosition();
    But that gives me a position in the middle, but near the bottom of the window, not the center. I'm new with World Wind but have been messing with this for hours.. Any help?

  • #2
    Position position = worldWindow.getView().getEyePosition();

    this is the position you are looking for.
    Torbjörn Härje
    Swedish Defence Research Agency (FOI)
    Linköping, Sweden

    Comment


    • #3
      Should note that the eyeposition is out in space looking down on earth. but you get the right coordinates in lat long.
      Torbjörn Härje
      Swedish Defence Research Agency (FOI)
      Linköping, Sweden

      Comment


      • #4
        Not quite.

        Code:
        worldWindow.getView().getEyePosition()
        isn't quite what I need. This gives me the position of the eye looking down on the globe. Not the center of the position it's looking at.. Does that make sense? Like that's where I'm looking from. I'm using a USB Controller to move the view around, but using that the coordinates never change because the eye is moving, just where it's looking is changing.

        Comment


        • #5
          My bad. I totally replied without logging in... Haha. But yeah as I was saying, worldWindow.getView().getEyePosition() gives me the position of the eye in the sky. I need the position of where the eye is actually looking at. I'm using a USB Controller to change the view, but the eye stays in the same place, just looks around. Does that make sense?

          Comment


          • #6
            Finally figured it out. In case anyone else runs into this problem, here's what worked for me:
            Code:
            Vec4 tempVec4 = worldWindow.getView().getCenterPoint();
            Position position = worldWindow.getView().getGlobe().computePositionFromPoint(tempVec4);
            This gave me a position with the actual center of the screen.

            Comment


            • #7
              I tried this code:

              Vec4 tempVec4 = wwd.getView().getCenterPoint(); gov.nasa.worldwind.geom.Position centerPosition = wwd.getView().getGlobe().computePosition FromPoint(tempVec4); and this:
              basicOrbitView.getCenterPosition();
              But when we have the map tilted and with vertical exaggeration the position is incorrect. It not take the vertical exaggeration in account.

              Can someone help me?

              Comment


              • #8
                If you need to account for the terrain, I would approach it this way:

                Code:
                Vec4 screenPoint = wwd.getView().getForwardVector();
                // Beware, computation of the ray will fail when the screen points x and y equal 0
                Line ray = wwd.getView().computeRayFromScreenPoint(screenPoint.getX(), screenPoint.getY());
                Intersection[] intersections = wwd.getSceneController().getTerrain().intersect(ray);
                if (intersections != null && intersections.length > 0) {
                      Vec4 point = intersections[0].getIntersectionPoint(); // There is a getIntersectionPosition, but it isn't implemented!
                      Position position = wwd.getModel().getGlobe().computePositionFromPoint(point);
                      System.out.println(position);
                } else {
                      // No intersection with the terrain
                }
                Where wwd is the WorldWindow object. This method calculates the intersection of a ray from the eye point through your desired screenPoint (in your case the center point) with the terrain. It then converts the cartesian to geographic coordinates.

                The view.getCenterPoint does something very similar, but calculates the intersection with the ellipsoidal globe, not the terrain. Keep in mind the elevation values in this approach are sensitive to terrain exaggeration. To remove this sensitivity, you would need to request the elevation with terrain intersection coordinates:

                Code:
                wwd.getModel().getGlobe().getElevation(position.getLatitude(), position.getLongitude());
                Remember terrain loads dynamically in World Wind, so even if you are not moving the globe, if the terrain gets updated from the server, your position/altitude may change.

                Zach
                Zach
                World Wind Team
                https://github.com/NASAWorldWind

                Comment

                Working...
                X