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

Add Viewport Smooth Focus Transition Animation config option #432

Open
wants to merge 1 commit into
base: v0_8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/creator/core/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ void incSettingsSet(T)(string name, T value) if (!is(T == string[])) {
settings[name] = value;
}

/**
Removes a setting
*/
void incSettingsRemove(string name) {
settings.object.remove(name);
}

/**
Gets a value from the settings store
*/
Expand Down
27 changes: 20 additions & 7 deletions source/creator/panels/viewport.d
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,23 @@ protected:
}
igEndChild();

// Handle smooth move
incViewportZoom = fdampen(incViewportZoom, incViewportTargetZoom, cast(float)deltaTime);
handleViewportSmoothMove(camera);
}

/**
Handle smooth movement of the viewport
*/
void handleViewportSmoothMove(Camera camera) {
if (incIsEnabledSmoothFocus()) {
float maxSpeed = incGetViewportSmoothMaxSpeed();
float speed = incGetViewportSmoothSpeed();
incViewportZoom = fdampen(incViewportZoom, incViewportTargetZoom, cast(float)deltaTime, maxSpeed, speed);
camera.position = vec2(fdampen(camera.position, incViewportTargetPosition, cast(float)deltaTime, maxSpeed, speed));
} else {
incViewportZoom = incViewportTargetZoom;
camera.position = incViewportTargetPosition;
}
camera.scale = vec2(incViewportZoom, incViewportZoom);
camera.position = vec2(fdampen(camera.position, incViewportTargetPosition, cast(float)deltaTime));
}

public:
Expand All @@ -327,7 +340,7 @@ mixin incPanel!ViewportPanel;

import inmath.util;
import std.traits;
V fdampen(V, T)(V current, V target, T delta, T maxSpeed = 50) if(isVector!V && isFloatingPoint!T) {
V fdampen(V, T)(V current, V target, T delta, T maxSpeed = 50, T conifgSpeed = 5.0) if(isVector!V && isFloatingPoint!T) {
V out_ = current;
V diff = current - target;

Expand All @@ -336,7 +349,7 @@ V fdampen(V, T)(V current, V target, T delta, T maxSpeed = 50) if(isVector!V &&
V direction = (diff).normalized;

T speed = min(
max(0.001, 5.0*(target - current).length) * delta,
max(0.001, conifgSpeed*(target - current).length) * delta,
maxSpeed
);
V velocity = direction * speed;
Expand All @@ -353,7 +366,7 @@ V fdampen(V, T)(V current, V target, T delta, T maxSpeed = 50) if(isVector!V &&
return out_;
}

T fdampen(T)(T current, T target, T delta, T maxSpeed = 50) if(isFloatingPoint!T) {
T fdampen(T)(T current, T target, T delta, T maxSpeed = 50, T conifgSpeed = 5.0) if(isFloatingPoint!T) {
T out_ = current;
T diff = current - target;
T diffLen = sqrt(diff^^2);
Expand All @@ -363,7 +376,7 @@ T fdampen(T)(T current, T target, T delta, T maxSpeed = 50) if(isFloatingPoint!T
if (diffLen > 0) {

T speed = min(
max(0.001, 5.0*sqrt((target - current)^^2)) * delta,
max(0.001, conifgSpeed*sqrt((target - current)^^2)) * delta,
maxSpeed
);
T velocity = direction * speed;
Expand Down
34 changes: 34 additions & 0 deletions source/creator/viewport/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,37 @@ bool incSetViewportZoomSpeed(float speed) {
incSettingsSet("ViewportZoomSpeed", speed);
return true;
}

/**
Viewport smooth focus configuration
also see fdampen() function
*/
bool incIsEnabledSmoothFocus() {
return incSettingsGet!bool("Viewport.EnabledSmoothFocus", true);
}

void incSetEnabledSmoothFocus(bool enable) {
incSettingsSet("Viewport.EnabledSmoothFocus", enable);
}

float incGetViewportSmoothSpeed() {
return incSettingsGet!float("Viewport.SmoothSpeed", 5);
}

void incSetViewportSmoothSpeed(float speed) {
incSettingsSet("Viewport.SmoothSpeed", speed);
}

float incGetViewportSmoothMaxSpeed() {
return incSettingsGet!float("Viewport.SmoothMaxSpeed", 50);
}

void incSetViewportSmoothMaxSpeed(float speed) {
incSettingsSet("Viewport.SmoothMaxSpeed", speed);
}

void incResetViewportSmoothSpeed() {
incSettingsRemove("Viewport.SmoothSpeed");
incSettingsRemove("Viewport.SmoothMaxSpeed");
incSettingsRemove("Viewport.EnabledSmoothFocus");
}
21 changes: 21 additions & 0 deletions source/creator/windows/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ protected:
incSetViewportZoomSpeed(zoomSpeed);
}
endSection();

beginSection(__("Smooth Focus Transition Animation"));
bool smoothFocus = incIsEnabledSmoothFocus();
if (igCheckbox(__("Enable Smooth Focus Animation"), &smoothFocus))
incSetEnabledSmoothFocus(smoothFocus);

igBeginDisabled(!smoothFocus);
float focusSpeed = incGetViewportSmoothSpeed();
if (igDragFloat(__("Focus Speed"), &focusSpeed, 0.01, 0, 100, "%0.2f"))
incSetViewportSmoothSpeed(focusSpeed);

float maxSpeed = incGetViewportSmoothMaxSpeed();
if (igDragFloat(__("Max Speed"), &maxSpeed, 0.01, 0, 1000, "%0.2f"))
incSetViewportSmoothMaxSpeed(maxSpeed);

igEndDisabled();

if (igButton(__("Reset##Smooth Focus"), ImVec2(64, 24)))
incResetViewportSmoothSpeed();

endSection();
break;
default:
incLabelOver(_("No settings for this category."), ImVec2(0, 0), true);
Expand Down
Loading