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

Invert Camera2D zoom values to make it intuitive #3888

Closed
madmiraal opened this issue Jan 29, 2022 · 10 comments · Fixed by godotengine/godot#57392
Closed

Invert Camera2D zoom values to make it intuitive #3888

madmiraal opened this issue Jan 29, 2022 · 10 comments · Fixed by godotengine/godot#57392
Labels
Milestone

Comments

@madmiraal
Copy link

madmiraal commented Jan 29, 2022

Describe the project you are working on

Allowing the user to use the scroll wheel to zoom in and out of the map.

Describe the problem or limitation you are having in your project

When adjusting a Camera2D's zoom property, the values are inverted:

The camera's zoom relative to the viewport. Values larger than Vector2(1, 1) zoom out and smaller values zoom in. For an example, use Vector2(0.5, 0.5) for a 2× zoom-in, and Vector2(4, 4) for a 4× zoom-out.

Currrently a zoom of Vector(2, 2) halves the size of objects in the viewport. Similarly, a zoom of Vector(0.5, 0.5) doubles the size of objects in the viewport:

No Zoom Zoom: (2, 2) Zoom: (0.5, 0.5)
Zoom x1 - Current Zoom x2 - Current Zoom x0 5 - Current

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I would expect values greater than 1 to increase the zoom and values less than 1 to decrease the zoom. A zoom of Vector(2, 2) should double the size seen in the viewport. Similarly, a zoom of Vector(0.5, 0.5) should halve the size seen in the viewport:

No Zoom Zoom: (2, 2) Zoom: (0.5, 0.5)
Zoom x1 - Current Zoom x0 5 - Current Zoom x2 - Current

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This would be a case of simply inverting the values inside the engine.
See godotengine/godot#57392

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, but this is what I want to avoid.

Is there a reason why this should be core and not an add-on in the asset library?

It's how the engine treats Camera2D's zoom property.

@madmiraal madmiraal changed the title Invert Camera2D zoom values Invert Camera2D zoom values to make it intuitive Jan 29, 2022
@WhalesState
Copy link

WhalesState commented Jan 29, 2022

This is the default zoom behavior in any engine, smaller zoom values result is bigger size, the viewport.size is multiplied by the camera zoom, so if you change zoom to (0.5, 0.5) it will result in smaller viewport size ( Viewport.size * (0.5, 0.5) ) = half viewport.size which means bigger size on screen.

@WhalesState
Copy link

for it to make sense for you, look at the viewport while you change the zoom of the camera, when the camera becomes smaller in size the things becomes bigger on screen because it will stretch by default to fill the screen.

@madmiraal
Copy link
Author

This is the default zoom behavior in any engine, smaller zoom values result in bigger size

In literally every other application I use, increasing the zoom increases the size of the objects I see.

@WhalesState
Copy link

WhalesState commented Jan 29, 2022

@madmiraal don't mix between Scale and Zoom, already what you say is what happens by default, but because the Camera is used to stretch to the Viewport by default you feel like it's the opposite but it's not, smaller things becomes bigger on Viewport stretch and vice versa, the camera is just another Viewport that stretches to fit the 2D Viewport.

@WhalesState
Copy link

WhalesState commented Jan 29, 2022

@madmiraal for better understanding of what's happening, read about the differences between Viewport stretch modes in godot Viewport and 2D

@Mickeon
Copy link

Mickeon commented Jan 29, 2022

I remember making the same mistake as this proposal numerous times, as someone that has used more "artist programs" than "game engine editors". If anything this could warrant changing the name of the property into something else, but zoom may just be too iconic and expected to see. But then again, I find the zoom property being a Vector2 to make sense in a game context, but not in your average visualization of the value, so to speak.

In Godot 3.4.2, there's a Project Setting called display/window/stretch/shrink that behaves the same on both axis.

@WhalesState
Copy link

i also remember arguing too much when i first used the 2d camera in Godot, because i also came from an artistic environment.

@WhalesState
Copy link

there's a big difference between how the things work in the back-end for programmers and how we show it to the users, if you are making a game or an app, you can't treat the users as programmers and to give them the same values that is used in the back-end, but instead you give them easier control, but Godot editor can't do the same thing since the users of the editor are programmers and they should follow the programming road-map, it's like Godot opens the door for you to be able to use any other game engine and any other programming language easily after learning it, because it simplifies everything for you and it gives you one of the easiest scripting languages out there and it saves you from the pain of using programming languages.

@TheDuriel
Copy link

In all visual media and real life applications, zoom is the act of amplifying the image by a >1 value. 2x zoom = 2 times the size of what you see. This is consistent in many applications across many forms of media. Chrome, Discord, Word, Blender, Photoshop, Your Phones Camera app, a real cameras focus value. Etc. >1 values equal a bigger image.

Right now zoom is a misnomer, since it is the viewport scale multiplier. Which happens to be the inverse value of the zoom value to achieve zoom. A trivial solution would be to introduce a redundant virtual property called 'zoom' which takes > 1 values to enlarge the image, and behind the scenes sets the viewport scale. And to rename the current property to camera scale.

TL:DR: Zoom works in the physical and art way where bigger numbers equal bigger images. And sets the, still visible, camera scale value.

Granted, this is fairly redundant and can be achieved with a few lines of code. But, it achieves further consistency with other software. Like Blender, from which Godot is already borrowing a lot of insights.

I have definitely written this code in the past for my own projects, and will be doing it again and again for the sake of this logical consistency.

@WhalesState
Copy link

WhalesState commented Jan 31, 2022

In graphics applications they give you zoom as a slider and its value is in percentage, if you set the zoom to 200% means bigger zoom and if you set it to 50% means smaller zoom, and behind the scene, they do this calculation to change the original zoom value which is Vector2 Camera2D.zoom = Vector2( 100 / zoom_percent, 100 / zoom_percent) 100 / 200 = 0.5 which is bigger zoom and smaller camera size, and 100 / 50 = 2 which is smaller zoom and bigger camera size.

Edit: if you still see that it's not the correct way and you want to create your own Camera2D then it's easy since Godot already allows you to do that.

tool
class_name Cam2D
extends Camera2D

export(int 25, 500, 25) var zoom_percent = 100 setget set_zoom_percent

func set_zoom_percent(_zoom: int) -> void:
    zoom_percent = _zoom
    zoom = Vector2( 100 / float(_zoom), 100 / float(_zoom) )
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants