dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
924 stars 106 forks source link

Unable to resize Shapes #139

Open ghost opened 7 years ago

ghost commented 7 years ago

Apologies if this is the wrong repo, but it looks like ncollide is the proper one to add file this under. I have code that looks like this:

let mut body = RigidBody::new_dynamic(Ball::new(1.0), 1.0, 0.3, 0.6);
let handle = physics_world.add_rigid_body(body);

I would like to dynamically resize the object later on. The shape is getting stored as ncollide::shape::ShapeHandle<nalgebra::Point3<{float}>, nalgebra::Isometry3<{float}>>. Since an nalgebra::Isometry3 struct is being used to store the state of the shape, only translation and rotation can be updated. It appears that if an nalgebra::Similarity3 struct were to be used instead, scaling could be set dynamically.

sebcrozet commented 7 years ago

This is issue applies to both nphysics and ncollide actually. Dynamically-resizing a shape has two non-trivial implications:

  1. Some collision detection algorithms might just not work (but I think most of them can easily be adapted).
  2. Dynamically resizing an object can invalidate a whole bunch of internal data of the physics engine due to the lack of smoothness of the scaling factor value (i.e. we can usually expect that translations and rotations are changed in a smooth way by the physics engine itself, or indirectly by the user by applying forces. A global scaling factor is usually exclusively controlled by the user so the collision object cannot be easily assimilated as an object subject to smooth deformations that depends on the interactions with the physical environment).

In any cases, this feature can be added, but one should keep in mind that changing the scaling factor of a shape is a very costly operation because some coherence data and pre-computed informations have to be recomputed at each rescale.

A simpler alternative than using a Similarity3 would be to allow the user to dynamically change the shape of a rigid body, e.g., with a .set_shape(...) method.