(solved) Problem updating from irrlicht 1.7. Rotation?

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!
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

(solved) Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

Hi, I have recently been updating my project to irrlicht 1.8 from 1.7 and a point release from 1.8's early development. The code was working fine with 1.7 and the proto-1.8 version. In all other 1.8 releases (I have not tried 1.8.4) I have a problem. Skinned meshes, while animated, are tilted to the right, tilted away from the camera, and rotated. It looks maybe like rotations are applied wrong.

Here is where the loader copies translation, rotation, and scale to the mesh's joints.

Code: Select all

 
scene::CM2Mesh::SJoint* Joint;
for(u32 i=0;i<M2MBones.size();i++)
{
  if(M2MBones[i].parentBone == -1)
  {
      ParentJoint=(scene::CM2Mesh::SJoint*)0;
  }
  else
  {
      ParentJoint=AnimatedMesh->getAllJoints()[M2MBones[i].parentBone];
  }
  Joint=AnimatedMesh->addJoint(ParentJoint);
 
  if(M2MBones[i].translation.timestamps.size()>0)
  {
    for(u32 j=0;j<M2MBones[i].translation.timestamps.size();j++)
    {
      scene::CM2Mesh::SPositionKey* pos=AnimatedMesh->addPositionKey(Joint);
      pos->frame=M2MBones[i].translation.timestamps[j];
      pos->position=fixCoordSystem(core::vector3df(M2MBones[i].translation.values[j*3],M2MBones[i].translation.values[j*3+1],M2MBones[i].translation.values[j*3+2]));
    }
  }
  if(M2MBones[i].rotation.timestamps.size()>0)
  {
    for(u32 j=0;j<M2MBones[i].rotation.timestamps.size();j++)
    {
      scene::CM2Mesh::SRotationKey* rot=AnimatedMesh->addRotationKey(Joint);
      rot->frame=M2MBones[i].rotation.timestamps[j];
      core::quaternion tempQ=core::quaternion(M2MBones[i].rotation.values[j*4+0],M2MBones[i].rotation.values[j*4+1],M2MBones[i].rotation.values[j*4+2],M2MBones[i].rotation.values[j*4+3]);
      tempQ = fixQuaternion(tempQ);
      tempQ.normalize();
      rot->rotation=tempQ;
    }
  }
 
  if(M2MBones[i].scaling.timestamps.size()>0)
  {
    for(u32 j=0;j<M2MBones[i].scaling.timestamps.size();j++)
    {
      scene::CM2Mesh::SScaleKey* scale=AnimatedMesh->addScaleKey(Joint);
      scale->frame=M2MBones[i].scaling.timestamps[j];
      scale->scale=core::vector3df(M2MBones[i].scaling.values[j*3],M2MBones[i].scaling.values[j*3+1],M2MBones[i].scaling.values[j*3+2]);
    }
  }
 
  Joint->Animatedposition=M2MBones[i].PivotPoint;
  Joint->Animatedscale=core::vector3df(1.0f,1.0f,1.0f);
  Joint->Animatedrotation=core::quaternion(0.0f,0.0f,0.0f,1.0f);
 
  core::matrix4 positionMatrix;
  positionMatrix.setTranslation( Joint->Animatedposition );
 
  core::matrix4 rotationMatrix = Joint->Animatedrotation.getMatrix();
 
  core::matrix4 scaleMatrix;
  scaleMatrix.setScale( Joint->Animatedscale );
 
  Joint->GlobalMatrix = positionMatrix * rotationMatrix * scaleMatrix;
}
 
 
Last edited by lumirion on Tue Jan 17, 2017 1:56 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

I don't know what your fixQuaternion does - but between 1.7 and 1.8 there had been a few quaternion fixes. Previously there had been a mix between left- and right-handed rotations.
Corresponding comment in changes.txt might help you to find the problem:
Quaternion conversions to and from matrix4 no longer invert rotations.
To test if your code was affected by this you can set IRR_TEST_BROKEN_QUATERNION_USE in quaternion.h and try to compile your application. Then on all compile-errors when you pass the matrix to the quaternion you can replace the matrix with the transposed matrix.
For all errors you get on getMatrix() you can use quaternion::getMatrix_transposed instead.
Unfortunately we had no way to fix this specific problem without breaking existing code as it involved constructors which either worked correct (as of now) or wrong (as in the past).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

Oh, fixquaternion just switches from y up coordinates to z up, irrlicht, stile coordinates.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

Well, I'm not seeing any matrix4 <-> quaternion conversions in your code. Maybe there is some in another part of your code?
Otherwise... I can't really check anything without having a code example which can be run and tested.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

First I want to say thanks for helping. Ok, so following your tip about IRR_TEST_BROKEN_QUATERNION_USE, I set it to 1 and tried to recompile. Compile flagged the line

Code: Select all

 
core::matrix4 rotationMatrix = Joint->Animatedrotation.getMatrix;
 
in my previously posted code with an error. how do I fix this?
I tried

Code: Select all

core::matrix4 rotationMatrix;
  Joint->Animatedrotation.getMatrix_transposed(rotationMatrix);
instead but I get the same result as before.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

Basically if that was the only one (check by commenting the one that complains out or replace by some dummy-line and compile again) it should work as before. But note - it was kinda wrong before (usually you would use getMatrix instead of getMatrix_transposed - everyone just hacked around that before always by switching rotations again to negative rotations etc). So this is to keep it the same as before - but often not the best code.

On first view, I'm wondering about order of: positionMatrix * rotationMatrix * scaleMatrix;
Shouldn't rotationMatrix be applied first? Or is matrix operator* working like that? I never can remember that one *sigh*
My guess would be something like - use getMatrix, but change order here. But could be I'm completely wrong. Hard to tell without having a good example which I can work through.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

Thank-you, I will try when I get home. :)
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

It is still not working. The source code for the loader and mesh, prior to my attempts to fix them, can be viewed at https://github.com/shlainn/pseuwow/tree ... Client/GUI in case anyone can see what's wrong. I know the mesh is based on an older version of skinned mesh. The files to look at are, cm2meshfileloader.h, cm2meshfileloader.cpp, cm2mesh.h and cm2mesh.cpp.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

Hm, can you make a quick example that just contains those files, lodas some model and reproduces the problem? Basically for anyone else to help that's usually the first thing someone has to do (otherwise it's pure guess-work like me doing above).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

Working on a minimal example, but I'm short on time. Doing fall yard work. I'll post it when I cut it down to size.
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

I have an example M2Viewer program and a sample mesh to load. It demonstrates the defective animation. It can be found at http://www24.zippyshare.com/v/u9oq4EGA/file.html . The M2Viewer also exhibits an incorrect submesh render order, so please ignore that. I included a copy of irrlicht 1.8.3 modified with pseuwow specific modifications that worked fine with 1.7 and the early 1.8 prereleases. I also included cmake project files to build it with. Any suggestions or changes are welcome.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

Thanks. I didn't get to Irrlicht coding last weekends, so by now I got rather a lot of somewhat urgent stuff on my list for the next weekends, so not sure when I'll get to this...

Also modified Irrlicht - sounds a little heavy for a simple example to reproduce a problem. Generally examples for bugs should be short enough so you can post them in the forum. Otherwise you are asking for a lot.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem updating from irrlicht 1.7. Rotation?

Post by CuteAlien »

Can't download your link. All I get is casino advertising when clicking download...
There are fantastic websites like bitbucket to upload project sources (or github, but not sure if that's as good when you also upload media files).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: Problem updating from irrlicht 1.7. Rotation?

Post by lumirion »

Aww crap. Ok I'll find a better host and re-upload. I included irrlicht so that my cmake project works. I'm a little overly proud of it. Lol. The changes are minimal. Just a texture loader and support for cm2mesh type.
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Problem updating from irrlicht 1.7. Rotation?

Post by AReichl »

I could download it - just close the popup-window and repeat until it works.
Post Reply