Problem with Irrlicht angles and Newton matrix

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
hoffhoff
Posts: 17
Joined: Fri Mar 10, 2006 11:55 am

Problem with Irrlicht angles and Newton matrix

Post 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!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hoffhoff
Posts: 17
Joined: Fri Mar 10, 2006 11:55 am

Post 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.
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post 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
Nick_Japan
Posts: 98
Joined: Mon Dec 13, 2004 11:47 am
Location: Japan

Post 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.
Image Image
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post 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.
Post Reply