Skip to content

Commit 93922f2

Browse files
Merge pull request #8 from BlankSourceCode/log-display-name-and-ease
Add easing to zoom animation
2 parents dbd5405 + 5c7c314 commit 93922f2

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

obs-zoom-to-mouse.lua

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ function lerp(v0, v1, t)
135135
return v0 * (1 - t) + v1 * t;
136136
end
137137

138+
---
139+
-- Ease a time value in and out
140+
---@param t number Time between 0 and 1
141+
---@return number
142+
function ease_in_out(t)
143+
t = t * 2
144+
if t < 1 then
145+
return 0.5 * t * t * t
146+
else
147+
t = t - 2
148+
return 0.5 * (t * t * t + 2)
149+
end
150+
end
151+
138152
---
139153
-- Clamps a given value between min and max
140154
---@param min number The min value
@@ -172,8 +186,9 @@ function get_monitor_info(source)
172186
-- TODO: Update this with some custom FFI calls to find the monitor top-left x and y coordinates if it doesn't work for anyone else
173187
-- TODO: Refactor this into something that would work with Windows/Linux/Mac assuming we can't do it like this
174188
if found then
175-
local x, y = found:match("@ (%d+),(%d+)")
176-
local width, height = found:match(": (%d+)x(%d+)")
189+
log("Parsing display name: " .. found)
190+
local x, y = found:match("(%d+),(%d+)")
191+
local width, height = found:match("(%d+)x(%d+)")
177192

178193
info = { x = 0, y = 0, width = 0, height = 0 }
179194
info.x = tonumber(x, 10)
@@ -186,6 +201,9 @@ function get_monitor_info(source)
186201
if info.width == 0 and info.height == 0 then
187202
info = nil
188203
end
204+
else
205+
log("Warning: Could not find display name.\n" ..
206+
"Try using the 'Set manual monitor position' option and adding override values")
189207
end
190208
end
191209

@@ -617,10 +635,10 @@ function on_timer()
617635
if zoom_state == ZoomState.ZoomingIn and use_auto_follow_mouse then
618636
zoom_target = get_target_position(zoom_info)
619637
end
620-
crop_filter_info.x = lerp(crop_filter_info.x, zoom_target.crop.x, zoom_time)
621-
crop_filter_info.y = lerp(crop_filter_info.y, zoom_target.crop.y, zoom_time)
622-
crop_filter_info.w = lerp(crop_filter_info.w, zoom_target.crop.w, zoom_time)
623-
crop_filter_info.h = lerp(crop_filter_info.h, zoom_target.crop.h, zoom_time)
638+
crop_filter_info.x = lerp(crop_filter_info.x, zoom_target.crop.x, ease_in_out(zoom_time))
639+
crop_filter_info.y = lerp(crop_filter_info.y, zoom_target.crop.y, ease_in_out(zoom_time))
640+
crop_filter_info.w = lerp(crop_filter_info.w, zoom_target.crop.w, ease_in_out(zoom_time))
641+
crop_filter_info.h = lerp(crop_filter_info.h, zoom_target.crop.h, ease_in_out(zoom_time))
624642
set_crop_settings(crop_filter_info)
625643
end
626644
else
@@ -953,11 +971,11 @@ end
953971
function script_defaults(settings)
954972
-- Default values for the script
955973
obs.obs_data_set_default_double(settings, "zoom_value", 2)
956-
obs.obs_data_set_default_double(settings, "zoom_speed", 0.1)
957-
obs.obs_data_set_default_bool(settings, "follow", false)
974+
obs.obs_data_set_default_double(settings, "zoom_speed", 0.06)
975+
obs.obs_data_set_default_bool(settings, "follow", true)
958976
obs.obs_data_set_default_bool(settings, "follow_outside_bounds", false)
959-
obs.obs_data_set_default_double(settings, "follow_speed", 0.1)
960-
obs.obs_data_set_default_int(settings, "follow_border", 2)
977+
obs.obs_data_set_default_double(settings, "follow_speed", 0.25)
978+
obs.obs_data_set_default_int(settings, "follow_border", 8)
961979
obs.obs_data_set_default_int(settings, "follow_safezone_sensitivity", 4)
962980
obs.obs_data_set_default_bool(settings, "follow_auto_lock", false)
963981
obs.obs_data_set_default_bool(settings, "use_monitor_override", false)

0 commit comments

Comments
 (0)