-
-
Notifications
You must be signed in to change notification settings - Fork 347
Fix user changes handling #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
78196b7
8600092
607f098
a175022
225ba23
1f6c483
8c15796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ impl ColliderSet { | |
| self.modified_colliders.clear(); | ||
| let modified_colliders = &mut self.modified_colliders; | ||
| self.colliders.iter_mut().map(move |(h, b)| { | ||
| b.changes |= ColliderChanges::MODIFIED; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is correct ; the fix may be more around And then add then refill |
||
| modified_colliders.push(ColliderHandle(h)); | ||
| (ColliderHandle(h), b) | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -668,7 +668,7 @@ impl PhysicsPipeline { | |
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use na::point; | ||
| use na::{point, vector}; | ||
|
|
||
| use crate::dynamics::{ | ||
| CCDSolver, ImpulseJointSet, IntegrationParameters, IslandManager, RigidBodyBuilder, | ||
|
|
@@ -1011,4 +1011,65 @@ mod test { | |
| assert!(rotation.w.is_finite()); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "dim2")] | ||
| fn test_multi_sap_disable_body() { | ||
| let mut rigid_body_set = RigidBodySet::new(); | ||
| let mut collider_set = ColliderSet::new(); | ||
|
|
||
| /* Create the ground. */ | ||
| let collider = ColliderBuilder::cuboid(100.0, 0.1).build(); | ||
| collider_set.insert(collider); | ||
|
|
||
| /* Create the bouncing ball. */ | ||
| let rigid_body = RigidBodyBuilder::dynamic() | ||
| .translation(vector![0.0, 10.0]) | ||
| .build(); | ||
| let collider = ColliderBuilder::ball(0.5).restitution(0.7).build(); | ||
| let ball_body_handle = rigid_body_set.insert(rigid_body); | ||
| collider_set.insert_with_parent(collider, ball_body_handle, &mut rigid_body_set); | ||
|
|
||
| /* Create other structures necessary for the simulation. */ | ||
| let gravity = vector![0.0, -9.81]; | ||
| let integration_parameters = IntegrationParameters::default(); | ||
| let mut physics_pipeline = PhysicsPipeline::new(); | ||
| let mut island_manager = IslandManager::new(); | ||
| let mut broad_phase = BroadPhaseMultiSap::new(); | ||
| let mut narrow_phase = NarrowPhase::new(); | ||
| let mut impulse_joint_set = ImpulseJointSet::new(); | ||
| let mut multibody_joint_set = MultibodyJointSet::new(); | ||
| let mut ccd_solver = CCDSolver::new(); | ||
| let physics_hooks = (); | ||
| let event_handler = (); | ||
|
|
||
| /* Run the game loop, stepping the simulation once per frame. */ | ||
| for _ in 0..200 { | ||
| physics_pipeline.step( | ||
| &gravity, | ||
| &integration_parameters, | ||
| &mut island_manager, | ||
| &mut broad_phase, | ||
| &mut narrow_phase, | ||
| &mut rigid_body_set, | ||
| &mut collider_set, | ||
| &mut impulse_joint_set, | ||
| &mut multibody_joint_set, | ||
| &mut ccd_solver, | ||
| None, | ||
| &physics_hooks, | ||
| &event_handler, | ||
| ); | ||
|
|
||
| let ball_body = &mut rigid_body_set[ball_body_handle]; | ||
| println!("Ball altitude: {}", ball_body.translation().y); | ||
|
|
||
| // This causes the error: | ||
| // Modify the translation (or rotation) (RigidBodyChanges::POSITION) | ||
| // Modify enabled | ||
| ball_body.set_translation(vector![0.0, 0.0], true); | ||
| // ball_body.set_rotation(nalgebra::UnitComplex::new(1.0), true); | ||
| ball_body.set_enabled(false); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a better test because it covers both RigidBodyChanges::POSITION with enable and disable, and it doesn't run for 200 iterations. use rapier2d::prelude::*;
fn main() {
// Create other structures necessary for the simulation.
let mut rigid_body_set = RigidBodySet::new();
let mut collider_set = ColliderSet::new();
let gravity = vector![0.0, -9.81];
let integration_parameters = IntegrationParameters::default();
let mut physics_pipeline = PhysicsPipeline::new();
let mut island_manager = IslandManager::new();
let mut broad_phase = DefaultBroadPhase::new();
let mut narrow_phase = NarrowPhase::new();
let mut impulse_joint_set = ImpulseJointSet::new();
let mut multibody_joint_set = MultibodyJointSet::new();
let mut ccd_solver = CCDSolver::new();
let mut query_pipeline = QueryPipeline::new();
let physics_hooks = ();
let event_handler = ();
// Create the ball with default values for translation, position and enabled state
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 0.0])
.rotation(0.0)
.build();
let collider = ColliderBuilder::ball(0.5)
.enabled(true)
.build();
let ball_body_handle = rigid_body_set.insert(rigid_body);
collider_set.insert_with_parent(collider, ball_body_handle, &mut rigid_body_set);
physics_pipeline.step(
&gravity,
&integration_parameters,
&mut island_manager,
&mut broad_phase,
&mut narrow_phase,
&mut rigid_body_set,
&mut collider_set,
&mut impulse_joint_set,
&mut multibody_joint_set,
&mut ccd_solver,
Some(&mut query_pipeline),
&physics_hooks,
&event_handler,
);
// This causes the error:
// Test RigidBodyChanges::POSITION and disable
{
let ball_body = &mut rigid_body_set[ball_body_handle];
// Also, change the translation and rotation to different values
ball_body.set_translation(vector![1.0, 1.0], true);
ball_body.set_rotation(nalgebra::UnitComplex::new(1.0), true);
ball_body.set_enabled(false);
}
physics_pipeline.step(
&gravity,
&integration_parameters,
&mut island_manager,
&mut broad_phase,
&mut narrow_phase,
&mut rigid_body_set,
&mut collider_set,
&mut impulse_joint_set,
&mut multibody_joint_set,
&mut ccd_solver,
Some(&mut query_pipeline),
&physics_hooks,
&event_handler,
);
// Test RigidBodyChanges::POSITION and enable
{
let ball_body = &mut rigid_body_set[ball_body_handle];
// Also, change the translation and rotation to different values
ball_body.set_translation(vector![0.0, 0.0], true);
ball_body.set_rotation(nalgebra::UnitComplex::new(0.0), true);
ball_body.set_enabled(true);
}
physics_pipeline.step(
&gravity,
&integration_parameters,
&mut island_manager,
&mut broad_phase,
&mut narrow_phase,
&mut rigid_body_set,
&mut collider_set,
&mut impulse_joint_set,
&mut multibody_joint_set,
&mut ccd_solver,
Some(&mut query_pipeline),
&physics_hooks,
&event_handler,
);
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rewrote it again, set default values at the beginning, and ensured that the values change. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me wonder if we should change
ColliderChanges::POSITION(and the likes) from:const POSITION = 1 << 3to
const POSITION = 1 << 3 | 1 << 0;(addingColliderChanges::MODIFIEDto it)This would clarify their relation and make mistakes harder to make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is probably not possible because
MODIFIEDis used to check if a collider is part of themodified_colliderslist. This seems difficult to maintain, I imagine searching formodified_colliders.pushshould be able to lead to aMODIFIEDbit to be added to that collider, but it's sometimes tricky to assess.I imagine changing
modified_collidersto aHashmapmay be less performant than storing that in the bitfield, but I'm throwing the idea.