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

High-level fj-viewer interface #803

Merged
merged 9 commits into from Jul 12, 2022

Conversation

jeevcat
Copy link
Contributor

@jeevcat jeevcat commented Jul 12, 2022

See #764 (comment)

Open questions:

  1. Does it make sense to pass Actions from fj-window to fj-viewer and back again?
  2. fj-viewer now uses resolution-independent cursor positions everywhere (normalized to [-1, 1]). This means I had to change the magic number here to feel right. What was the meaning/units of this number? https://github.com/hannobraun/Fornjot/blob/edf7a6636d1d0323d7e56943c3fc96ab4cfd46a3/crates/fj-viewer/src/input/rotation.rs#L32
  3. I've introduced a small change in behavior of the "focus point" which might not be desirable. On left and right clicks a new focus point is chosen. There is no way to remove an old focus point, only replacing when clicking again. Zooming now uses the most recently created focus point, instead of the current cursor position. Is this fine, or should I reimplement the old behavior (Mouse down creates focus point, mouse up removes focus point, temporary focus point calculated for each zoom event)?

@hannobraun
Copy link
Owner

Thank you for the pull request, @jeevcat! I intend to take a look later today and will answer your questions then.

@hannobraun hannobraun marked this pull request as ready for review July 12, 2022 11:20
@hannobraun hannobraun self-requested a review as a code owner July 12, 2022 11:20
Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, @jeevcat! I definitely like where this is going. I've left a comment with a bit of a nitpick, but that isn't a blocker for merging.

The only thing I'm not so sure about is the new focus point behavior. See my answer below.

On to your questions.


Does it make sense to pass Actions from fj-window to fj-viewer and back again?

No, not really. In fact, I think Actions should no longer exist, as it is now redundant with input::Event. input::Handle::handle_event should receive a &mut DrawConfig instead.

fj-viewer now uses resolution-independent cursor positions everywhere (normalized to [-1, 1]). This means I had to change the magic number here to feel right. What was the meaning/units of this number?

It's just that: a number to make to make the input feel right. f probably stands for "factor", so no unit.

I think it would make sense to give it a real name, change it to a const, and add some documentation. But that doesn't need to be done here and now (but feel free to, if you want).

I've introduced a small change in behavior of the "focus point" which might not be desirable. On left and right clicks a new focus point is chosen. There is no way to remove an old focus point, only replacing when clicking again. Zooming now uses the most recently created focus point, instead of the current cursor position. Is this fine, or should I reimplement the old behavior (Mouse down creates focus point, mouse up removes focus point, temporary focus point calculated for each zoom event)?

My immediate reaction is that I don't like the new behavior, for the following reasons:

  • It's slightly more complicated, for no clear (to me) benefit.
  • It introduces state that is hidden from the user, which could lead to confusion.

But that is not a very strong opinion. What do you think, does my reasoning make sense?


I think this pull request is mostly ready to be merged! The only blocker is to decide whether to revert to the old focus point behavior or not.

Any other improvements can be done in follow-up PRs and don't need to hold up merging this one.

Comment on lines 8 to 22
/// Move the view up, down, left or right
Pan {
/// The normalized position of the cursor before input
previous: NormalizedPosition,
/// The normalized position of the cursor after input
current: NormalizedPosition,
},

/// The user scrolled
Scroll(MouseScrollDelta),
/// Rotate the view around the focus point
Orbit {
/// The normalized position of the cursor before input
previous: NormalizedPosition,
/// The normalized position of the cursor after input
current: NormalizedPosition,
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metaphor that Fornjot's UI follows, is that you manipulate the model, not an abstract camera. So maybe Translate and Rotate would be better names than Pan/Orbit.

I realize that this metaphor isn't fully followed everywhere, especially in code comments. So there's no need to follow it here right now, and I certainly won't block merging this pull request on this detail. I'm just mentioning it, in case you have thoughts, and to document where I'd like to see things go mid- to long-term.

(Side note: Maybe we should rename Camera to Observer or Spectator to reinforce the metaphor and reduce confusion. Maybe not a good idea.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll fix this up.

On a related note. I feel like the camera object shouldn't exist in fj-window at all. Seems like it belongs in fj-viewer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess I mean the lifetime could also be controlled by the viewer. Right now it is instantiated in fj-window.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. The way all of this is structured pretty much reflects the fact, that it lived in a single crate not long ago. It probably makes sense to have a single Viewer struct with methods like handle_input and draw_graphics. No need, really, for fj-window to deal with input::Handler, Renderer, etc. separately.

@hannobraun
Copy link
Owner

Now that I think about it, maybe f should live in fj-window, together with the other tuning values.

@jeevcat
Copy link
Contributor Author

jeevcat commented Jul 12, 2022

Thanks for all the feedback. Regarding the focus point behavior, the main reason for changing it was just to reduce complexity in implementation. But I agree with your points, so I'll make sure it works the same as previously.

Let me make the following changes then I'll un-draft this PR:

  • Ensure same focus point behavior
  • Remove Actions
  • Extract and document rotation constant
  • Rename events in accordance with model manipulation metaphor

@hannobraun
Copy link
Owner

I've already un-drafted it for some reason, but otherwise 👍

@jeevcat jeevcat requested a review from hannobraun July 12, 2022 14:13
Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, @jeevcat. Looks great!

@hannobraun hannobraun merged commit 01b0e7e into hannobraun:main Jul 12, 2022
@jeevcat jeevcat deleted the sam/viewer-interface branch July 12, 2022 14:48
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

2 participants