Recently, I am working on openGL es and ARToolKitplus together to draw a model based on the marker I have.
After I used Artoolkitplus, it returns the modelview matrix, which is:
0.99 -0.08 -0.08 0.00
-0.07 -0.97 0.22 0.00
-0.10 -0.21 -0.97 0.00
9.80 3.53 462.65 1.00
which last row means my marker is 9.80 mm in x-axis, 3.53 mm in y-axis, and 462.65mm in z axis away from the camera.
Given this model view matrix, I am trying to draw my object with correct rotation, translation, and scale but I could only make rotation working. Since this matrix is object relative to camera, I invert 3x3 matrix (First three columns and row) and I was able to make my object rotates correctly while I move my marker around. Now, the question is that I couldn’t make my translation and scale factor working.
I thought the modelview matrix includes everything…so scale factor is included in that 3x3 matrix but I guess now? Also I can I translate my object correctly using those mm information?
Could someone tell me how? I am having hard time to understand this Thank you so much!
Typically, the translation terms must be in the fourth column rather than in the fourth row.
Are you sure your scale factors are not working? Your X scale factor is 0.99, your Y scale factor is -0.97 and your Z scale factor is -0.97 (to the two digits of significance you provided). It would probably be difficult to see the difference between scale factors of 1.0 and 0.99 or 0.97 . (The signs of the scale factors don’t affect the scale, rather they affect the coordinate system.)
Thank you so much for the reply!
Actually, the way it represents from ARToolkit was column major so theoretically, it should be:
0.99 -0.07 -0.10 9.80
-0.08 -0.97 -0.21 3.53
-0.08 0.22 -0.97 462.64
0.00 0.00 0.00 1.00
Anyway, so I think I understand scale factor. Actually, when I rotate my marker around, it does affect the scale. But it does not affect the scale when I move my marker away from camera (z translation (462.64mm in this case). I mean object should be smaller but I don’t think this translation affects at all and I don’t know how to solve it. Thank you so much again!
Oftentimes, the modelview and projection matrices are separate matrices. I’m assuming the matrix you’ve shown above is a modelview-only matrix. (If it isn’t, then it is an orthographic projection matrix and they don’t scale objects smaller in the distance anyway.) In the case you just have a modelview-only matrix, it will not (and should not) scale your marker smaller when you move it further away from the camera. That’s the job of the projection matrix – provided it has a perspective transform.
You can identify a projection matrix with a perspective transform because the fourth row will look something like this: [0 0 1 0] (the key point is that the third column of the fourth row will not be zero). What that does is copy the point’s Z coordinate into the W coordinate’s position. Later in the OpenGL pipeline, the Perspective Divide is performed, which is dividing each point’s X, Y, and Z coordinates by the point’s W coordinate. The way that perspective works is that the further away a point is (i.e., the bigger its Z coordinate), the bigger the number the X, Y, and Z coordinates are divided by, making them smaller.