Skip to content

Commit

Permalink
gizmos: cleaner force arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Jan 10, 2025
1 parent f190786 commit db7328b
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions crates/yahs-ui/src/dev_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,35 @@ impl Plugin for KinematicsGizmos {
}

fn force_arrows(weights: Query<&Weight>, buoys: Query<&Buoyancy>, drags: Query<&Drag>, mut gizmos: Gizmos) {
let mut arrows = Vec::new();

for weight in weights.iter() {
let start = weight.point_of_application();
let end = start + weight.force() * ARROW_SCALE;
let color = match weight.color() {
Some(c) => c,
None => RED.into(),
};
gizmos.arrow(start, end, color).with_tip_length(0.3);
arrows.push(new_force_arrow(weight, RED.into()));
}

for buoyancy in buoys.iter() {
let start = buoyancy.point_of_application();
let end = start + buoyancy.force() * ARROW_SCALE;

let color = match buoyancy.color() {
Some(c) => c,
None => BLUE.into(),
};
gizmos.arrow(start, end, color).with_tip_length(0.3);
arrows.push(new_force_arrow(buoyancy, BLUE.into()));
}

for drag in drags.iter() {
let start = drag.point_of_application();
let end = start + drag.force() * ARROW_SCALE;
let color = match drag.color() {
Some(c) => c,
None => GREEN.into(),
};
arrows.push(new_force_arrow(drag, GREEN.into()));
}

for (start, end, color) in arrows {
gizmos.arrow(start, end, color).with_tip_length(0.3);
}
}

fn new_force_arrow(force: &dyn Force, default_color: Color) -> (Vec3, Vec3, Color) {
let start = force.point_of_application();
let end = start + force.force() * ARROW_SCALE;
let color = match force.color() {
Some(c) => c,
None => default_color,
};
(start, end, color)
}

fn orientation_indicator(query: Query<&Transform, With<Balloon>>, mut gizmos: Gizmos) {
for transform in query.iter() {
gizmos.cross(transform.translation, 2.0, LIME);
Expand Down

0 comments on commit db7328b

Please sign in to comment.