summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-02-20 14:01:27 +0000
committerDavid Robillard <d@drobilla.net>2015-02-20 14:01:27 +0000
commit0fae9e20897ec1efaf8ea2181f642835f6732506 (patch)
tree76a3464acae34083b24b1c041373bf7fe3daca87 /src
parent56cdcc7f886e9a4889f8f692c7863190705d9452 (diff)
downloadganv-0fae9e20897ec1efaf8ea2181f642835f6732506.tar.gz
ganv-0fae9e20897ec1efaf8ea2181f642835f6732506.tar.bz2
ganv-0fae9e20897ec1efaf8ea2181f642835f6732506.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/Canvas.cpp11
1 files changed, 6 insertions, 5 deletions
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,