Newton + Irrlicht crash problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Newton + Irrlicht crash problem

Postby Julio Jerez » Tue Apr 27, 2010 6:14 pm

no way with 1.53
1.53 does no exist anymore.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton + Irrlicht crash problem

Postby telmopereira » Tue Apr 27, 2010 9:52 pm

I try out to move to Newton 2.18, and i am having problems with "NewtonMaterialSetCollisionCallback"

In Newton 1.53 i do something like this:

NewtonMaterialSetCollisionCallback (p_world, idMat1, idMat2, NULL, beginDefaultContactCallback, processDefaultContactCallback, endDefaultContactCallback);

Now in 2.18 i remove the last argument:

Code: Select all
NewtonMaterialSetCollisionCallback (p_world, idMat1, idMat2, NULL, beginDefaultContactCallback, processDefaultContactCallback);

int vehi_hdRepresentation::beginDefaultContactCallback(const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1)
{
   contactHD = 0;
   contactProcessed = false;
   int id0 = NewtonBodyGetMaterialGroupID(body0);
   int id1 = NewtonBodyGetMaterialGroupID(body1);

   vehi_physics* physics = vehi_register::AppManager->getPhysics();
   vehi_materialData* matData= physics->getMaterialData();

   stringc matName = "";
   matName = matData->getName(id0);
   if (strcmp(matName.c_str(), "haptic")==0)
          contactHD = ((vehi_hdRepresentation*) NewtonBodyGetUserData(body0));
   
   else
   {
      matName = matData->getName(id1);
      if (strcmp(matName.c_str(), "haptic")==0)
         contactHD =  ((vehi_hdRepresentation*) NewtonBodyGetUserData(body1));
   }
   return 1;
}

int vehi_hdRepresentation::processDefaultContactCallback(const NewtonMaterial* material, const NewtonContact* contact)
{
   contactProcessed = true;
   render();
   contactHD = 0;
   contactProcessed = false;
   return 1;
}


The problem is that i receive an error : "C2664: 'NewtonMaterialSetCollisionCallback' : cannot convert parameter 5 from 'int (__cdecl *)(const NewtonMaterial *,const NewtonBody *,const NewtonBody *)' to 'NewtonOnAABBOverlap'"

and i don't understand how works the NewtonOnAABBOverlap.

Can you please give me some help in how to transform this callback functions that i design for 1.53 to work now on 2.0 please?

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

Re: Newton + Irrlicht crash problem

Postby JernejL » Wed Apr 28, 2010 3:30 am

This wiki page explains all the changes to do with collision callback:

http://newtondynamics.com/wiki/index.ph ... 53_and_2.0

Additionally, read this page about forcetorque functionality changes:
http://newtondynamics.com/wiki/index.ph ... e_callback

It's all there. Let us know if you have any additional questions about it.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Newton + Irrlicht crash problem

Postby telmopereira » Wed Apr 28, 2010 9:12 am

Hi,

I saw that pages yesterday. One of my doubts is about OnAABBOverlap. In this page, http://newtondynamics.com/wiki/index.php5?title=NewtonContactBegin , its explain how works NewtonContactBegin for Newton 1.53 and i can't find something similar about OnAABBOverlap. Can you please show me one code example like i present before, but now using OnAABBOverlap instead of BeginContact ?

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

Re: Newton + Irrlicht crash problem

Postby JernejL » Wed Apr 28, 2010 9:24 am

telmopereira wrote:Hi,

I saw that pages yesterday. One of my doubts is about OnAABBOverlap. In this page, http://newtondynamics.com/wiki/index.php5?title=NewtonContactBegin , its explain how works NewtonContactBegin for Newton 1.53 and i can't find something similar about OnAABBOverlap. Can you please show me one code example like i present before, but now using OnAABBOverlap instead of BeginContact ?

Thanks,
Telmo


NewtonContactBegin IS identical to NewtonOnAABBOverlap, the usage is identical, the wiki page documentation for new NewtonOnAABBOverlap appears to be simply missing, but it works the same, look at the article i linked to, it is ALL explained there.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Newton + Irrlicht crash problem

Postby telmopereira » Tue May 11, 2010 11:31 am

Hi again,

I had already moved to Newton 2.18.
Now I check out the tutorial nº 3 and i have some doubts about the kinematicController. First, there is no CustomPickBodySetTargetMatrix anymore, so how does it affects the solution? Second, as i can see, you create an object and add to that object a KinematicController. In the end you made NewtonBodySetMatrix, and that's it. In my case, i pretend that when i move an object with the keyboard , it changes the physic matrix (in my update function), and also the graphic, but someone said that doing that by using NewtonBodySetMatrix is an incorrect way, so how should i do my update function ? I don't understand very well how the kinematicController works. Can you help me please?

Thanks,

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

Re: Newton + Irrlicht crash problem

Postby Julio Jerez » Tue May 11, 2010 1:45 pm

If you are using the CustomKinematicController, here is the class
Code: Select all
class CustomKinematicController: public NewtonCustomJoint
{
   public:
   CustomKinematicController (const NewtonBody* body, const dVector& attachmentPointInGlobalSpace);
   virtual ~CustomKinematicController();

   void SetPickMode (int mode);
   void SetMaxLinearFriction(dFloat accel);
   void SetMaxAngularFriction(dFloat alpha);
   
   void SetTargetRotation (const dQuaternion& rotation);
   void SetTargetPosit (const dVector& posit);
   void SetTargetMatrix (const dMatrix& matrix);

   dMatrix GetTargetMatrix () const;

   protected:
   virtual void SubmitConstraints (dFloat timestep, int threadIndex);
   virtual void GetInfo (NewtonJointRecord* info) const;

   int m_pickMode;
   int m_autoSlepState;
   dFloat m_maxLinearFriction;
   dFloat m_maxAngularFriction;
   dVector m_localHandle;
   dVector m_targetPosit;
   dQuaternion m_targetRot;
};


after you attach a joint to the body, you hold on to the joint as you interface for controlling the body.
To set the body position you can use

Joint->SetTargetMatrix (const dMatrix& matrix);

and you pass a target matrix you get from your imput device.
the joint will do then work to make the body move to the target matrix while trying to obey the max friction force and max angular friction force it is allow to use.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton + Irrlicht crash problem

Postby telmopereira » Thu May 13, 2010 5:55 am

Hey, thanks for the answer. Aldo, i try what you said and is not working.

After i create the body on my init() function i did this:

Code: Select all
NewtonBodyGetMatrix(body, &p_matrix[0][0]);

   kinematic = new CustomKinematicController (body, &p_matrix.m_posit[0]);
   kinematic->SetPickMode(1);
   kinematic->SetMaxAngularFriction(2.0f);
   kinematic->SetMaxLinearFriction(2.0f);
   kinematic->SetTargetMatrix(p_matrix);


And then on my update function i do this:

Code: Select all
                vector3df actualPos = vector3df(p_pos.X/2,p_pos.Y/2,-p_pos.Z/2);
      p_irrSceneNode->setPosition(actualPos);
      
      matrix4 mat;
      mat.setTranslation( getPosition() );
      //NewtonBodySetMatrix(p_body, mat.pointer());
      
      p_matrix.m_posit.m_x = mat[12];
      p_matrix.m_posit.m_y = mat[13];
      p_matrix.m_posit.m_z = mat[14];
      kinematic->SetTargetMatrix(p_matrix);


However this is not working...graphically the object is moved and despite the p_matrix is correct there are no collisions now that i comment the NewtonBodySetMatrix of my update function. Do you know what is missing here that will put this working?

Just another question: The function "NewtonContactProcess" that i use on NewtonMaterialSetCollisionCallback should only be called when there is a collision correct? In my app is always being called, but i guess is because my collisions between the object that i control and the rest of the objects are not ok. Or this problem could be something else?

Thanks,

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

Re: Newton + Irrlicht crash problem

Postby Julio Jerez » Thu May 13, 2010 10:48 pm

now that you add the joint t the body, you nee to decide the max force the body will use when you move

you do that by setting the max friction force and torque,
setting 2 in probally too low, for exmple if you wnat to lift teh body teh firtion force sodul be at less bigger teh his wown weight.

at goo idea if to set ma friction a a factor of how many Gravity forces time the body mass teh body teh joint will apply
for example, if you will allow 10 G's
kinematic->SetMaxAngularFriction(10 * Gravity * bodyMass);
kinematic->SetMaxLinearFriction(10 * Gravity * bodyMaxx * someMaxRadiusThatWillBeConsderedAPickHnadle);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton + Irrlicht crash problem

Postby telmopereira » Fri May 14, 2010 8:45 am

Hi,

Despite i changed the values to what you said, it still have the same problem...the physic representation of the body is always in the same place (initial position = (0,0,0) ). As you can see in this video, http://feupload.fe.up.pt/get/rwPj9R5H18yDedF ,the box that is falling collides with the object that i am moving. The object is not on origin, but is physic representation is there (that's why the falling box have that behavior when is near the floor), and is never changed despite i am doing this on my update function:

Code: Select all
   vector3df actualPos = vector3df(p_pos.X/2,p_pos.Y/2,-p_pos.Z/2);
      p_irrSceneNode->setPosition(actualPos);
      
      matrix4 mat;
      mat.setTranslation( getPosition() );

      p_matrix.m_posit.m_x = mat[12];
      p_matrix.m_posit.m_y = mat[13];
      p_matrix.m_posit.m_z = mat[14];
      kinematic->SetTargetMatrix(p_matrix);


Only the graphical matrix is being updated... Altough if i add the NewtonBodySetMatrix(p_body, mat.pointer()); in this update function it seems that collisions works more or less good...at least is better then before i use the kinematic and only did the NewtonBodySetMatrix...is that suppose to be made like that BodySetMatrix + Kinematic->SetTargetMatrix???

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

Re: Newton + Irrlicht crash problem

Postby Julio Jerez » Fri May 14, 2010 8:57 am

I already told you, if you want to do it right you need to use the kinematic joint and use set target matrix.
see the Mouse Pick function in the newton tutorial in the wiki, is make a detail explanation of how to use it.
http://newtondynamics.com/wiki/index.php5?title=Tutorial_103:_-_Adding_Joints
set the last joint in the demo, it make a body follow a circular Path by ptotting positions in a circle into the target matrix.



do not set the matrix directly,
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton + Irrlicht crash problem

Postby telmopereira » Fri May 14, 2010 9:25 am

But without doing setMatrix, only with what you told me to do with the kinematic, it is no working, like you can see in the video i post...i put the values as you told me, i did the setTargetMatrix using the right matrix and it didnt work...i also saw the tutorial 3 example, but in this case, if i understand well, all that i need to do is create the kinematic and then make the setTargetMatrix to the kinematic joint on my update , so that should be the way to move physically the object that i am controlling. But is not working...so is something missing here ?

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

Re: Newton + Irrlicht crash problem

Postby Julio Jerez » Fri May 14, 2010 11:34 am

you do no need to set the body matrix on the update function.
you only set the initial position and form there in update function set the target Matrix on the Joint.
in the transform callback you just need to copy the matrix to the graphics mesh.

did you run the tutorial demo, so that you can see hwo it work?
It is not that complicated.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron