title: Rotate model around x,y,z axes, without gimbal lock, with input data always as x,y,z axes angle rotations
body: <p>I have an input device that gives me 3 angles -- rotation around x,y,z axes.</p>
  
  <p>Now I need to use these angles to rotate the 3D space, without gimbal lock. I thought I could convert to Quaternions, but <a href="https://stackoverflow.com/questions/6325689/rotate-3d-euler-point-using-quaternions-to-avoid-gimbal-lock">apparently since I'm getting the data as 3 angles this won't help</a>? </p>
  
  <p>If that's the case, just how can I correctly rotate the space, keeping in mind that my input data simply is x,y,z axes rotation angles, so I can't just "avoid" that. Similarly, moving around the order of axes rotations won't help -- all axes will be used anyway, so shuffling the order around won't accomplish anything. But surely there must be a way to do this?</p>
  
  <p>If it helps, the problem can pretty much be reduced to implementing this function:</p>
  
  <pre><code>void generateVectorsFromAngles(double &amp;lastXRotation,
                                                        double &amp;lastYRotation,
                                                        double &amp;lastZRotation,
                                                        JD::Vector &amp;up,
                                                        JD::Vector &amp;viewing) {
      JD::Vector yaxis = JD::Vector(0,0,1);
      JD::Vector zaxis = JD::Vector(0,1,0);
      JD::Vector xaxis = JD::Vector(1,0,0);
      up.rotate(xaxis, lastXRotation);
      up.rotate(yaxis, lastYRotation);
      up.rotate(zaxis, lastZRotation);
      viewing.rotate(xaxis, lastXRotation);
      viewing.rotate(yaxis, lastYRotation);
      viewing.rotate(zaxis, lastZRotation);
  }
  </code></pre>
  
  <p>in a way that avoids gimbal lock.</p>