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!
Problem with Irrlicht angles and Newton matrix
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...![Wink ;)](./images/smilies/icon_wink.gif)
Just open it and search for matrix4 !!!
Then you'll see all that you can do with it...
![Wink ;)](./images/smilies/icon_wink.gif)
while(!asleep) sheep++;
IrrExtensions:![Image](http://abusoft.g0dsoft.com/Irrlicht/gfx/logo.jpg)
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
![Image](http://abusoft.g0dsoft.com/Irrlicht/gfx/logo.jpg)
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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.
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.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
Heres code i use: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.
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();
}
HTH
-
- Posts: 98
- Joined: Mon Dec 13, 2004 11:47 am
- Location: 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.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
I can second that, boy did I waste a lot of time on it, myself.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.