Better parameters
This commit is contained in:
parent
eac404e976
commit
a530600e54
|
@ -18,8 +18,8 @@ impl Default for Body {
|
|||
position: Vec2::ZERO,
|
||||
velocity: Vec2::ZERO,
|
||||
acceleration: Vec2::ZERO,
|
||||
drag: 0.85,
|
||||
mass: 25.0,
|
||||
drag: 0.1,
|
||||
mass: 1.0,
|
||||
fixed: false,
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ impl MenuNode {
|
|||
from: parent,
|
||||
to: id,
|
||||
length: 30.0,
|
||||
stiffness: 0.5,
|
||||
stiffness: 15.0,
|
||||
margin: 10.0,
|
||||
});
|
||||
|
||||
|
@ -196,8 +196,8 @@ impl MenuNode {
|
|||
graph.springs.push(Spring {
|
||||
from: *sibling,
|
||||
to: id,
|
||||
length: 80.0,
|
||||
stiffness: 0.5,
|
||||
length: 60.0,
|
||||
stiffness: 15.0,
|
||||
margin: 10.0,
|
||||
});
|
||||
}
|
||||
|
@ -242,14 +242,25 @@ impl Spring {
|
|||
displacement += self.margin;
|
||||
}*/
|
||||
|
||||
if displacement.abs() < self.margin {
|
||||
/*if displacement.abs() < self.margin {
|
||||
displacement *= displacement.abs() / self.margin;
|
||||
}
|
||||
}*/
|
||||
|
||||
let displacement = displacement.clamp(-MAX_DISPLACE, MAX_DISPLACE);
|
||||
let force = displacement * self.stiffness * delta.normalize_or_zero();
|
||||
force
|
||||
}
|
||||
|
||||
pub fn d3_spring(&self, delta: Vec2) -> Vec2 {
|
||||
let distance = delta.length();
|
||||
let displacement = distance - self.length;
|
||||
|
||||
if displacement.abs() < self.margin {
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
|
||||
self.stiffness.copysign(displacement) * delta.normalize()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -299,7 +310,7 @@ impl ForceGraph {
|
|||
for spring in self.springs.iter() {
|
||||
let force = self.with_unhidden(spring.from, spring.to, |from, to| {
|
||||
let delta = to.body.position - from.body.position;
|
||||
spring.hookes_law(delta)
|
||||
spring.d3_spring(delta)
|
||||
});
|
||||
|
||||
if let Some(force) = force {
|
||||
|
@ -313,7 +324,7 @@ impl ForceGraph {
|
|||
for i in 1..self.nodes.len() {
|
||||
for j in i..self.nodes.len() {
|
||||
let force = self.with_unhidden(i - 1, j, |from, to| {
|
||||
const REPULSION_CONSTANT: f32 = 50.0;
|
||||
const REPULSION_CONSTANT: f32 = 300.0;
|
||||
let delta = to.body.position - from.body.position;
|
||||
let proximity = delta.length().max(0.1);
|
||||
let force = -(REPULSION_CONSTANT / (proximity * proximity));
|
||||
|
@ -335,11 +346,11 @@ impl ForceGraph {
|
|||
let position = node.body.position;
|
||||
let children = node.info.unhide.to_owned();
|
||||
for child in children {
|
||||
let offset = Vec2::from_angle(child as f32) * 10.0;
|
||||
let angle = Vec2::from_angle(child as f32);
|
||||
let child = &mut self.nodes[child];
|
||||
child.info.hidden = false;
|
||||
child.body.fixed = false;
|
||||
child.body.position = position + offset;
|
||||
child.body.position = position + angle;
|
||||
child.body.velocity = Vec2::ZERO;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue