2

There is a header file in GLKit with the following comment:

GLKMatrixStack is a CFType that allows for the creation of a 4x4 matrix stack similar to OpenGL's matrix stack. Any number of matrix stacks can be created and operated on with functions similar to those found in fixed function versions of OpenGL.

How would you go about generating a model view matrix based on the contents of the stack? I can't find any reference to the GLKMatrixStackRef type outside of the GLKMatrixStack header.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Scott Hyndman
  • 923
  • 1
  • 7
  • 15

1 Answers1

2

In Apple's C libraries, <whatever>Ref is a typedef for a pointer to <whatever>. So the appropriate documentation is that for GLMatrixStack. So you'd use GLMatrixStackCreate, then whatever combination of GLMatrixStackRotate, GLMatrixStackScale, GLMatrixStackPush/Pop etc and something like GLMatrixStackGetMatrix4 when you want to communicate the results to your shaders.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • According to the docs, [`GLKMatrixStackGetMatrix4`](https://developer.apple.com/library/ios/#DOCUMENTATION/GLkit/Reference/GLKMatrixStack/Reference/reference.html) returns the matrix from the _top_ of the stack, not the resultant transformation matrix. – Scott Hyndman Mar 11 '12 at 14:53
  • Just realized that `GLKMatrixStackPush` pushes a copy of the topmost matrix on the stack, which you then perform transformations on. So the top-most matrix is always the result. You were right. Thanks for your help. – Scott Hyndman Mar 11 '12 at 15:38
  • I kind of follow what you're saying, but a short sample snippet would be quite handy. The thing I'm having difficulty with is objects that are "attached" to parent objects such that (for example), when I rotate the upper-arm about the shoulder, the forearm and hand follow-along. How do I get the starting matrix (off the stack?) for the forearm and hand objects? Thanks! – Olie May 24 '13 at 17:32