1
\$\begingroup\$

Ok, so I've tried reading over the other questions and something's just not clicking for me. I am working on an augmented reality application using ARToolkit, however it should just be straight OpenGL matrix math.

So, one of my fiducial markers is considered to be my global coordinate base. So I have an x,y,z that I pull out of the ARToolkit transform matrix (this would be something like trans[0][3], trans[1][3], trans[2][3]). I am feeding that into a glTranslated() call in order to move my objects around, relative to the origin.

Now, when I use another marker, those are recognized with their own local coordinates. I need to transform them into the coordinates of the original marker, and that is where I'm having issues. I can pull out the x,y,z coordinates easy enough, but taking that relative to the origin is my issue.

So my understanding was that I could somehow create my global coordinates, take the inverse, multiply those by the new coordinates, and that would give me the coordinates of the new object relative to the origin. I think my issue is in figuring out how to add those in properly to a matrix, since I'm dealing with x,y,z coords separately.

Any help would be appreciated...I'm doing this all in C as well, so no nifty STL functionality for me.

\$\endgroup\$
2
\$\begingroup\$

A small correction first.

x, y and z translation in a 4x4 OpenGL matrix is not

trans[0][3], trans[1][3], trans[2][3]

but

trans[3][0], trans[3][1], trans[3][2]

since OpenGL matrices are in column-major form, the translation being in the last column.

This code-snippet demonstrates it:

    glLoadIdentity();
    glTranslatef(1.0, 2.0, 3.0);
    float m[4][4];
    glGetFloatv(GL_MODELVIEW_MATRIX, (float*)m);
    printf("%3.1f, %3.1f, %3.1f\n", m[3][0], m[3][1], m[3][2]);

The output is: 1.0, 2.0, 3.0


Now here is the answer to your question. Let

  mA be the transformation matrix of marker A
  mB be the transformation matrix of marker B
  mA^-1 be the inverse matrix of mA

Now to get the matrix that transforms mB-space into mA-space -> m = mA^-1 * mB

m[3][0] and m[3][1] and m[3][2] will be the position of marker B in the local space of marker A

Btw. you dont need to pull out x, y and z to pass it to glTranslated, just upload the entire matrix using glMultMatrixd, in order to not only apply the position but also the correct orientation.

\$\endgroup\$
  • \$\begingroup\$ thanks, i'll give that a shot...i'm using ARToolkit for a project and fumbling along with my limited OpenGL knowledge \$\endgroup\$ – the_e Mar 4 '12 at 0:22
  • \$\begingroup\$ @espais not sure why you would need all this though, it is a bit over-complicated. You can just render the markers using their normal transformation matrices via glMultMatrixd, render all objects in the scene normally, then use one markers inverse matrix as camera matrix, if you want the camera to be on the marker, voila :) You need help with this? just shoot.. \$\endgroup\$ – Maik Semder Mar 4 '12 at 9:43
  • \$\begingroup\$ basically, if my origin object is recognized, i draw the scene, and if the other markers are recognized i draw my objects where those physically are in space...what i wanted to do was to basically make my objects that i'm holding up physically interact with my scene \$\endgroup\$ – the_e Mar 5 '12 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.