-
-
Notifications
You must be signed in to change notification settings - Fork 56
Make controllers configurable and apply damping #490
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
Conversation
@berendkleinhaneveld we need to test this branch with your project before merging. I'm a little concerned it won't be compatible with your push-based render loop. |
This is ready (and no longer requires a change in wgpu-py). |
I added an example with a very wide texture, and a camera config that only allows horizontal panning. Funnily enough, the horizontal-only panning revealed that the panning also moved vertically, due to a bug where we calculate the panning vectors. |
Another question: is it possible to disable damping? |
Yes, just set it to 0. |
In that case, I'd like a test from berend to see how well this works on his project before we merge. |
I'll try it out, but it will have to wait till next week. Unless we are in a hurry to get this in? |
No, not in a hurry. BTW, once this is merged I'll add a Trackball controller (which is just a few lines) and a FlyController (which also should be easy now). |
@berendkleinhaneveld I added an explanation in the top post. If needed we can sit together to see how we can tie things together. |
So I discussed this with Berend and here's what would need to change in order for collagraph to retain full control over the update-render loop:
There's two essential requirements here:
|
Is the controller hooked up to the renderer events in the collagraph case? If not, a lot of the requirements are met, which means that we can keep the controller Just Work when using
Would it work if we made |
The controller is listening to mouse/keyboard events, but nothing else. I guess that's what you mean?
Yes, I agree.
Yes, that would work. We could also make the camera state a property, instead of returning it. I think that's a little more flexible. |
How are these events fed into the controller? By calling
I'd rather not, because the internal camera state is only valid as long as any actions are active, and we'd have to figure out whether to e.g. set it to None when there are no actions, etc. |
I just pushed a commit that I think should do the trick. The |
I added the reactive example and adjusted it for the new controller. |
Exactly. Because of the inertia, it needs to be called somehow in addition to (mouse) events. A timer would work. At draw-time works too. |
New features:
It needs some work:
before_draw
(also in relation to viewports) in a seperate PR.How does the controller work?
When an interaction starts, an
action
object is created. In some cases (e.g. dragging) the action's target value is updated as new events come in. There can be multiple actions simultaneously, e.g. you can zoom while panning. Though only one drag action is allowed at one time, otherwise that just gets weird.During each "tick" a number of things happen:
A bit more on that state object: the camera's state is obtained using
camera.get_state()
, and is kept as a private var on the controller. It is updated at each tick (possibly by multiple actions). This controller's internal state is used as long as there are active actions. This means that changes to the cameras (e.g. pushing a button to rotate it), have no effect while the controller is doing its thing. In practice the inertia from the smoothing is short, so this should not be a problem for changes invoked by user interaction.So how is this kept up-to date? When an event occurs that changes the state, a new draw is requested (unless
auto_update
is false).The tick mentioned above happens right before each draw, using a new event emitted by the renderer. The tick itself also requests a new draw when there are still active actions.
When you don't make use of
controller.register_events()
, this would work somewhat differently. We may need to change a few things around to make that work well.