NewtonCollisionSetMatrix / offset matrix have no effect

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

NewtonCollisionSetMatrix / offset matrix have no effect

Postby Shaderman » Sat Jan 07, 2017 4:34 am

Hi.

There seems to be a problem with the offset of collision matrices. I've tested with the Primitive Collision demo and changed two files:

newton-dynamics\applications\demosSandbox\sdkDemos\toolBox\PhysicsUtils.cpp line 669.

Change: pass offset matrix to NewtonCreateBox (was NULL):

Code: Select all
      case _BOX_PRIMITIVE:
      {
         // create the collision
         dMatrix offsetMatrix(dGetIdentityMatrix());
         offsetMatrix.m_posit.m_x = 0.5f;

         collision = NewtonCreateBox (world, size.m_x, size.m_y, size.m_z, 0, &offsetMatrix[0][0]);
         break;
      }


newton-dynamics\applications\demosSandbox\sdkDemos\demos\PrimitiveCollision.cpp line 108.

Change: Trying to change the offset matrix with NewtonCollisionSetMatrix.

Code: Select all
   // create the shape and visual mesh as a common data to be re used
   NewtonWorld* const world = scene->GetNewton();
   NewtonCollision* const collision = CreateConvexCollision (world, dGetIdentityMatrix(), size, type, materialID);
   dMatrix offsetMatrix(dGetIdentityMatrix());
   offsetMatrix.m_posit.m_x = 0.5f;
   NewtonCollisionSetMatrix(collision, &offsetMatrix[0][0]);


I expect the collision mesh to be moved with either change, but they have no effect. I presume the problem is somewhere in dgCollisionInstance, but I'm lost :oops:
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Julio Jerez » Sat Jan 07, 2017 10:19 am

yes is supposed to have not effect. the user collision take a transformation matrix as argument an the demo is using the entity matrix no the body matrix

as I remember that demo came about as a request from an Ogre engine user who wanted to use newton a pure collision system. If you look at function
Code: Select all
   static int CalculateContacts (const NewtonBody* const otherBody, void* const userData)
   {
      ShowCollisionCollide* const me = (ShowCollisionCollide*)userData;
      if (me->m_body != otherBody) {
         const int cMaxContacts = 15;
         dFloat contacts[cMaxContacts][3];
         dFloat normals[cMaxContacts][3];
         dFloat penetrations[cMaxContacts];
         dLong attributeA[cMaxContacts];
         dLong attributeB[cMaxContacts];
         NewtonWorld* const world = NewtonBodyGetWorld(otherBody);

         //NewtonBodyGetMatrix(me->m_body, &matrixA[0][0]);
         //NewtonBodyGetMatrix(otherBody, &matrixB[0][0]);
         DemoEntity* const entityA = (DemoEntity*)NewtonBodyGetUserData(me->m_body);
         DemoEntity* const entityB = (DemoEntity*)NewtonBodyGetUserData(otherBody);

         const dMatrix& matrixA = entityA->GetRenderMatrix ();
         const dMatrix& matrixB = entityB->GetRenderMatrix (); 

         NewtonCollision* const collisionA = NewtonBodyGetCollision(me->m_body);
         NewtonCollision* const collisionB = NewtonBodyGetCollision(otherBody);

         int count = NewtonCollisionCollide (world, cMaxContacts, collisionA, &matrixA[0][0], collisionB, &matrixB[0][0],
                                    &contacts[0][0], &normals[0][0], penetrations, attributeA, attributeB, 0);

         dVector originColor (1.0f, 0.0f, 0.0f, 0.0f);
         dVector lineColor (0.0f, 0.0f, 1.0f, 0.0f);
         for (int i = 0; i < count; i ++) {

            dVector n (normals[i][0], normals[i][1], normals[i][2], 0.0f);
            dVector p0 (contacts[i][0], contacts[i][1], contacts[i][2], 0.0f);
            dVector p1 (p0 + n.Scale (0.5f));
            p0 = matrixA.UntransformVector(p0);
            p1 = matrixA.UntransformVector(p1);
            ShowMousePicking (p0, p1, originColor, lineColor);
         }
      }
      return 1;
   }

you will see that it is calling calculate collision for to shape relative the rendering matrix not relative to the rigid body. At some point was doing what you expect, taking the body matrix but that
was not what the person who requested wanted. you can change it to this
Code: Select all
         dMatrix matrixA;
         dMatrix matrixB; 
         NewtonBodyGetMatrix(me->m_body, &matrixA[0][0]);
         NewtonBodyGetMatrix(otherBody, &matrixB[0][0]);
         NewtonCollision* const collisionA = NewtonBodyGetCollision(me->m_body);
         NewtonCollision* const collisionB = NewtonBodyGetCollision(otherBody);

         int count = NewtonCollisionCollide (world, cMaxContacts, collisionA, &matrixA[0][0], collisionB, &matrixB[0][0],
                                    &contacts[0][0], &normals[0][0], penetrations, attributeA, attributeB, 0);
 

but then the contacts will be on the body collision and they are not moving with the mouse.

That demo is a legacy from newton 1.xx when the compound and scene collision was not as developed as it is in latter versions.
if I have to use newton for pure collision system, I would use a scene or a compound collision.
you can create and single scene collision attach it to a kinematic body, them you can add and remove collision shapes at will and use the handle of each child shape as the control proxy of the shape.
Since the matrix of each shape is local to the scene collision, they act a global matrix. and you can move them around at will.

on that demo each shape waste a full rigid body and fort the engine to do a lot of house keeping
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Shaderman » Sat Jan 07, 2017 2:54 pm

Julio Jerez wrote:you will see that it is calling calculate collision for to shape relative the rendering matrix not relative to the rigid body.

Thanks Julio, this makes sense now and I was able to work around it :)

Just another question, not related to this topic. I believe I read somehing about the material system being reworked but can't find that post. It probably was an old post and the material system has already been reworked. Are there plans to change the current system?
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Julio Jerez » Sat Jan 07, 2017 3:16 pm

Shaderman wrote:I believe I read somehing about the material system being reworked but can't find that post. It probably was an old post and the material system has already been reworked


oh that was long time ago, for newton 2.xx.
that was when I added the concept of collision instance.
before that, newton 1.xx did not have the ability to discriminate collision shapes, only collision tree had the option of a collision id per face.
by adding collision instance, each collision now have its own user data and collision ID.
this can be used to design a material system by the end application in any way the application wants.
before that only the graph based system was possible the rigid body as the nodes.

Now an application in a callback can get the collision id or collision user data of the two colliding instances and used that to pass the material property of that contact point.

this allow for shape base material system like all other engine do, but also allows for graph based if the application make a hash map the use the collision id to get the property form tow different.

I still let the old material system material because if can be used for course granularity collision.
for example you can set layers in which a set of bodies with one material ID do not interact with a set of bodies with a different ID because they respond to different callback.

To summarize, the old material system is there and works as it has always worked but an application can override it by setting one callback and setting all body IDs to the same value them use the collision shape ID to write its own material system.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Shaderman » Sun Jan 08, 2017 5:32 pm

Thanks for the detailed answer Julio. I think it'll be not too hard to make the material system work the way I want it to be.
Before I start working on it, I need to solve something else though. Calling functions like NewtonBodySetForce still have no effect when called from the engines LUA callbacks which run async from the engines main thread.
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Sweenie » Mon Jan 09, 2017 3:32 am

Are you calling NewtonBodySetForce from within the NewtonApplyForceAndTorque callback?
I think that still is a requirement.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonCollisionSetMatrix / offset matrix have no effect

Postby Shaderman » Mon Jan 09, 2017 4:33 pm

Sweenie wrote:Are you calling NewtonBodySetForce from within the NewtonApplyForceAndTorque callback?
I think that still is a requirement.


Yes I think it's still required, but i had to find a way to pass data to that Newton callback. Taking dNewtonDynamicBody::OnForceAndTorque as example and extra functions to pass data, it's almost working. Now I just need to figure out why that force callback only affects a single object and not the expected one :oops:

Thanks for your help Sweenie.
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest

cron