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

RigdBodyDesc can't be stored #205

Open
AndreaCatania opened this issue Jun 23, 2019 · 8 comments
Open

RigdBodyDesc can't be stored #205

AndreaCatania opened this issue Jun 23, 2019 · 8 comments

Comments

@AndreaCatania
Copy link

The RigidBodyDesc accept a reference to the colliders https://github.com/rustsim/nphysics/blob/master/src/object/rigid_body.rs#L727

The problem is that due to the lifetime used there is not possible to store the RigidBodyDesc in the heap and move it around.

Since the RigidBody only exist inside the world, and I need to manipulate its parameters even out of the world, would be nice to be able to store them directly inside the descriptor.

@sebcrozet
Copy link
Member

Hi! I'm currently attempting to allow the user to manage itself the set of rigid bodies (outside of the physics world),. That should solve your problem here.

@AndreaCatania
Copy link
Author

Do you mean make the RigidBody available even if not assigned to the world yet?

In this case it will improve a lot the integration that I'm doing

@sebcrozet
Copy link
Member

Basically the user will responsible for managing the set of bodies. A reference to this set will have to be passed to every methods like world.step because the physics world will no longer own the set of bodies.

@AndreaCatania
Copy link
Author

AndreaCatania commented Jun 23, 2019

This seems nice but instead to pass the whole array per each call, what do you think about insert an array of weak pointers inside the world?

So the user can handle the bodies as he prefer.
For example he could even store the bodies not in an Array, or he could even use a custom Array (like me)

@sebcrozet
Copy link
Member

sebcrozet commented Jun 23, 2019

By set of bodies I did not mean an Array. specifically I meant anything (including user-defined collections) that would be able to provide references to bodies. So it would basically be anything that implements a trait like:

trait BodySet<'a, N: RealField> {
    type Body: ?Sized + Body<N>;
    type Handle: Copy;
    type Iter: Iterator<Item = (Self::Handle, &'a Self::Body)>;
    type IterMut: Iterator<Item = (Self::Handle, &'a mut Self::Body)>;

    fn get(&self, handle: Self::Handle) -> Option<&Self::Body>;
    fn get_mut(&mut self, handle: Self::Handle) -> Option<&mut Self::Body>;

    fn contains(&self, handle: Self::Handle) -> bool;

    fn iter(&'a self) -> Self::Iter;
    fn iter_mut(&'a mut self) -> Self::IterMut;
}

This trait is what I am experimenting with. The World stepping method would look like:

fn step<'a, N: RealField, Bodies: BodySet<'a, N>() {
  ....
}

Having the world store a weak pointer isn't desirable as it would require the user to rely on some form of shared pointers like Arc or Rc, which is not desirable.

@AndreaCatania
Copy link
Author

This is perfect for what I'm doing! Do you already have a PR / branch that I can keep an eye on it?

Because get rid of the builder will make my life much easier.

@sebcrozet
Copy link
Member

Not yet, it's still very experimental. It will likely end up in the ccd branch within a couple of weeks if it ends up working well.

@AndreaCatania
Copy link
Author

Ok thanks!

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

2 participants