Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve position selected for camera in viewRectangle in 3D. #2764

Merged
merged 7 commits into from
Jun 4, 2015

Conversation

kring
Copy link
Member

@kring kring commented May 29, 2015

For Camera.viewRectangle in 3D, Cesium places the camera by selecting a position halfway along a Cartesian line between the southwest and northeast corners, and then computing its height. This works when extents are approximately rectangles, but it yields total garbage for rectangles where the top and bottom are at very different latitudes.

This change has the Camera instead select the position that is the average of the four corners of the extent. This isn't perfect (the perfect solution I guess would find the barycenter of the projection of the extent onto the globe) but it's drastically better.

For example, 90, -62, 174, -4 (WSEN) looks like this:

Before this change:
image

After this change:
image

@kring
Copy link
Member Author

kring commented May 29, 2015

CC TerriaJS/terriajs#696

@emackey emackey mentioned this pull request May 29, 2015
@pjcozzi
Copy link
Contributor

pjcozzi commented May 29, 2015

Thanks @kring. This sounds OK to me. @bagnell can you review and merge?

@mramato
Copy link
Contributor

mramato commented Jun 1, 2015

@bagnell you might want to look at this for 1.10, since it looks like a good small-impact change.

@bagnell
Copy link
Contributor

bagnell commented Jun 1, 2015

There's a failing test:
image

@kring
Copy link
Member Author

kring commented Jun 3, 2015

Good catch, Dan. My system (Ubuntu 15.04 / Chrome / NVidia Quadro 4000) has a number of test failures under normal circumstances so I missed this.

The problem is that my new code works very poorly when the east and west boundaries are coplanar (e.g. west: -180 degrees and east: 0 degrees). To correct this, I have a new version that uses EllipsoidGeodesic to find the midpoint latitude and then uses that latitude plus the average longitude (no geodesics here, just a simple average of the longitude values) as the center point.

In addition to avoiding problems with coplanar longitudes, this also yields a slightly better result for my test numbers above:

image

@kring
Copy link
Member Author

kring commented Jun 3, 2015

This turned out to be a lot more complicated than I expected, but I'm pretty happy with it now.

After calling viewExtent in 3D, it is now guaranteed that all four corners, the midpoints of the rectangle at the northern and southern boundaries, and the points on the eastern and western boundary that lie at zero latitude (if any) are all inside the view frustum (so they're visible, unless they're on the back side of the Earth). And the whole thing will be centered in the window.

It's still possible for part of the extent to be outside the view frustum when the side bulge out from the corners (the coordinates above will exhibit this behavior). I don't think it's easy to important to fix this.

The camera also now looks down the ellipsoid surface normal rather than toward the center of the Earth after viewing a rectangle.

One thing I noticed while working on this is that the DEFAULT_VIEW_RECTANGLE looks..umm..arbitrary:

image

So we may want to change it now that viewing big rectangles is more reliable.

Another weird thing I noticed is that Sandcastle and Cesium Viewer (at least) don't actually use the DEFAULT_VIEW_RECTANGLE. I'm not sure what that's about. The HomeButtonViewModel instead starts with that rectangle and then does a bunch of stuff to it for some reason.

@kring
Copy link
Member Author

kring commented Jun 3, 2015

I made another small change to this because I realized I was computing the camera position displacement along the geodetic surface normal, but then actually displacing it along the geocentric normal. Oops. This changes the camera position by a couple of pixels for big rectangles.

@bagnell
Copy link
Contributor

bagnell commented Jun 4, 2015

@kring This looks good to me. Is it ready to be merged or were there other changes you wanted to make?

@kring
Copy link
Member Author

kring commented Jun 4, 2015

It's ready as far as I'm concerned.

@bagnell
Copy link
Contributor

bagnell commented Jun 4, 2015

I updated CHANGES.md by moving what you added to the 1.11 section. Merging.

bagnell added a commit that referenced this pull request Jun 4, 2015
Improve position selected for camera in viewRectangle in 3D.
@bagnell bagnell merged commit f1b3aab into master Jun 4, 2015
@bagnell bagnell deleted the viewRectangle branch June 4, 2015 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants