Merge pull request #24 from Calinou/improve-camera-zoom

Improve the camera zoom behavior
This commit is contained in:
Rodz Labs 2019-10-18 06:48:58 +02:00 committed by GitHub
commit 65ece5f794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,9 @@ const ENVIRONMENTS = [
"experiment", "lobby", "night", "park", "schelde" "experiment", "lobby", "night", "park", "schelde"
] ]
const CAMERA_DISTANCE_MIN = 1.0
const CAMERA_DISTANCE_MAX = 10.0
onready var objects = $MaterialPreview/Preview3d/Objects onready var objects = $MaterialPreview/Preview3d/Objects
onready var current_object = objects.get_child(0) onready var current_object = objects.get_child(0)
@ -77,9 +80,17 @@ func on_gui_input(event):
$Config/Rotate.pressed = false $Config/Rotate.pressed = false
match event.button_index: match event.button_index:
BUTTON_WHEEL_UP: BUTTON_WHEEL_UP:
camera.translation.z *= 1.01 if event.shift else 1.1 camera.translation.z = clamp(
camera.translation.z / (1.01 if event.shift else 1.1),
CAMERA_DISTANCE_MIN,
CAMERA_DISTANCE_MAX
)
BUTTON_WHEEL_DOWN: BUTTON_WHEEL_DOWN:
camera.translation.z /= 1.01 if event.shift else 1.1 camera.translation.z = clamp(
camera.translation.z * (1.01 if event.shift else 1.1),
CAMERA_DISTANCE_MIN,
CAMERA_DISTANCE_MAX
)
elif event is InputEventMouseMotion: elif event is InputEventMouseMotion:
var motion = 0.01*event.relative var motion = 0.01*event.relative
var camera_basis = camera.global_transform.basis var camera_basis = camera.global_transform.basis