Page 1 of 1

Problem with Irrlicht angles and Newton matrix

Posted: Thu Jun 01, 2006 10:45 pm
by hoffhoff
Hello,

I have written the following newton´s callback for to set the mesh´s transform event:

void _cdecl CObject::SetMeshTransformEvent(const NewtonBody* body, const dFloat* matrix)
{
//std::cout << "Called SetMeshTransformEvent in cobject \n";
// copy the matrix into an irrlicht matrix4
matrix4 mat;
vector3df euler;
CObject* object;
mat.makeIdentity();
memcpy(mat.M, matrix, sizeof(float)*16);

// Retreive the user data attached to the newton body
object = (CObject*) NewtonBodyGetUserData (body);
IAnimatedMeshSceneNode *tmp = object->getscenenode();

// a character is not supposed to answer to torque events
if (object->ObjectType == CHARACTER)
mat.setRotationDegrees(tmp->getRotation());

NewtonGetEulerAngle (&mat.M[0], &euler.X);

if (tmp)
{
// Position the node
tmp->setPosition(mat.getTranslation() * NewtonToIrr); // set position
tmp->setRotation(euler * (180.0f / 3.1416f)); // and rotation
}
}

Then in the RIGHT / LEFT key event I increase/decreade the rotation of the SceneNode. My problem is that I can only work with angles between -90 and 90 degrees. When it reaches this angles, the model stops spinnig.
I asked for help in Newton´s forum, and they said that I should avoid using angles, and set the matrix of the mesh instead.

Well, I know that I can get the matrix with getRelativeTransformation (), but I don´t know how to set a value to matrix.

Do someone know how to solve this problem?

I´ve been working on it for a few weeks, and I can´t go on coding without solving it.

Thanks!

Posted: Thu Jun 01, 2006 11:39 pm
by Acki
There is a magic file included to the Irrlicht sdk called "Irrlicht.chm" !!!
Just open it and search for matrix4 !!!
Then you'll see all that you can do with it... ;)

Posted: Fri Jun 02, 2006 2:11 am
by hoffhoff
That "magic" file is also online, on API documentation, and I can say that I didn´t spend those weeks waiting for a God hand.
If I didn´t ask here before is because I surelly read the Irrlicht documentation.

Also, as you can see, I am using matrix there.
BUT why doesn´t it let me work with angles lower than -90 or bigger than +90?

That´s my problem.

Posted: Sun Jun 04, 2006 1:47 pm
by dhenton9000
hoffhoff wrote:That "magic" file is also online, on API documentation, and I can say that I didn´t spend those weeks waiting for a God hand.
If I didn´t ask here before is because I surelly read the Irrlicht documentation.

Also, as you can see, I am using matrix there.
BUT why doesn´t it let me work with angles lower than -90 or bigger than +90?

That´s my problem.
Heres code i use:

Code: Select all


void  NewtonBoid::SetMeshTransformEventHandler(const NewtonBody* body, const float* matrix)
{


   matrix4 mat, fixmat, unfixmat, rotmat;
   memcpy(mat.M, matrix, sizeof(float)*16);
   setPosition(mat.getTranslation().X,mat.getTranslation().Y, mat.getTranslation().Z);
   vector3df place = mat.getTranslation()* NewtonToIrr ;
    m_animatedBoxNode->setPosition(place);
   m_animatedBoxNode->setRotation(mat.getRotationDegrees());
	m_animatedBoxNode->updateAbsolutePosition();
}
  
This allows me to use the matrix from newton and set the irrlicht node with it. You can see I'm just pulling angles out, but it works for me!

HTH

Posted: Tue Jun 06, 2006 3:37 am
by Nick_Japan
It's been a while since I've done any work with Newton, but I remember that when I did I found something really strange. Basically, Newton seems to do rotations in a really weird way. Instead of using from 0 to 360 (or using the radian equivalent), it seemed to go from -180 to 180, so 181 degrees would become -179. This wasn't a problem until you try and use the rotations manually, because even though you set a rotation of 190, for example, when you then try to get the same rotation out you get -170. I had a really hard time trying to work with that.

Posted: Tue Jun 06, 2006 8:14 pm
by dhenton9000
Nick_Japan wrote:It's been a while since I've done any work with Newton, but I remember that when I did I found something really strange. Basically, Newton seems to do rotations in a really weird way. Instead of using from 0 to 360 (or using the radian equivalent), it seemed to go from -180 to 180, so 181 degrees would become -179. This wasn't a problem until you try and use the rotations manually, because even though you set a rotation of 190, for example, when you then try to get the same rotation out you get -170. I had a really hard time trying to work with that.
I can second that, boy did I waste a lot of time on it, myself.