From 177ef9fea33e2f8904cd6d06ec4404bfb60ed7f5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 27 Apr 2014 15:56:26 +0000 Subject: Fix layout of nodes with partners. Reduce oscillation by adding force noise. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5378 a436a847-0d15-0410-975c-d299462d15a1 --- src/Canvas.cpp | 8 +++++++- src/fdgl.hpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 5e0605b..7694954 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -883,6 +883,11 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) node->impl->force, tide_force(mouth, reg.pos, 4000000000000.0)); + // Add slight noise to force to limit oscillation + const Vector noise = { rand() / (float)RAND_MAX * 128.0, + rand() / (float)RAND_MAX * 128.0 }; + node->impl->force = vec_add(noise, node->impl->force); + FOREACH_ITEM(_items, j) { if (i == j || (!GANV_IS_MODULE(*i) && !GANV_IS_CIRCLE(*i))) { continue; @@ -902,7 +907,8 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) static const float damp = 0.3; // Velocity damping - if (node->impl->grabbed || !node->impl->connected) { + if (node->impl->grabbed || + (!node->impl->connected && !ganv_node_get_partner(node))) { node->impl->vel.x = 0.0; node->impl->vel.y = 0.0; } else { diff --git a/src/fdgl.hpp b/src/fdgl.hpp index b40f333..224824b 100644 --- a/src/fdgl.hpp +++ b/src/fdgl.hpp @@ -16,7 +16,7 @@ #include #include -static const double CHARGE_KE = 1000000.0; +static const double CHARGE_KE = 4000000.0; static const double EDGE_K = 16.0; static const double EDGE_LEN = 0.1; -- cgit v1.2.1