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 orbitControl() to make it smoother #6140

Merged
merged 8 commits into from
May 14, 2023
Merged

Improve orbitControl() to make it smoother #6140

merged 8 commits into from
May 14, 2023

Conversation

inaridarkfox4231
Copy link
Contributor

Introduce the idea of ​​using p5.EasyCam's damping to make the behavior of orbitControl() smoother.

Resolves #6139

Changes:

When you set up your renderer, you provide velocity variables to handle each of the scaling, rotation, and translation.
Interactions accelerate these velocity variables.
The velocity variable is moderately damped every frame.
You can smooth out the behavior by performing an update on these velocity variables.

Demo

Demo is here:newOrbitControl

PR Checklist

Let material and texture coexist.
revert.
Prepare velocity variables in the renderer. 
These are used in orbitControl() to smooth things out.
By introducing damping to orbitControl(), the processing is smoothed and more comfortable operation is realized.
This idea was inspired by p5.EasyCam.
Variable "mouseZoomScaleFactor" is too long, so shorten process to pass linter.
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

This is feeling really good so far, and definitely feels more polished/professional! I left a few little notes, let me know what you think!

this._renderer._curCamera._orbit(0, 0, deltaRadius);

// zoom process
if (accelerateZoomVelocity) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we initialize deltaRadius to 0, maybe we could simplify this section by removing the need for an accelerateZoomVelocity flag? And maybe similarly for the rotation/move flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If initialize it to 0 and only process it if it's not 0 then probably don't need the flag... ok, I'll think about it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that the flag has been eliminated, let's rewrite the code.

let executeRotateProcess = false;
let executeMoveProcess = false;
// The idea of using damping is based on the following website. thank you.
// https://github.com/freshfork/p5.EasyCam/blob/master/p5.easycam.js
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to consider using a link to a commit hash (and maybe a relevant line number?) in case the easycam repo changes any branch or file names. Maybe this? https://github.com/freshfork/p5.EasyCam/blob/9782964680f6a5c4c9bee825c475d9f2021d5134/p5.easycam.js#L1124

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly, it would be easier to understand if put a link directly to the place. I got it!
In the case of comments, is it okay if the number of characters is large?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be fine!

// For touches, the appropriate scale is different
// because the distance difference is multiplied.
const mouseZoomScaleFactor = 0.02;
const touchZoomScaleFactor = 0.0008;
const mouseZoomScaleFactor = 0.00008;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think my impression of zooming using my laptop trackpad is that it feels just a little bit slow to start, how would you feel about increasing this a little bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it a little bigger.

  const mouseZoomScaleFactor = 0.0001;
  const touchZoomScaleFactor = 0.0004;

how is it? If possible, I would like you to rewrite the code and try it...
Here is the rewritten code. newOrbitControl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the reason I messed with the touch was because I was trying to change these at the same time.
If it's better not to change the touch, I'm going to try not to change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's an improvement, thanks!

I've rewritten the link address to show exactly where the referenced idea is.
If you initialize the variables used to move the camera to 0, you don't need to make judgments with flags.
@@ -175,43 +177,81 @@ p5.prototype.orbitControl = function(
// if mouseLeftButton is down, rotate
// if mouseRightButton is down, move
if (this._mouseWheelDeltaY !== 0) {
executeZoomProcess = true;
// zoom according to direction of mouseWheelDeltaY rather than value.
Copy link
Contributor

Choose a reason for hiding this comment

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

oh one more tiny thing, is this comment still accurate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, the original comment is still there... not good.
For example, "zoom the camera depending on the value of _mouseWheelDeltaY. Move away if positive, move closer if negative" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I would like to add a comment to the zoom section for touch.

Increased some constants for better usability.
Part of the explanation about zooming was inappropriate, so I rewrote it.
Also, added a comment to the zoom section for touch.
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes, everything looks good!

@davepagurek davepagurek merged commit a181fab into processing:main May 14, 2023
@inaridarkfox4231 inaridarkfox4231 deleted the improve_orbitControl branch May 14, 2023 22:44
@inaridarkfox4231
Copy link
Contributor Author

Thank you very much for all! ('ω')

@inaridarkfox4231 inaridarkfox4231 restored the improve_orbitControl branch May 14, 2023 22:47
@inaridarkfox4231 inaridarkfox4231 deleted the improve_orbitControl branch May 14, 2023 22:47
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.

Make orbitControl() smoother
2 participants