I've been unable to find anything online relating to the answer I'm looking for.
All the key words keep taking me to solutions to other problems.
Basically the Camera class has a Property called keep_aspect which must be set to either KEEP_WIDTH or KEEP_HEIGHT.
One will cause the 3D contents of the window to only stretch/shrink when resizing vertically and the other will cause the contents to stretch/shrink when resizing horizontally.
Problem: There is no option to prevent stretching/shrinking when resizing in either direction.
I've also tried every combination of settings from the menu Project => Project Settings... -> Display -> Window :> Stretch >> Mode and Aspect.
The closest work-a-round I have figured out is this:
extends Spatial
onready var viewport : Viewport = get_tree().root
func _ready() -> void:
assert(OK == viewport.connect("size_changed", self, "_on_resize"))
func _on_resize() -> void:
var val : float = 1.0 - ((1280.0 - OS.window_size.x) / 1280.0) # This almost works, almost. . .
viewport.get_camera().fov = 70.0 * val
Notes:
Camera.keep_aspect = KEEP_WIDTH
1280.0 is my initial Window width.
70.0 is my initial Camera.fov.
Drop the above GDScript code into a script attached to a node in the scene and it Should Just Work⢠(just not 100% correctly).
Defect: When the window gets small enough, val grows a little too big and ends up zooming in instead of keeping the contents of the window the same size.
I don't know how to work out the math correctly to get it to work. Basically Camera.fov is not a linear value.
Is there a better solution, has this been solved somewhere else that I haven't found, or can someone please help me out with the math one?