Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Refactor Transform - #3497

Merged
1ec5 merged 7 commits into
masterfrom
1ec5-animation-options-2600
Jan 14, 2016
Merged

1ec5 merged 7 commits into
masterfrom
1ec5-animation-options-2600

Conversation

@1ec5

@1ec5 1ec5 commented Jan 11, 2016

Copy link
Copy Markdown
Contributor

This PR cleans up Transform considerably, making it easier to implement #2600 at this low level:

  • CameraOptions only describes the destination viewpoint now. AnimationOptions describes the transition to that destination viewpoint.
  • Eliminated many redundant methods on Transform.
  • Minimized usage of TransformState::x and TransformState::y.
  • Added convenience constructors for AnimationOptions. When scaling, passing in view’s origin as the anchor no longer anchors the scaling operation at the view’s center. To specify no anchor, use NaN instead of 0.
  • Corrected setBearing() to assume an origin at the upper-left corner of the view rather than the lower-left corner.
  • Added an anchor option to CameraOptions that pins a coordinate to a point within the view throughout a zoom, rotation, or tilt. This option is useful for ensuring that a pinch or rotation gesture is revolves around the gesture rather than the view’s center point. However, all the platform frontends currently use convenience methods for this purpose anyways.
  • Easing across the antimeridian now travels the short way around the globe (see Further refine flyTo() flight path #3355).

/cc @tmpsantos @zugaldia

@1ec5 1ec5 added refactor in progress ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Jan 11, 2016
@mappy-mobile

Copy link
Copy Markdown

Hi @1ec5,
I just saw this pull-request related to #2600. You said that it will make easier to implement insets with your work. So I was wondering if you will work on #2600 after this pull-request ? Otherwise can you give us some clues about how you think it should be implemented with your refactoring.
For the moment we pause our work on #2600 because it seems there will be a lot of conflicts once you will merge this pull-request.
Regards,
Larry

@1ec5

1ec5 commented Jan 11, 2016

Copy link
Copy Markdown
Contributor Author

Hi Larry, #2600 is definitely top of mind for me right now. I’m open to your ideas about where the insets should be implemented.

The refactoring in this PR is needed generally, but I wanted to make it possible to eventually implement the inset functionality down in Transform and/or TransformState, so that other platforms like Android can take advantage of them. I’m not sure yet whether the insets should be merely a camera option like around in GL JS (the least flexible approach), or an optional parameter like the anchor parameter in this PR, or an additional field in TransformState (the most complex but more comprehensive approach).

Do you think you could push what you have so far (even a gist with a high-level overview is fine), so we can hash out the details and avoid conflicts?

@lgeromegnace

Copy link
Copy Markdown

Yes sure we can push our work. It is not working fine with all interactions impacted by the insets. We still have issues to deal with.

As you suggested in your comment we also implement the inset functionality in Transform and TransformState.

The base idea is to add the insets on center(x,y) point in easeTo method.

To do so we must take into account the map's angle and pitch. Unfortunately we ended up with an issue with the pitch perspective.
Because of that we tried to modify the projection matrix in TransformState just before applying the rotation transformations by translating the center by the insets. The pitch was fine and the animation to center on the user position too. However this code broke the gestures excepting the pitching one by adding insets continuously.

Finally we tried to detect the "pitching gesture" by adding an API to state to be aware of it and applied in TransformState the inset to the matrix only if we are pitching. On the other side, in Transform we applied the inset only if we are not in a "gesture in progress" state. Still not good : the pitch case is not ok.

At this moment I cannot give you a clear vision on what should be done to fulfill the inset functionality but here are some leads we have in mind:

  • I think it could help to have more info in state such as "start panning". With this it will be possible to synchronize the state.x|y with the insets (previously applied on the proj matrix) at the beginning of the gesture only. Indeed, we could compute a delta between start and current position.
  • I see that the proj matrix is rebuilt each time. What about applying the transformations once ? Maybe you have constraints that lead you to this design ?

I prepare a pull-request with a "DO NOT MERGE" in the commit message if you want to have a look on what we tried so far.

@1ec5

1ec5 commented Jan 13, 2016

Copy link
Copy Markdown
Contributor Author

Wonderful! I followed up in #3523. For this PR, I’m going to finish cleaning Transform up, then insets will likely be in a separate PR.

@1ec5 1ec5 self-assigned this Jan 13, 2016
@jfirebaugh

Copy link
Copy Markdown
Contributor

This is looking great. 👍 💯

@1ec5
1ec5 force-pushed the 1ec5-animation-options-2600 branch from cb24a25 to e9ebd40 Compare January 14, 2016 07:20
1ec5 added 7 commits January 14, 2016 00:39
Eliminated many redundant methods on Transform. Minimized usage of TransformState::x and TransformState::y. Added convenient constructors for AnimationOptions. When scaling, passing in view’s origin as the anchor no longer anchors the scaling operation at the view’s center. To specify no anchor, use NaN.

Increased precision of worldSize(), now that it’s used much more heavily in transform methods.
All Transform methods that take a PrecisionPoint now assume a “flipped” origin at the upper-left corner of the view. Previously, some methods assumed an origin at the lower-left corner.
Cleaned up gesture recognizers, flipping the origins of anchor points only and always before calling mbgl methods. This exposed the fact that the cursor locking feature during drag-zoom/rotate/tilt was broken, so I fixed it to match MapKit behavior exactly and also account for modifier changes in mid-gesture.
Made anchor a CameraOption for easeTo().
Pushed much of easeTo() and flyTo() into startTransition() to avoid code duplication.
@1ec5
1ec5 force-pushed the 1ec5-animation-options-2600 branch from 21a3b43 to ff8b014 Compare January 14, 2016 08:43
@1ec5 1ec5 removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Jan 14, 2016
@1ec5 1ec5 changed the title [WIP] Refactor Transform Refactor Transform Jan 14, 2016
@1ec5
1ec5 merged commit ff8b014 into master Jan 14, 2016
@1ec5 1ec5 removed the in progress label Jan 14, 2016
@1ec5
1ec5 deleted the 1ec5-animation-options-2600 branch January 14, 2016 09:14
@tmpsantos

Copy link
Copy Markdown
Contributor

Fantastic!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants