[Solved] How to toggle body collidable?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

[Solved] How to toggle body collidable?

Postby AntonSynytsia » Thu Jan 02, 2014 8:30 pm

NewtonSetBodyCollidable function does not prevent the body from colliding with the other bodies. Could anyone, please, provide an example of how to toggle the body collidable?
Last edited by AntonSynytsia on Fri Jan 03, 2014 8:32 pm, edited 3 times in total.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby AntonSynytsia » Thu Jan 02, 2014 10:30 pm

I guess I figured this one out:
Use NewtonBodyEnableSimulation and NewtonBodyDisableSimulation.

Edit: but the body will stop moving too.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby JoeJ » Fri Jan 03, 2014 5:55 am

See there: http://newtondynamics.com/forum/viewtopic.php?f=11&t=7772

That's how you can do also more complex things like door bodies should not collide against player body but they should collide with all other stuff.
NewtonSetBodyCollidable maybe is meant for kinematic bodies only.

For the static body question simply set it's mass to zero.
If many bodies go and should stay static, you may wanna add them to scene collision to speed things up.

I'm not sure if there are better ways for anything of the above.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: How to toggle body collidable?

Postby Julio Jerez » Fri Jan 03, 2014 7:09 am

NewtonSetBodyCollidable should work, if it is not then I think that's a bug.

I see that Joe is correct for some reason I made SetCollidable only work for kinematic bodies by not for dynamics

this is the function for kinematic bodies
virtual void SetCollidable (bool state) {m_collidable = state;}

and this is for dynamics bodies
virtual void SetCollidable (bool state) {}

I do not remember why I did that, but can you change that to
virtual void SetCollidable (bool state) {m_collidable = state;}

and see if it does the job, then I made the change, it is in file
../coreLibrary_300\source\physics\dgDynamicBody.h
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to toggle body collidable?

Postby AntonSynytsia » Fri Jan 03, 2014 1:22 pm

Julio Jerez wrote:virtual void SetCollidable (bool state) {m_collidable = state;}
This does the job! Thank you :twisted:
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby AntonSynytsia » Fri Jan 03, 2014 2:24 pm

What about the compound bodies? The uncollidable state has no effect on them, except colliding uncollidable compound bodies results in massive force reaction and sometimes in a crash.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby Julio Jerez » Fri Jan 03, 2014 4:56 pm

What do you mean, the test for collidable does no depend of the collsionb sha[e


Code: Select all
            dgBody* const linkBody = cell->m_bodyNode;
            dgAssert ((constraint->m_body0 == body) || (constraint->m_body1 == body));
            dgAssert ((constraint->m_body0 == linkBody) || (constraint->m_body1 == linkBody));
            const dgContact* const contact = (constraint->GetId() == dgConstraint::m_contactConstraint) ? (dgContact*)constraint : NULL;
            dgInt32 ccdMode = contact ? (body->m_continueCollisionMode | linkBody->m_continueCollisionMode) : 0;
            if (linkBody->IsCollidable() && (!contact || contact->m_maxDOF || ccdMode)) {
//emit collsion air here


check If the body is in collidable first, and only when the body is collidable that the contacts are passed to the solver.
the test is not concerned wit the collision shape.

can you modified any of the sand bob demo to show me what you mean?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to toggle body collidable?

Postby AntonSynytsia » Fri Jan 03, 2014 5:24 pm

Create a body from the compound collision and call NewtonSetBodyCollidable(bodyPtr, 0). By doing this, we expect the body to go through other bodies, but as of result it doesn't. The NewtonSetBodyCollidable() function works for the bodies created by single collision, but not for the bodies created by compound collision.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby Julio Jerez » Fri Jan 03, 2014 7:26 pm

Oh I see, yes you and JoeJ are right, the function IsCollidable is named wrong.
That function is only for kinematic bodies, making the change that I told you will actually break the engine real bad.

In fact ther are few ways to make a body non collidable, one is by material by rejection the contact in the callback but those are too expensive.
the best way is by setting the shape to be non collidable. Let me fix the API and I post again.
Sorry for misleading you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to toggle body collidable?

Postby AntonSynytsia » Fri Jan 03, 2014 7:30 pm

:roll: :twisted:
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: How to toggle body collidable?

Postby Julio Jerez » Fri Jan 03, 2014 8:04 pm

Ok here is the proper way of doing it
Code: Select all
NewtonCollision* const collision = NewtonBodyGetCollision (m_body);
NewtonCollisionSetCollisonMode(compound, 0);

I also renamed those two functions in the body interface, so that there is no confusion, to these respective names
Code: Select all
int NewtonKinematicBodyGetCollidable (const NewtonBody* const body);
void NewtonKinematicBodySetCollidable (const NewtonBody* const body, int collidableState);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

[Solved] How to toggle body collidable?

Postby AntonSynytsia » Fri Jan 03, 2014 8:32 pm

Thank you :)
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron