-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[examples] Use logarithmic scaling for 2d examples with zoom functionality #3977
Conversation
You can also implement something similar with powf, like here:
This way you also get natural feeling increments. This solution seems more straightforward to me, but maybe the expf solution has some advantages that I fail to see. |
@rmn20 Personally I prefer this solution, it seems more simple to me. Also, I prefer to apply it to only one of the examples ( |
Basically, the EDIT: Actually, we can avoid float scaleFactor = 1.0f + (0.25f * fabsf(wheel));
if (wheel < 0) scaleFactor = 1.0f / scaleFactor;
camera.zoom = Clamp(camera.zoom * scaleFactor, 0.125, 64); |
a52a181
to
e272cc6
Compare
If it's just the one example that this change is being applied to, I'd also like to propose using a click-and-drag motion instead of the mouse wheel: @@ -48,9 +48,8 @@ int main ()
camera.target = Vector2Add(camera.target, delta);
}
- // Zoom based on mouse wheel
- float wheel = GetMouseWheelMove();
- if (wheel != 0)
+ // Zoom based on mouse left click
+ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
// Get the world point that is under the mouse
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
@@ -61,10 +60,13 @@ int main ()
// Set the target to match, so that the camera maps the world space point
// under the cursor to the screen space point under the cursor at any zoom
camera.target = mouseWorldPos;
-
+ }
+ if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
+ {
// Zoom increment
- float scaleFactor = 1.0f + (0.25f * fabsf(wheel));
- if (wheel < 0) scaleFactor = 1.0f / scaleFactor;
+ float deltaX = GetMouseDelta().x;
+ float scaleFactor = 1.0f + (0.01f * fabsf(deltaX));
+ if (deltaX < 0) scaleFactor = 1.0f / scaleFactor;
camera.zoom = Clamp(camera.zoom * scaleFactor, 0.125, 64);
} |
@myQwil Actually examples are intended for users to learn so we can add several approaches to show users the different possibilities. I'm merging this PR and adding the proposed alternative. |
Makes zoom increments feel more natural. Otherwise, increments can feel too small when zoomed in, or too big when zoomed out.