You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To demonstrate the issue I made the following test, which should be self-explaining.
Notice the use of position in the collider description builder vs. set_position.
#[test]
pub fn test() {
use nalgebra::{Isometry3, Vector3};
use ncollide3d::shape::{Cuboid, ShapeHandle};
use nphysics3d::{
force_generator::DefaultForceGeneratorSet,
joint::DefaultJointConstraintSet,
object::{BodyPartHandle, ColliderDesc, DefaultBodySet, DefaultColliderSet, Ground},
world::{DefaultGeometricalWorld, DefaultMechanicalWorld},
};
// world
let mut mechanical_world = DefaultMechanicalWorld::new(Vector3::new(0.0, -9.81, 0.0));
let mut geometrical_world = DefaultGeometricalWorld::<f32>::new();
let mut bodies = DefaultBodySet::<f32>::new();
let mut colliders = DefaultColliderSet::new();
let mut joint_constraints = DefaultJointConstraintSet::<f32>::new();
let mut force_generators = DefaultForceGeneratorSet::<f32>::new();
// ground
let ground_thickness = 0.2;
let ground_shape = ShapeHandle::new(Cuboid::new(Vector3::new(3.0, ground_thickness, 3.0)));
let ground_handle = bodies.insert(Ground::new());
let co = ColliderDesc::new(ground_shape)
.translation(Vector3::y() * -ground_thickness)
.build(BodyPartHandle(ground_handle, 0));
colliders.insert(co);
let cuboid = ShapeHandle::new(Cuboid::new(Vector3::repeat(0.2)));
let isometry = Isometry3::translation(1.0, 1.0, 1.0);
// collider 1
let co_1 = ColliderDesc::new(cuboid.clone())
.position(Isometry3::translation(1.0, 1.0, 1.0))
.build(BodyPartHandle(ground_handle, 0));
let co_handle_1 = colliders.insert(co_1);
assert_eq!(colliders.get(co_handle_1).unwrap().position(), &isometry);
// collider 2
let mut co_2 = ColliderDesc::new(cuboid.clone()).build(BodyPartHandle(ground_handle, 0));
co_2.set_position(Isometry3::translation(1.0, 1.0, 1.0));
let co_handle_2 = colliders.insert(co_2);
assert_eq!(colliders.get(co_handle_2).unwrap().position(), &isometry);
mechanical_world.step(
&mut geometrical_world,
&mut bodies,
&mut colliders,
&mut joint_constraints,
&mut force_generators,
);
// passes
assert_eq!(colliders.get(co_handle_1).unwrap().position(), &isometry);
// fails!
assert_eq!(colliders.get(co_handle_2).unwrap().position(), &isometry);
}
The text was updated successfully, but these errors were encountered:
This is expected. We should probably make set_position not callable from outside of nphysics itself. The position of a collider is recomputed automatically at each timestep, using the position of the body it is attached to, and the collider position relative to the body (given by collider.position_wrt_body). Perhaps we should add a collider.set_position_wrt_body method instead.
To demonstrate the issue I made the following test, which should be self-explaining.
Notice the use of
position
in the collider description builder vs.set_position
.The text was updated successfully, but these errors were encountered: