## Body move and SetTraformCallback

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

### Body move and SetTraformCallback

Hi, again with a newbie question.

After the creation of body and collision, i've to move
all things. I've set a force 9.81 * mass in the
Force and torque callback, but my object is stopped
and doesn't move at all.

Note that my object is flying. So the gravity would
make it move down...or not?

I say that it doesn't move because of the trasform
matrix callback isn't ever called.

Is there anything else to do?

Thanks again.

Note: i call the NewtonUpdate function and the body
is unfreezed. The NewtonBodySetMatrix is not been used
(i think is identity).
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

If the body is unfreezed, and if you correctly set the callback ForceAndTorque and if you call correctly the NewtonUpdate... so, there is no evident reasons on the fact that your body doesn't fall down.

Please, post some portion of the code and/or give us more details to let us the possibility to figure out where is the problem.

Ciao,
Gianluca
Gianluca

Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

### Re: Body move and SetTraformCallback

This is true at all.

So i've created a collision box + body and tested.
The box correctly falls down.My dice don't.
Code: Select all
`// dice (id = 15)   tmp = CreateNewtonCustomObjFromIrrSceneId(scenehandle,15);   myDice = tmp;   NewtonBodySetFreezeTreshold(tmp->body, 0.0000001f, 0.0000001f, 50);    NewtonBodySetMassMatrix (tmp->body, 100.0f, 1.0f, 1.0f, 1.0f);   NewtonBodySetAutoFreeze(tmp->body,0);   NewtonWorldUnfreezeBody(nWorld, tmp->body);   NewtonBodySetMaterialGroupID(tmp->body,i);   NewtonBodySetTransformCallback(tmp->body, SetMeshTransformEvent);   NewtonBodySetForceAndTorqueCallback(tmp->body, ApplyForceAndTorqueEvent);      // temp box   NewtonCollision *tmpcol = NewtonCreateBox(nWorld, 40.0f, 40.0f, 40.0f, NULL);   NewtonBody *tmpbody = NewtonCreateBody(nWorld,tmpcol);   tmp = new NewtonCustomObj();   tmp->body = tmpbody;   tmp->collision = tmpcol;   othersIdArray.insert(50);   othersMap.insert(50,tmp);   NewtonBodySetFreezeTreshold(tmp->body, 0.0000001f, 0.0000001f, 50);    NewtonBodySetMassMatrix (tmp->body, 100.0f, 1.0f, 1.0f, 1.0f);   NewtonBodySetAutoFreeze(tmp->body,0);   NewtonWorldUnfreezeBody(nWorld, tmp->body);   NewtonBodySetMaterialGroupID(tmp->body,i);   NewtonBodySetTransformCallback(tmp->body, SetMeshTransformEvent);   NewtonBodySetForceAndTorqueCallback(tmp->body, ApplyForceAndTorqueEvent);`

The only difference is collision creation,
the dice is a NewtonCreateConvexHull.
The creation is done in this function from Irrlicht.

Code: Select all
`NewtonCustomObj *MyDiceApp::CreateNewtonCustomObjFromIrrSceneId(ISceneManager * sceneHandle,irr::c8 id){   NewtonCustomObj *ret = new NewtonCustomObj();   ISceneNode *sn = sceneHandle->getSceneNodeFromId(id);   if ((sn == 0 ) || (sn->getType() != scene::ESNT_MESH))      return(0);      IMeshSceneNode *msn = static_cast<IMeshSceneNode*>(sn);   IMesh *m = msn->getMesh();   if (m == 0)      return(0);   irr::u32 nMeshBuffer = 0; //Mesh Buffer count   IMeshBuffer *mesh_buffer = 0;   dFloat *vertices;   u32 nVertices = 0;      for( nMeshBuffer=0 ; nMeshBuffer < m->getMeshBufferCount() ; nMeshBuffer++ )   {      nVertices += m->getMeshBuffer(nMeshBuffer)->getVertexCount();   }   vertices = (dFloat*)iaf->allocate(nVertices * 3);   u32 tmpCounter = 0;      matrix4 mat = sn->getRelativeTransformation();   vector3df scaleVect = sn->getScale();   for( nMeshBuffer=0 ; nMeshBuffer < m->getMeshBufferCount() ; nMeshBuffer++ )   {      mesh_buffer = m->getMeshBuffer(nMeshBuffer);      if (mesh_buffer->getVertexType() != EVT_STANDARD)         return 0;      S3DVertex *s3vertices = (S3DVertex*)mesh_buffer->getVertices();            vector3df irrOrig,irrTrasf;            for(irr::u32 i=0; i<mesh_buffer->getVertexCount(); i++)      {         vertices[tmpCounter++] = s3vertices[i].Pos.X * scaleVect.X;         vertices[tmpCounter++] = s3vertices[i].Pos.Y * scaleVect.Y;         vertices[tmpCounter++] = s3vertices[i].Pos.Z * scaleVect.Z;      }    }   //Create Newton collision object   NewtonCollision *tmp = NewtonCreateConvexHull(nWorld,nVertices,vertices,sizeof(float)*3,NULL);   //delete vertices   iaf->deallocate(vertices);         NewtonBody *body = NewtonCreateBody(nWorld, tmp);   dFloat *matArray = mat.pointer();   NewtonBodySetMatrix(body,matArray);      ret->body = body;   ret->collision = tmp;   return(ret);}`
Last edited by Kapitan on Sun Nov 02, 2008 7:52 am, edited 1 time in total.
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

A pretty image.

Newton.image.JPG (55.92 KiB) Viewed 5525 times
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

I'm switching to sdk 2.0, some changes occurred, the time
to set all things and i'll be back to this problem (i hope has
been solved).
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

Ok, now the forceandtorque callback is called correctly
on my dice, but still no move.

SetAutoSleep is 0, SetFreezeState is 0, but FreezeThreshold
has been removed so how can i control it ?

EDIT: NewtonGetSleepState called on my frozed object returns
1, so the object is sleeping, but how to wake up?
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

they wake up automaticly now by default when you apply force, now you get the forcetorque callback called each frame rather than only when the body is active.
Help improving the Newton Game Dynamics WIKI

JernejL

Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

### Re: Body move and SetTraformCallback

So, let me summarize:
- you moved to Newton 2.0
- now, the ForceAndTorqueCallback is called at each NewtonUpdate on your Dice body
- and the Dice body is still frozen and doesn't respond to the applied Force
Is it right ???
If yes, try to understand:
- how you add force/torque ?? (if you simply call NewtonAddTorque is correct, if you do somethingelse please post it here)
- Are you sure that the un-movable Dice body is within the world dimensions ??? (did you call NewtonWorldSetSize ???)
Gianluca

Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

### Re: Body move and SetTraformCallback

I don't Believe it!!!

Was the NewtonSetWorldSize!!!

It seems to me that something was missing.

Thanks guys.
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

But i don't think the trasform matrix is ready to be applied
to irrlicht directly.

I'm in the TrasformCallback and while all things
moving, the scale diagonal continues to do up and down.

Others test coming...

For example.

If i apply a torque in the applyforceandtorque callback
the collision body gets bigger than when there was
not torque, as i modify collision vertex, but clearly
is not.
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

I think is a bug, or have not understand the torque.

If i set a force with NewtonBodyAddForce my
collision is as usual and work perfectly.

If i set a torque the scale diagonal of the trasformation
matrix has imperfections,
the 3 direction moves random and my collision is modified
and has wrong behaviour.

If you want i'll send you the .exe to see, my project is
made for university and so it can be distributed .
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

for a gravity object teh torque is zero.
What are you doing?
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Body move and SetTraformCallback

Yes but the problem is that when it collides
the torque is created by collision...and it's the same....

And if i would set a custom impulse on a gravity object? Can i?

Tomorrow i'll post other photos so you can see..
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

Here is the code:

1) Creation of Collision
Code: Select all
`// add points - part of CreateNewtonCustomObjFromIrrSceneIdfor(irr::u32 i=0; i<mesh_buffer->getVertexCount(); i++)      {                  vertices[tmpCounter++] = s3vertices[i].Pos.X;         vertices[tmpCounter++] = s3vertices[i].Pos.Y;         vertices[tmpCounter++] = s3vertices[i].Pos.Z;      }      //Create Newton collision objectNewtonCollision *tmp = NewtonCreateConvexHull(nWorld,nVertices,vertices,sizeof(float)*3,0.50f,NULL);   //delete verticesiaf->deallocate(vertices);if (tmp != NULL){   NewtonBody *body = NewtonCreateBody(nWorld, tmp);         if (body != NULL)   {      NewtonBodySetUserData(body,sn);      ret = new NewtonCustomObj();      dFloat *matArray = mat.pointer();      NewtonBodySetMatrix(body,matArray);             ret->body = body;      ret->collision = tmp;   }}`

2) The call and the set of Newton Mass and Callback
Code: Select all
`// the calltmp = CreateNewtonCustomObjFromIrrSceneId(scenehandle,15);if (tmp != NULL){   myDice = tmp;   NewtonBodySetAutoSleep(tmp->body,1);   NewtonBodySetFreezeState(tmp->body,0);            dFloat *inertia = (dFloat*)iaf->allocate(3);   dFloat *origin = (dFloat*)iaf->allocate(3);   NewtonConvexCollisionCalculateInertialMatrix(tmp->collision,inertia,origin);   NewtonBodySetMassMatrix(tmp->body,kDiceMass,kDiceMass*inertia[0],kDiceMass*inertia[1],kDiceMass*inertia[2]);   iaf->deallocate(inertia);   iaf->deallocate(origin);   NewtonBodySetTransformCallback(tmp->body, SetMeshTransformEvent);   NewtonBodySetForceAndTorqueCallback(tmp->body, ApplyForceAndTorqueEvent);}`

3) The Omega Applied
Code: Select all
`// the inputif(event.KeyInput.Key == KEY_RETURN){   dFloat *velImpulse = (dFloat*)iaf->allocate(3);   //dFloat *centre = (dFloat*)iaf->allocate(3);   velImpulse[0] = 0.0f; velImpulse[1] = 5.0f; velImpulse[2] = 10.0f;   //centre[0] = 0.0f; centre[1] = 0.0f; centre[2] = 0.0f;               NewtonBodySetOmega(myDice->body,velImpulse);  // NewtonBodySetVelocity doesn't made problems!!! Problems are only with torques?   iaf->deallocate(velImpulse);   //iaf->deallocate(centre);}`
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

### Re: Body move and SetTraformCallback

A snapshot.

When i press enter (see previous post,
i simply apply an omega to the dice),
the collision mesh changes immediately to this.

In debug i've tried with a NewtonBodySetOmega,
with a NewtonBodySetTorque and when a collision
make the dice rotate, and in any case the matrix
passed in the Trasform Callback has the scale
diagonal set to one, as if it was in 1.53.

The internal mesh (from irrlich) doesn't change
because i've not applied the scale in the Trasform
callback.

Newton.error.after.JPG (56.78 KiB) Viewed 5366 times
Kapitan

Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Next