Problem with Irrlicht angles and Newton matrix
Posted: Thu Jun 01, 2006 10:45 pm
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!
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!