Callback ObjectTransform and Update physic position

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Callback ObjectTransform and Update physic position

Postby telmopereira » Mon Apr 19, 2010 1:39 pm

Hello,

I have 2 questions.

First is a doubt about the code i will post next. I am using Irrlicht and Newton. When i create a body i draw it graphically and then among many other things i do this:

....
Code: Select all
NewtonBodySetTransformCallback(p_body, setObjectTransformCallback); 
NewtonBodySetForceAndTorqueCallback(p_body, applyForceTorqueCallback);

....

Code: Select all
void vehi_hdRepresentation::setObjectTransformCallback(const NewtonBody* body, const float* matrix)
{
   vehi_hdRepresentation* hdRep = (vehi_hdRepresentation *)NewtonBodyGetUserData(body);
 
        matrix4 mat;
   memcpy(mat.pointer(), matrix, sizeof(float)*16);
        if(p_irrSceneNode)
   {
                p_irrSceneNode->setPosition(mat.getTranslation());
      p_irrSceneNode->setRotation(mat.getRotationDegrees());
   }
}


I saw this in some tutorial. So, as i can understand what is happening is that Newton knows when there is some transformation made to an object, and call the function that i defined : setObjectTransformCallback. this function as one argument called matrix, that i believe that is Newton body matrix, am i right ?? Because of that all i need to do in my function is to change the position in the graphical way, since Newton make that automatically, its correct ??

Now, my second question:

I want to control one object with a haptic device, but let's just think that i am controlling one object with the keyboard. So every time i press a key the object make so moves. When this happen i guess that what i need to do is update graphically but also Physically, something that in the first question was made automatically by Newton. So what i did was something like:

Code: Select all
void vehi_hdRepresentation::hapticTransformMatrixChanged(const matrix4& mat)
{
        if(p_irrSceneNode)
      p_irrSceneNode->setPosition(vector3df(p_pos.X,p_pos.Y, p_pos.Z));

        if(p_body)
   {
               /** First solution **/
                matrix4 matTemp;
      NewtonBodyGetMatrix(p_body, matTemp.pointer());
      matTemp.setTranslation(p_pos);
      NewtonBodySetMatrix(p_body, matTemp.pointer());

             /** Second solution **/
              NewtonBodySetMatrix(p_body, mat.pointer());

}


Notice that p_pos is the actual position of the object that i am controlling (is obtained with haptic device API). The matrix passed as argument in this function is the matrix that gives the actual position of the object (also obtained with haptic device API). I try out both solutions and in both happens the same thing...the application crash's !!! What i am doing wrong? Anyone have any idea why application crashs?

Thanks,

Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Callback ObjectTransform and Update physic position

Postby Julio Jerez » Mon Apr 19, 2010 2:00 pm

are you the same person who posted a similar quetsion last week?

There have to be a bug some where, I said if you could post a small test that I can look at,
usually these error are end user error, but is is hard to figure out from a corde fragment or a video.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Callback ObjectTransform and Update physic position

Postby telmopereira » Mon Apr 19, 2010 2:03 pm

Hi Julio.

Yes, i thought that i complicated to much that question, so i try out to simplify here. On that post you talk about use constraints, but i dont understand how that will help...

Thanks,
Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Callback ObjectTransform and Update physic position

Postby Julio Jerez » Mon Apr 19, 2010 2:06 pm

It will help because in the code fragment you posted I do not see anything that could generate a crash

Code: Select all
      matrix4 matTemp;
      NewtonBodyGetMatrix(p_body, matTemp.pointer());
      matTemp.setTranslation(p_pos);
      NewtonBodySetMatrix(p_body, matTemp.pointer());
     


there is nothing wrong there. so unless the data is wrong, or the pointer to the body is illegal, It is dififcult to see what is wrong.
The only thing I can thing off is if the orientation part of the matrix correct?


Using constraingh is the correct way to deal with dierect improt in physics base simulation, But let us fuccus on teh later,
if there is a Bug change teh way of doing will not solve it.
I can tell you afte we get teh bug fixed hwo and why a contraint will help and will make it better.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron