inline Coord3D repulsionForce(const Coord3D& a, const Coord3D& b, float repulsion, float natlength) { Coord3D diff = a - b; float r = repulsion; r /= cube((std::max)(diff.size() / 2.0f, natlength / 10)); diff = diff * r + Coord3D(frand(-0.01f, 0.01f), frand(-0.01f, 0.01f), frand(-0.01f, 0.01f)); return diff; }
Coord3D SpringLayout::forceLinearSprings(const Coord3D& a, const Coord3D& b, float ideal) { Coord3D diff = (a - b); float dist = diff.size() - ideal; float factor = (std::max)(dist, 0.0f) * m_attraction; // Let springs attract really strong near their equilibrium if (dist > 0.0f) { factor = (std::max)(factor, 100 * m_attraction / (std::max)(dist * dist / 10000.0f, 0.1f)); } return diff * factor; }