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

Partially integrated collision groups into nphysics #58

Merged
merged 11 commits into from Apr 6, 2016
Merged

Partially integrated collision groups into nphysics #58

merged 11 commits into from Apr 6, 2016

Conversation

Kerollmops
Copy link
Sponsor Contributor

Don't really know if this integration is good for you, I didn't implement this from #55:

the modification will have no effect if it is performed after the rigid body has been added to the scene). If the rigid body is static, the corresponding group should be set automatically after the user modified the group

@@ -94,7 +94,7 @@ impl<'a> Testbed<'a> {
minor_version: 1
};
let window =
match RenderWindow::new(mode, "nphysics 2d demo", Close, &setting) {
match RenderWindow::new(mode, "nphysics 2d demo", Close, &ContextSettings::default()) {
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did I have to do about that ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to keep your modification. I believe the setting variable initialization just above could be removed now.

@@ -244,7 +247,7 @@ impl<N: Scalar> RigidBody<N> {
}

/// Creates a new rigid body that can move.
pub fn new_dynamic<G>(shape: G, density: N, restitution: N, friction: N) -> RigidBody<N>
pub fn new_dynamic<G>(shape: G, density: N, restitution: N, friction: N, groups: Option<RigidBodyCollisionGroups>) -> RigidBody<N>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to add groups as a constructor argument. For many applications, a custom value is not needed at all.


/// Mutable reference to the collision groups of this rigid body.
#[inline]
pub fn collision_groups_mut(&mut self) -> &mut RigidBodyCollisionGroups {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure but I think it is better not to return a mutable reference, but instead have something like .set_collision_groups(&mut self, new_groups: &mut RigidBodyCollisionGroups). In the future, the rigid body will have to know that the groups have been tempered with in order to notify the collision detectors.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep collision_groups(&self) -> &RigidBodyCollisionGroups ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, immutable access might be useful and has no impact on the physics engine anyway.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want new_groups: &mut RigidBodyCollisionGroups to be mutable ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't, sorry, my mistake ^^ It should be new_groups: RigidBodyCollisionGroups of course.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Implemented like this now ^^

@@ -272,7 +278,8 @@ impl<N: Scalar> RigidBody<N> {
pub fn new(shape: Arc<Box<Repr<Point<N>, Matrix<N>>>>,
mass_properties: Option<(N, Point<N>, AngularInertia<N>)>,
restitution: N,
friction: N)
friction: N,
groups: RigidBodyCollisionGroups)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one should not have groups on its constructor either. On this method, the static or dynamic status of the rigid body is automatically deduced from mass_properties. If it is set to None, then the rigid body is static. It is dynamic otherwise.

@Kerollmops
Copy link
Sponsor Contributor Author

Do you think fn get_internal_collision_groups(&self) -> &CollisionGroups is a good function name ? or is a good thing to have ?

@sebcrozet
Copy link
Member

It is a must-have so that the user can perform queries on the CollisionWorld from ncollide with those groups (without having to use the World from nphysics as an intermediate).

As for the name, I'd say collision_groups(...) is enough... unless you find it confusing in which case I am okay with internal_collision_groups(...). The choice is yours! In any case, the get_ prefix has to be dropped as it is not idiomatic in rust.

@Kerollmops
Copy link
Sponsor Contributor Author

The function is mainly there to help world::add_body 😄
But you are right, the users will need this too !

@Kerollmops
Copy link
Sponsor Contributor Author

Do you think world/collision_groups.rs is in the right place ?

@sebcrozet
Copy link
Member

Actually, it might be even clearer to name it as_collision_groups(...) (prefix as_), or, even better, to implement the Deref trait instead !

@sebcrozet
Copy link
Member

Since it is directly related to rigid bodies, it should go on object/rigid_body_collision_groups.rs (btw. as a convention the file name usually matches the name of the structure it defines) and be re-exported by object/mod.rs.

#[inline]
pub fn internal_collision_groups(&self) -> &CollisionGroups {
&self.collision_groups
pub fn as_collision_groups(&self) -> &CollisionGroups {
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep this function ?

// internal reserved static group id
const STATIC_GROUP_ID: usize = 29;

/// TODO: better explanations or redirect user to `ncollide` documentation ?!?
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do I do here for the doc ? ❓ ❔ ⁉️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment I suggest you just remove the TODO line and keep your rest of your comment. I will have to reword it when sensors will be added anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same remark about all the FIXME better documentation bellow.)

@Kerollmops
Copy link
Sponsor Contributor Author

What do I do about that too ?

the modification will have no effect if it is performed after the rigid body has been added to the scene). If the rigid body is static, the corresponding group should be set automatically after the user modified the group.

@sebcrozet
Copy link
Member

Your current implementation already does that:

the modification will have no effect if it is performed after the rigid body has been added to the scene).

The rest is irrelevant as long as a full integration (allowing collision groups changes at any time) is not done.

@Kerollmops
Copy link
Sponsor Contributor Author

Ok, see you later for a better implementation!
Will you publish this version of collisionGroups integration for the moment ?

@@ -9,7 +9,7 @@ use ncollide::utils::data::hash_map::{HashMap, Entry};
use ncollide::utils::data::hash::UintTWHash;
use ncollide::broad_phase::{BroadPhase, DBVTBroadPhase};
use ncollide::narrow_phase::ContactSignalHandler;
use ncollide::world::{CollisionWorld, CollisionObject, CollisionGroups};
use ncollide::world::{CollisionWorld, CollisionObject/*, CollisionGroups*/};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just remove this comment? Then I should be ready for a merge.

@sebcrozet sebcrozet changed the title Partially integrated collision groups into nphysics, need many fixes and advices ! Partially integrated collision groups into nphysics Apr 6, 2016
@sebcrozet sebcrozet merged commit e94c2c9 into dimforge:master Apr 6, 2016
@sebcrozet
Copy link
Member

Thanks!

This will be published with a minor version number change, namely 0.2.1, as this does not includes breaking changes.

@Kerollmops
Copy link
Sponsor Contributor Author

Thanks to you !
I'm ok with that, have a good day/night 😄

@Kerollmops
Copy link
Sponsor Contributor Author

STOP ! there is a big problem !
all examples are fucked up !
Due to my bad implementation of collisionGroups !

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

Successfully merging this pull request may close these issues.

None yet

2 participants