Skip to content
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

set_position has no effect on collider after calling step #225

Open
eldyer opened this issue Aug 30, 2019 · 2 comments
Open

set_position has no effect on collider after calling step #225

eldyer opened this issue Aug 30, 2019 · 2 comments

Comments

@eldyer
Copy link

eldyer commented Aug 30, 2019

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);
}
@sebcrozet
Copy link
Member

Hi!

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.

@jaredly
Copy link

jaredly commented Oct 7, 2019

Oh hey I just ran into this :D I would love a set_position_wrt_body!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants