Unhide includes parent as neighbor and rotates around it
This commit is contained in:
parent
be816127fb
commit
ca3877f96c
|
@ -18,7 +18,7 @@ impl Default for Body {
|
|||
position: Vec2::ZERO,
|
||||
velocity: Vec2::ZERO,
|
||||
acceleration: Vec2::ZERO,
|
||||
friction: 0.1,
|
||||
friction: 0.015,
|
||||
mass: 1.0,
|
||||
fixed: false,
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ pub struct Constraint {
|
|||
|
||||
impl Constraint {
|
||||
pub fn apply(&self, mut delta: Vec2) -> Vec2 {
|
||||
const ALPHA: f32 = 0.1;
|
||||
const ALPHA: f32 = 0.4;
|
||||
let distance = delta.length();
|
||||
let displacement = distance - self.length;
|
||||
delta *= displacement / distance * self.strength * ALPHA;
|
||||
|
@ -335,15 +335,18 @@ impl ForceGraph {
|
|||
}
|
||||
|
||||
let mut neighbor_num = children.len();
|
||||
let mut rotate_by = Vec2::new(1.0, 0.0);
|
||||
|
||||
if node.info.parent.is_some() {
|
||||
if let Some(parent) = node.info.parent {
|
||||
neighbor_num += 1;
|
||||
rotate_by = self.nodes[parent].body.position - position;
|
||||
rotate_by = rotate_by.normalize();
|
||||
}
|
||||
|
||||
let theta = std::f32::consts::TAU / neighbor_num as f32;
|
||||
|
||||
for (index, child) in children.into_iter().enumerate() {
|
||||
let angle = Vec2::from_angle((index + 1) as f32 * theta);
|
||||
let angle = Vec2::from_angle((index + 1) as f32 * theta).rotate(rotate_by);
|
||||
let child = &mut self.nodes[child];
|
||||
child.info.hidden = false;
|
||||
child.body.fixed = false;
|
||||
|
|
Loading…
Reference in New Issue