I need to get x,y,z axis angles from the 4by4 rotation matrix used in the ARToolKitPlus examples, since other than superimposing something along with the mark recognized, I want to use the translation and rotation of the mark as a controller for something else. For example, when rotating a mark, it functions like a knob to change color or so…
Also, how can I know the mark’s position (x,y) on the screen?
In ofxVectorMath theres a matrix44 class that can do matri, decomposition. You can feed the matrix you are getting from artoolkit into an ofxMatrix4x4 and get all the individual transformations from that.
I’ve just added this code. The result im getting is->
If I turn the marker right 180 around the max value I get is 150. 90 degree’s is about 100.
If I start turning the marker left it starts counting negative but when it gets to -140 it switches back to a positive float.
I don’t really know why it’s not going from 0 - 360?
Thanks,
David.
update function:
ofxMatrix4x4 mat = m; // m is set in the draw
ofxVec3f translation;
ofxQuaternion rotation;
ofxVec3f scale;
ofxQuaternion so;
mat.decompose(translation, rotation, scale, so);
float f;
ofxVec3f v;
rotation.getRotate(f, v);
cout << v.x * f * (180 / PI) << endl;
draw function:
glViewport(cameraCenterX, cameraCenterX, cameraWidth, cameraHeight );
glMatrixMode( GL_PROJECTION );
glLoadMatrixf(tracker->getProjectionMatrix());
for(int i=0; i<numDetected; i++)
{
ARToolKitPlus::ARMarkerInfo marker = tracker->getDetectedMarker(i);
float m34[ 3 ][ 4 ];
float c[ 2 ] = { 0.0f, 0.0f };
float w = 40.0f;
tracker->rppGetTransMat( &marker, c, w, m34 );
//float m[ 16 ]; //this is some crazy matrix transformative stuff. I think initially it came out of one of the arToolkit functions.... but i got it from here: [http://chihara.naist.jp/people/STAFF/imura/computer/OpenGL/artp/disp-content](http://chihara.naist.jp/people/STAFF/imura/computer/OpenGL/artp/disp-content)
for ( int i = 0; i < 3; i++ ) {
for ( int j = 0; j < 4; j++ ) {
m[ j * 4 + i ] = m34[ i ][ j ];
}
}
for ( int j = 0; j < 3; j++ ) {
m[ j * 4 + 3 ] = 0.0f;
}
m[ 3 * 4 + 3 ] = 1.0f;
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( m );
Going back to 0062, the ofxMatrix4x4 is supposed to be set in quaternion rads, not degrees, so that might explain why the results are unintuitive. This seems to work fine.
Also, for each marker you might try calling getOrientationQuaternion() or getOrientationMatrix() to see if that helps you get the rotation a little more cleanly. In the processing implementation of this I remember there being a really easy way to get the rotation for each axis, but it doesn’t seem like that exists in the ARToolKit implemenation.