jgraphics t_jmatrix stack

Mar 14, 2009 at 10:42am

jgraphics t_jmatrix stack

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?

Thijs

#42849
Mar 14, 2009 at 2:33pm

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

-Joshua

#153373
Mar 16, 2009 at 11:30pm

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.

Thijs

#153374
Mar 17, 2009 at 12:11am

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.

-Joshua

#153375
Mar 20, 2009 at 11:02am

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.

Best,
Thijs

#153376

You must be logged in to reply to this topic.