After a series of transformations and rotations, how to get current coordinates?

I just recently came from processing, where a command like this would be like

float curx = modelX(0,0,0);

reference: https://processing.org/reference/modelX_.html

where curx would be the x coordinate relative to the origin at (0,0,0).
Im not that used to using actual matrices for translations and rotations so Im not sure where to look in regards to the documentation.

What I am trying to do is read in some sensor data, then rotate some arm segment box relative to the sensors orientation, then translate to the point of the next arm segment, and so on till I can draw a ‘virtual arm’. Now I can do this, but I want to be able to get the point of my hand/fingers after all those transformations/rotations once I popMatrix().

Thanks!

There’s a couple of ways to go around this. First, you could set up each segment as a child using ofNode() to bind them, this might be the easiest as in this case you can do your transformations hierarchically without losing track of each ones parents.

Otherwise, the more involved solution is using matrices and more specifically, ofMatrixStack(). I ran into this same issue some time ago and managed to solve it, it’s documented in this thread. (A word of caution: I’m not sure whether this exact same method still works 100% or not since the move to glm as the native math library may have affected a few things.)

1 Like

if you are using ofPush/PopMatrix you can get the current model matrix by calling ofGetCurrentMatrix(OF_MODEL_MATRIX) then multiply 0,0,0 by that and you get the coordinates in world space as in:

glm::vec3 world = ofGetCurrentMatrix(OF_MODEL_MATRIX) * glm::vec3(0.);

If you are trying to model a hierarchy of transformations though it’s easier to use ofNode as @ayruos says

3 Likes

Got it, thanks guys! =)