views:

65

answers:

1

The D3DXMatrixRotationYawPitchRoll() function builds a matrix with a specified yaw, pitch, and roll. Is there an equivalent function for iphone developers??

I found a beautiful little sample project for drawing a winding road or rollercoaster here.

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.

Could someone point me in the right direction here? I need to create a rotation matrix from yaw,pitch,roll values.

This directX function signature is this:

     D3DXMATRIX * D3DXMatrixRotationYawPitchRoll(
  __inout  D3DXMATRIX *pOut,
  __in     FLOAT Yaw,
  __in     FLOAT Pitch,
  __in     FLOAT Roll
);

Is there a glu*() equivalent for this?


(...hours of reading later)


Well, after quite a bit of reading (with lots more to go), this is what I've gathered:

This site was a great help!

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:

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))]

And then combine these into one quaternion with:

Qcombined = Qx * Qy * Qz

Then I can convert this resulting "unit" quaternion back to the kind of rotation matrix that openGL will like by doing this:

Matrix =  [ 1 - 2y2 - 2z2    2xy - 2wz      2xz + 2wy
              2xy + 2wz    1 - 2x2 - 2z2    2yz - 2wx
              2xz - 2wy      2yz + 2wx    1 - 2x2 - 2y2 ]
A: 

looking here: http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions

you should create a matrix composed by Rz(-roll)*Rx(-pitch)*Ry(yaw), then to use the result a call to glMultMatrix (if you have column mayor matrices) or glMultTransposeMatrix (if you have row-mayor matrices) is enough to set the view. http://www.opengl.org/sdk/docs/man/xhtml/glMultTransposeMatrix.xml http://www.opengl.org/sdk/docs/man/xhtml/glMultMatrix.xml

andijcr