title: How to convert mesh defined in a right-handed XYZ coordinate system to a left-handed XZY one
body: <p>I need a way to pass to these coordinate systems, but I'm struggling with the math.</p>
  
  <p>Basically I have a mesh created "for OpenGL", so right-handed XYZ coordinate system, and I would like to load it in a different environment (the Unreal Engine 4) which uses a left-handed XZY coordinate system.</p>
  
  <p>For now, take this mesh as an example, in its original state:
  <a href="https://i.stack.imgur.com/Uwo2o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uwo2o.png" alt="enter image description here"></a></p>
  
  <p>If a load it leaving all the vertices as they were, I get this:
  <a href="https://i.stack.imgur.com/MxmN6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MxmN6.png" alt="enter image description here"></a></p>
  
  <p>If you look carefully you'll see that it's "mirrored", the left legs of the spider are swapped with the right ones. Also, in the image is not very clear but the depth is off, I can see "inside" the spider (if you notice, the eyes are missing because of that).</p>
  
  <p>Now, if I swap the Y coordinate of each vertex with -Y I basically get the same result as the original:
  <a href="https://i.stack.imgur.com/lpIku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lpIku.png" alt="enter image description here"></a></p>
  
  <p>Now, the mesh format I'm using has objects hierarchies, meaning that a subset of the mesh may have as parent another subset, and if that's so it has a position and a rotation matrix relative to the parent associated to it. This means more problems when loading the mesh, because also the rotation matrix and position are defined in the wrong coordinate system.
  To apply this changes I create the vertices, then the object made up of these vertices, assign it its parent and then apply the rotation matrix and the position.</p>
  
  <p>Take for instance this mesh, defined with this format; all the various part the compose it are hierarchical in the way I described:
  <a href="https://i.stack.imgur.com/bnJox.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bnJox.png" alt="enter image description here"></a></p>
  
  <p>If I load it as it is, with the vertices, relative rotation matrices and positions in the wrong coordinate system, I get this:
  <a href="https://i.stack.imgur.com/4H5XA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4H5XA.png" alt="enter image description here"></a></p>
  
  <p>Which kind of looks the same, except that it's "mirrored" along an axis. Notice that yellow thing (wouldn't know how to call it) in the rightmost part of the image: it's on the opposite side respect of its position in the original image.
  Also, if you look at the text "BROKK" (which is not a texture, it's made up of vertices) it's reversed too.</p>
  
  <p>Now, if I apply the same trick as with the spider, switch the Y to -Y, I get this:
  <a href="https://i.stack.imgur.com/LDsZ9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LDsZ9.png" alt="enter image description here"></a></p>
  
  <p>Now it doesn't look mirrored, but the "arm" of the machine is all wrong, probably because I'm leaving the relative rotation matrices and positions in their orignal coordinate system maybe? I tried messing with them, but I get all kind of weird things going on, nothing close to the solution.</p>
  
  <p>I've looked a lot around, an to switch between coordinate systems I've found contrasting ideas. I tried applying this matrix below to switch the axis and invert the axis going "forward", but the result is crazy wrong:</p>
  
  <p>(1   0   0)<br>
  (0   0   1)<br>
  (0  -1   0)</p>
  
  <p>I'm helpless, do you have any ideas?</p>
  
  <p><strong>EDIT:</strong> thanks to Ripi2's suggestion (only inverting the sign to the Z coordinate) I've kind of got closer to the ideal solution. This is the result:
  <a href="https://i.stack.imgur.com/rPG5d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rPG5d.png" alt="enter image description here"></a></p>
  
  <p>Even though it's upside down (I can simply rotate it later) it's not mirrored anymore. Still, in that picture I'm only inverting the Z coordinates of the vertices of the mesh and of the childrens positions. In the picture all the parts except the arm are in the right orientation because their rotation matrix is the identity matrix. In the arm though the rotation matrix isn't the identity, and since I'm leaving it as it was in the original coordinate system it looks all wrong.</p>
  
  <p>I need a matrix of some kind to multiply to each rotation matrix, but I've no idea what!</p>