Skip to content

Commit

Permalink
physics: fix drag force (placeholder)
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Nov 19, 2024
1 parent 88ce33b commit 81c9930
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
11 changes: 8 additions & 3 deletions docs/devlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ bring in the "out of bounds" level to be less than the true bounds.

The drag force is the one that is causing the bad acceleration. Weight and
buoyancy don't change with time since the balloon has constant size right now.
Annoying since the drag is supposed to be the placeholder.

I found the bug. The drag's "flow velocity" variable was being set to the
_balloon_ velocity, rather than the opposing force. After making that change,
the balloon gently floats to the ground when filled with air, and gently rises
when filled with helium.

- Added pause/play controls. Default key is `Space`.
- Added a new ui that displays the simulation state.
Expand Down Expand Up @@ -93,9 +99,8 @@ think about it, that might be easier and simpler in the long run. If we need to
know each force's value and identity, we can add it to a resource or something
that the UI can query.

Update: it was not better. Still ran into the forever accumulating force issue
using a `ForceCollection` aggregator component and generic vectors. However, I
found a way to
Update: it was not better.

I fell in love with [iyes_perf_ui](https://github.com/IyesGames/iyes_perf_ui).
It is simple and easy to work with. Egui was adding a lot of overhead, more than
I want right now. This is perfect until I'm done with the basic features of the
Expand Down
4 changes: 3 additions & 1 deletion src/app3d/ui/monitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ struct ForceMonitor {
/// Should we display units?
pub display_units: bool,
/// Highlight the value if it goes above this threshold
#[allow(dead_code)]
pub threshold_highlight: Option<f32>,
/// Support color gradients!
#[allow(dead_code)]
pub color_gradient: ColorGradient,
/// Width for formatting the string
pub digits: u8,
Expand All @@ -172,7 +174,7 @@ impl Default for ForceMonitor {
display_units: true,
threshold_highlight: Some(10.0),
color_gradient: ColorGradient::new_preset_gyr(0.0, 10.0, 100.0).unwrap(),
digits: 12,
digits: 5,
precision: 2,
sort_key: iyes_perf_ui::utils::next_sort_key(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulator/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn spawn_balloon(
balloon: Balloon::default(),
gas: IdealGasBundle::new(
Collider::sphere(radius),
GasSpecies::air(),
GasSpecies::helium(),
Temperature::STANDARD,
Pressure::STANDARD,
),
Expand Down
6 changes: 3 additions & 3 deletions src/simulator/forces/aero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ fn update_drag_parameters(
}

/// Force (N) due to drag as a solid body moves through a fluid.
pub fn drag(flow_velocity: Vec3, ambient_density: f32, drag_area: f32, drag_coeff: f32) -> Vec3 {
let drag_direction = flow_velocity.normalize_or_zero(); // parallel to flow
pub fn drag(velocity: Vec3, ambient_density: f32, drag_area: f32, drag_coeff: f32) -> Vec3 {
let drag_direction = -velocity.normalize_or_zero(); // oppose the object's velocity
let drag_magnitude = drag_coeff / 2.0
* ambient_density
* flow_velocity.length_squared()
* velocity.length_squared()
* drag_area;
drag_direction * drag_magnitude
}
Expand Down

0 comments on commit 81c9930

Please sign in to comment.