From 0fae9e20897ec1efaf8ea2181f642835f6732506 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 Feb 2015 14:01:27 +0000 Subject: Dampen sprung layout energy over time to prevent oscillation. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5588 a436a847-0d15-0410-975c-d299462d15a1 --- src/Canvas.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 3339e5d..695e3c3 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -249,6 +249,7 @@ struct GanvCanvasImpl { #ifdef GANV_FDGL this->layout_idle_id = 0; + this->layout_energy = 0.4; this->sprung_layout = FALSE; #endif @@ -449,6 +450,7 @@ struct GanvCanvasImpl { #ifdef GANV_FDGL guint layout_idle_id; + gdouble layout_energy; gboolean sprung_layout; #endif }; @@ -805,8 +807,7 @@ GanvCanvasImpl::layout_iteration() { if (_drag_state == EDGE) { return FALSE; // Canvas is locked, halt layout process - } - if (!sprung_layout) { + } else if (!sprung_layout) { return FALSE; // We shouldn't be running at all } @@ -917,8 +918,6 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) GanvNode* const node = *i; - static const float damp = 0.3; // Velocity damping - if (node->impl->grabbed || (!node->impl->connected && !ganv_node_get_partner(node))) { node->impl->vel.x = 0.0; @@ -926,7 +925,7 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) } else { node->impl->vel = vec_add(node->impl->vel, vec_mult(node->impl->force, dur)); - node->impl->vel = vec_mult(node->impl->vel, damp); + node->impl->vel = vec_mult(node->impl->vel, layout_energy); static const double MAX_VEL = 1000.0; static const double MIN_COORD = 4.0; @@ -972,6 +971,7 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) } } + layout_energy *= 0.999; return n_moved > 0; } @@ -1982,6 +1982,7 @@ ganv_canvas_contents_changed(GanvCanvas* canvas) { #ifdef GANV_FDGL if (!canvas->impl->layout_idle_id && canvas->impl->sprung_layout) { + canvas->impl->layout_energy = 0.4; canvas->impl->layout_idle_id = g_timeout_add_full( G_PRIORITY_DEFAULT_IDLE, 33, -- cgit v1.2.1