title: Is there an equivalent of D3DXMatrixRotationYawPitchRoll() for iphone developers?
body: <p>The <code>D3DXMatrixRotationYawPitchRoll()</code> function builds a matrix with a specified yaw, pitch, and roll.  Is there an equivalent function for iphone developers??</p>
  
  <p>I found a beautiful little sample project for drawing a winding road or rollercoaster <a href="http://www.mvps.org/directx/articles/catmull/" rel="nofollow noreferrer">here.</a></p>
  
  <p>It's not a lot of code, and the comments seem mostly understandable, but the code is relying on a few DirectX functions that I'm not yet smart enough to recreate in C for use in my iphone project.</p>
  
  <p>Could someone point me in the right direction here?  I need to create a rotation matrix from yaw,pitch,roll values.</p>
  
  <p>This directX function signature is this:</p>
  
  <pre><code>     D3DXMATRIX * D3DXMatrixRotationYawPitchRoll(
    __inout  D3DXMATRIX *pOut,
    __in     FLOAT Yaw,
    __in     FLOAT Pitch,
    __in     FLOAT Roll
  );
  </code></pre>
  
  <p>Is there a glu*() equivalent for this?</p>
  
  <hr>
  
  <p>(...hours of reading later)</p>
  
  <hr>
  
  <p>Well, after quite a bit of reading (with lots more to go), this is what I've gathered:</p>
  
  <p><a href="http://www.gamedev.net/reference/articles/article1095.asp" rel="nofollow noreferrer">This</a> site was a great help!</p>
  
  <p>It appears that I will need to convert the 3 euler angles (that's what pitch,roll,yaw are called) into three independent unit quaternions:</p>
  
  <pre><code>Qx = [ cos(a/2), (sin(a/2), 0, 0)]
  Qy = [ cos(b/2), (0, sin(b/2), 0)]
  Qz = [ cos(c/2), (0, 0, sin(c/2))]
  </code></pre>
  
  <p>And then combine these into one quaternion with:</p>
  
  <p>Qcombined = Qx * Qy * Qz</p>
  
  <p>Then I can convert this resulting "unit" quaternion back to the kind of rotation matrix that openGL will like by doing this:</p>
  
  <pre><code>Matrix =  [ 1 - 2y2 - 2z2    2xy - 2wz      2xz + 2wy
                2xy + 2wz    1 - 2x2 - 2z2    2yz - 2wx
                2xz - 2wy      2yz + 2wx    1 - 2x2 - 2y2 ]
  </code></pre>