Set Rotation Problem (Irrlicht to Newton)

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Set Rotation Problem (Irrlicht to Newton)

Postby herbetferreira » Tue Dec 07, 2010 10:16 am

I am developing a game that uses a haptic device as interaction with the game. For those who don't know what haptic is, think like a 3D joystick with force feedback.

My game is pretty simple. The world has a static object in the center of the scene and another static object that represents the haptic device in the scene.

Only two major tasks are performed:

    1) When I move the haptic device, the object represented by it is only changed its position and rotation.
    2) When the object (represented by the haptic device) touches the object that stands at the center of the scene, a collision is detected, and a return force is calculated for the haptic device, with the intention of the user feel that the two objects were touched.

No animation physics is shown. There is no gravity, there is no mass of objects, no object is changed dynamically, all are static. I just change the position (translation) and rotation of the object of the haptic device according to the matrix of the device.
I am using the Newton engine just for the two objects have a physical body and when they collide I can receive information such as point of contact, normal and penetration. Because with this information I can calculate the force feedback.

My problem is the opposite of what usually happens in games that use a physics engine, where when the physical objects are changed (moving dynamically), I need to change the position and rotation in the graphics engine. That is, the method SetTransformCallback is used to receive the NewtonBody body and Matrix and changes the position and rotation in the graphics engine.

In my case is different. First, I get the the position and rotation of my haptic device (joystick 3D) through it Matrix, and thus I change the Matrix of my newton body with the new positions and rotations.

I'm using the graphics engine Irrlicht.
My methods are:

Code: Select all
void CObject::setPosition(const vector3df& position)
{
   if(m_node)
   {
      m_node->setPosition(position);
      m_node->updateAbsolutePosition();
   }

   if(m_body)
   {
      core::matrix4 mat;
      NewtonBodyGetMatrix(m_body, mat.pointer());
      mat.setTranslation(position);
      NewtonBodySetMatrix(m_body, mat.pointer());
   }
}


Code: Select all
void CObject::setRotation(const vector3df& rotation)
{
   if(m_node)
   {
      m_node->setRotation(rotation);
              //m_node->updateAbsolutePosition();
   }

   if(m_body)
   {
      core::matrix4 mat;
      NewtonBodyGetMatrix(m_body, mat.pointer());
      mat.setsetRotationDegree(rotation);
      NewtonBodySetMatrix(m_body, mat.pointer());
        }
}


The problem is the rotation just does not happen!
When I move my device, my object is usually translated (graphically and physically)
But when the object rotates through the device, it is rotated only graphically, the physical body it remains the same position. That is, the rotation in Irrlicht engine is correctly, but when I try to rotate the newton body, it does not rotate!

Is there something wrong with rotate this way?

Code: Select all
core::matrix4 mat;
NewtonBodyGetMatrix(m_body, mat.pointer());
mat.setRotationDegree(rotation);
NewtonBodySetMatrix(m_body, mat.pointer());
Last edited by herbetferreira on Tue Dec 07, 2010 12:36 pm, edited 1 time in total.
herbetferreira
 
Posts: 3
Joined: Thu May 27, 2010 11:42 am

Re: Set Rotation Problem (Irrlicht to Newton)

Postby ledahut » Tue Dec 07, 2010 11:14 am

I am not shure but I see 'm_node->updateAbsolutePosition();' in the rotation procedure.
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: Set Rotation Problem (Irrlicht to Newton)

Postby herbetferreira » Tue Dec 07, 2010 12:35 pm

That makes no difference. If I take this line, graphically still the same thing.

The problem is with the physical body that does not change! Simply does not make the rotation.
herbetferreira
 
Posts: 3
Joined: Thu May 27, 2010 11:42 am

Re: Set Rotation Problem (Irrlicht to Newton)

Postby ledahut » Tue Dec 07, 2010 1:37 pm

Are you sure that the matrix 'mat' has been modified with mat.setsetRotationDegree(rotation) ?

I am sorry but I found sample with quick search and some people use a multiplication after calling this function.
I don't know irrlitch.

Code: Select all
mat2=mat1
mat1.setsetRotationDegree(rotation);
mat2=mat2*mat1;



After typing that, i see setsetRotationDegree instead of setRotationDegree in your code.
If sample your code is the reel code of your project, this could be the problem. (but the compiler must failed, and the debugger must check this error)
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: Set Rotation Problem (Irrlicht to Newton)

Postby herbetferreira » Tue Dec 07, 2010 1:49 pm

The source code is correct with mat.setRotationDegree (rotation);
I missed when writing the topic now, sorry ;)

I did what you suggested but neither worked. :(
Code: Select all
   if(m_body)
   {
      core::matrix4 mat1, mat2;
      NewtonBodyGetMatrix(m_body, mat1.pointer());

      mat2 = mat1;
      mat1.setRotationDegrees(rotation);
      mat2=mat2*mat1;

      NewtonBodySetMatrix(m_body, mat2.pointer());
   }
Last edited by herbetferreira on Tue Dec 07, 2010 7:10 pm, edited 1 time in total.
herbetferreira
 
Posts: 3
Joined: Thu May 27, 2010 11:42 am

Re: Set Rotation Problem (Irrlicht to Newton)

Postby ledahut » Tue Dec 07, 2010 5:53 pm

The first NewtonBodySetMatrix need to be NewtonBodyGetMatrix

Did you try breakpoint +watchlist with debugger to see if the matrix you sent is correct?

Manipulating newtonBodyMatrix work perfectly with me, and you code look correct.

Maybe if you give use more than two little class.
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron