NewtonCollisionSetCollisionMode behavior change

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonCollisionSetCollisionMode behavior change

Postby Bird » Mon Jul 14, 2014 9:11 pm

Hi Julio,

I just synced to the latest version on GitHub and now my collision based painting no longer works.

During collision based painting, I first paint with a "phantom" body with NewtonCollisionSetCollisionMode set to 0 so that it doesn't effect any other bodies and use it to do the NewtonWorldForEachBodyInAABBDo tests. In previous versions of Newton this worked fine but now the phantom body does not detect contact with any other bodies within its AABB. Is this something you can change back to the previous behavior?

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Mon Jul 14, 2014 11:54 pm

There was a problem wit the collision mode with kinematic bodies.
It is better that we fix your system to work with the new method which is much better.
can you tell me what is the behavior that you need?

NewtonCollisionSetCollisionMode 0 should never interact with other bodies in the scene, are you using a kinematic body?
I am confuded how are you using NewtonWorldForEachBodyInAABBDo.

Oh I see you were using NewtonCollisionSetCollisionMode 0 but because the joint was generation contacts, you were using the contacts for object places.

I sound like the collsion need anoteh mode.
basically NewtonCollisionSetCollisionMode 0 is generates joint but no contacts
basically NewtonCollisionSetCollisionMode 1 is generates joint and contacts but do not collide (this I need to add)
basically NewtonCollisionSetCollisionMode 2 is generates joint and contacts and collide

the change I made is that collision mode 0 does no generate contacts by I can see how that is incomplete, when I was doing in the back on my mind I fell like something was missing
Ok I will add that mode.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 12:24 am

the change I made is that collision mode 0 does no generate contacts by I can see how that is incomplete, when I was doing in the back on my mind I fell like something was missing
Ok I will add that mode.


Excellent! Thanks very much. Whew :)

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 12:33 am

I am doing now, can you show me the code fragment you are using, so that I have an idea.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 12:49 am

when you set NewtonCollisionSetCollisionMode set to 0 before that meant no collision. but were you getting the joints?
because that mode did generate contact?

can you please tell me step by step there behavior that you expect?
the code now is more flexible and the behavior can be accommodate, I just need to know what it is expects.

Basically now the joint is always generated, that was not possible before, but make coding logic like trigger volumes more difficult
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 12:58 am

Julio Jerez wrote:I am doing now, can you show me the code fragment you are using, so that I have an idea.


Here's the basic code.

My body has that I pass to testForCollision() has NewtonCollisionSetCollisonMode set to 0. I want to be able to find out what other bodies are in it's AABB so I can know when it's not intersectin anything but I don't want it to cause any collision reaction with any other bodies in the scene while the engine is running. Basically the user drags this body around and when there are no collisions a new instance is painted.

-Bird

Code: Select all
bool IssacMeshOps::testForCollision (PhysicsBody * const pBody)
{

   // this body has NewtonCollisionSetCollisonMode set to 0
   
   BBox3f bbox = pBody->component->modelBound;
   dVector min( bbox.min[0], bbox.min[1], bbox.min[2] );
   dVector max( bbox.max[0], bbox.max[1], bbox.max[2] );

   NewtonWorldForEachBodyInAABBDo(world_, &min[0], &max[0], &IssacMeshOps::aabbCollisionCallback, pBody);
   return true;
}

int IssacMeshOps::aabbCollisionCallback (const NewtonBody * const body, void * const userData)
{   
   IssacEntity* entity = (IssacEntity*)(userData);
   if (!entity ) return 1;

   IssacEntity* otherEntity = (IssacEntity*) NewtonBodyGetUserData(body);
   if (!otherEntity ) return 1;

   const NewtonBody * const otherBody = (NewtonBody*)entity->component->userData;
   if(!otherBody) return 1;

   // not interested in self collision
   if( body == otherBody ) return 1;

   NewtonCollision* collisionA = NewtonBodyGetCollision(body);
   NewtonCollision* collisionB = NewtonBodyGetCollision(otherBody);
   NewtonWorld* const world = NewtonBodyGetWorld(body);

   dMatrix poseA;
   NewtonBodyGetMatrix(body, &poseA[0][0]);

   dMatrix poseB;
   NewtonBodyGetMatrix(otherBody,&poseB[0][0]);

   if( NewtonCollisionIntersectionTest(world, collisionA, &poseA[0][0], collisionB, &poseB[0][0],0) )
   {
      // ignore contact with no penetration
      const int maxSize = 2;
      dFloat contacts[maxSize * 3];
      dFloat normals[maxSize * 3];
      dFloat penetrations[maxSize];
      dLong attrbA[maxSize * 3];
      dLong attrbB[maxSize * 3];
      int contactCount = NewtonCollisionCollide(world, maxSize,
                                      collisionA, &poseA[0][0],
                                      collisionB, &poseB[0][0],
                                      &contacts[0],
                                      &normals[0],
                                      &penetrations[0],
                                      &attrbA[0],
                                      &attrbB[0],
                                      0);
      if(contactCount)
         entity->bodyDesc.collisionInfo.collisionList.push_back( (PhysicsBody*)(otherEntity) );
   }
   return 1;
}
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 1:26 am

Here's a video of how it works with the older versions of Newton. The blue cow is the "phantom" body with NewtonCollisionSetCollisonMode set to 0. As the user drags it, I keep asking Newton if it is intersecting another body. If the answer is no, then a new cow instance is generated. As in the video, I need it to work when the engine is running and when it is not

http://hurleyworks.com/media/flash/AP_Collision_Paint3/AP_Collision_Paint3.html

It's way past my bedtime, so I'm signing off for now :)

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 11:39 am

where is aabbCollisionCallback called from?
Never Mind I see it. I think that behavior can be recreated with out make any change.

I will try to recreated tonight in the sandbody, I have one question, in eh video is the cow the pBody
in bool IssacMeshOps::testForCollision (PhysicsBody * const pBody)

the part that is no clear to me is that pBody is of type PhysicsBody * const pBody and is the user data to the callback
bu in the callback you cant it to IssacEntity*, is IssacEntity teh base class of PhysicsBody ?

also I assume you do this for compound and single collision objects. is the cow in a compound body?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 12:05 pm

for what I can see, the solution to this is quite essay. and you do no even have to use NewtonWorldForEachBodyInAABBDo if pBody is a object is the work.

I will write in the same function bool IssacMeshOps::testForCollision (PhysicsBody * const pBody)
tonigh after I test it in the sandbox, no change had to be made to the engine at all.

as a Matter of fact the change I made was to eliminate the same thong you are doing. basically the "phantom" should tell what bodies are iteration with him at all time.

in fact maybe you can do it your self by looking at the the trigger manager here is teh code
C:\tmp\newton-dynamics\packages\dCustomJoints\CustomTriggerManager.cpp
line 52


Code: Select all
bool IssacMeshOps::testForCollision (PhysicsBody * const pBody)
{
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (pBody); joint; joint = NewtonBodyGetNextContactJoint (pBody, joint)) {

      int isActive = NewtonJointIsActive (joint);
   
      if (isActive) {
// teh code will he thsi like if the  phantonm body is colling with the othe the body

      NewtonBody* const body0 = NewtonJointGetBody0(joint);
      NewtonBody* const body1 = NewtonJointGetBody1(joint);
      NewtonBody* const otherbody = (body0 != pBody) ? body0 : body1;
// do what you nee tod do
....
}


please see if this make sense to you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 12:23 pm

I will try to recreated tonight in the sandbody, I have one question, in eh video is the cow the pBody
in bool IssacMeshOps::testForCollision (PhysicsBody * const pBody)

Yes, it's the cow body with NewtonCollisionSetCollisonMode set to 0. I create a new instance from it in LW once it is not colliding with any other body.

the part that is no clear to me is that pBody is of type PhysicsBody * const pBody and is the user data to the callback
bu in the callback you cant it to IssacEntity*, is IssacEntity teh base class of PhysicsBody ?

PhysicsBody is the base class of IssacEntity. My project can support multiple physics engines so clients of my library can use PhysicsBody class without knowing what engine is being used. IssacEntity just encapsulates the callbacks I need like applyForceAndTorqueCallback()

also I assume you do this for compound and single collision objects. is the cow in a compound body?

It's just a single collision object in the video but I need to do it for compound shapes too. I can't paint with compound shapes currently because of this problem
http://newtondynamics.com/forum/viewtopic.php?f=26&t=8598

Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 12:53 pm

Bird wrote:
also I assume you do this for compound and single collision objects. is the cow in a compound body?

It's just a single collision object in the video but I need to do it for compound shapes too. I can't paint with compound shapes currently because of this problem
http://newtondynamics.com/forum/viewtopic.php?f=26&t=8598
Bird

Ok yes I tough the test volume was the convex hull of the cow, I asked to be sure.

did you look at the code sniped? I believes that solves the problem of detecting if the body is interfering with the volume.
then you do the cast test rest for each hit as you where doing.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 12:54 pm

I thought I fixed NewtonCollisionClosestPoint() are you sure that is still broken?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 1:06 pm

Julio Jerez wrote:I thought I fixed NewtonCollisionClosestPoint() are you sure that is still broken?

No, I'm not sure. I will test again now and also try out the code you posted.

Thanks for the help!

-Bord
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Bird » Tue Jul 15, 2014 1:55 pm

did you look at the code sniped? I believes that solves the problem of detecting if the body is interfering with the volume.
then you do the cast test rest for each hit as you where doing

That seems to work ok but it only finds contacts while the engine is running. I need something that works while the engine is not updating too.

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: NewtonCollisionSetCollisionMode behavior change

Postby Julio Jerez » Tue Jul 15, 2014 2:02 pm

would it help is I add a broaphase update funtion?

bascially a call to update the collision that can be made anytime.
so when you move one or more bodies you can call that and the broadphase will be updated.
Newton 1.xx and 2.xx had that functionality and the I removed. but there is not reason why no to have again.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests