jgraphics t_jmatrix stack

    Mar 14 2009 | 10:42 am
    I want to use a transformation stack similar to the OpenGL push/pop interface. There seem to be none available for jgraphics, and before I start rolling my own I would like to know that I didn't overlook it.
    If it doesn't exist yet, wouldn't this be a useful addition?

    • Mar 14 2009 | 2:33 pm
      You can use the following in place of such push/pop logic.
      void jgraphics_get_matrix(t_jgraphics *g, t_jmatrix *matrix);
      void jgraphics_set_matrix(t_jgraphics *g, const t_jmatrix *matrix);
    • Mar 16 2009 | 11:30 pm
      This would be more like the equivalent of getModelViewMatrix() / setModelViewMatrix().
      For nested transformations you would have to (re)store the matrix for every level. I would prefer the elegance and simplicity of a push/pop interface.
      It's no big deal. I'll roll my own.
    • Mar 17 2009 | 12:11 am
      Sure, but you can just use the program stack and nested blocks if you like with macros like the following, unless you're using matched push/pop pairs as called from separate functions.
      #define MY_PUSH_TRANSFORM(g) { t_jmatrix mpush; jgraphics_get_matrix(g, &mpush);
      #define MY_POP_TRANSFORM(g) jgraphics_set_matrix(g, &mpush); }
      Otherwise, yes, you'll need to build and maintain your own stack.
    • Mar 20 2009 | 11:02 am
      I finally decided to create a stack, because it's more convenient for the interface I'm working with.
      Your approach is probably more efficient, since the matrices are stored on the program stack, and mine on the heap, but I don't think it'll matter much.
      I can't think of a scenario in my code where the push/pop calls would come from separate functions but I do want to use nested push/pop calls within one function, and I think it's cleaner this way.