Log in or register to post comments

How to get Quaternion or RotationMatrix from the Pose Matrix

July 20, 2012 - 9:07am #1

Hi,

I'm trying to rotate 3D Model by finger swipe.

But it happend incorrectly rotation.

If I rotate my phone on landscape, It is rotate reversely.

I thought because there are two different coordnates system, world coordnate system and the pose coordnate system.

So, I want to know how to get the rotation information from the Pose matrix.

Is there anyone who can tell me about it?

Thank you!

How to get Quaternion or RotationMatrix from the Pose Matrix

July 22, 2012 - 6:27pm #4

You're welcome - thanks for posting your solution!

How to get Quaternion or RotationMatrix from the Pose Matrix

July 20, 2012 - 3:02pm #3

Thank you soooooooooo much!!!

I was able to solve my problem because your reply.

I'm so happy!!

Thank you so much!!

============= for someone worry about same problem ===============

step1. create rotation matrix for PoseMatrix in renderFrameQCAR

QCAR::Matrix34F poseMatrix = trackable->getPose();           

    poseRotMatrix = GLKMatrix3Make(poseMatrix.data[0], poseMatrix.data[1], poseMatrix.data[2], poseMatrix.data[4], poseMatrix.data[5], poseMatrix.data[6], poseMatrix.data[8], poseMatrix.data[9], poseMatrix.data[10]);

 step2. get rotation matrix for detected 3D object in touchesMoved

        GLKVector3 locationVec3 = GLKVector3Make(location.x, location.y, 0);

        GLKVector3 lastLocVec3 = GLKVector3Make(lastLoc.x, lastLoc.y, 0);

        

        locationVec3 = GLKMatrix3MultiplyVector3(poseRotMatrix, locationVec3);

        lastLocVec3 = GLKMatrix3MultiplyVector3(poseRotMatrix, lastLocVec3);

        

        GLKVector3 diffVec3 = GLKVector3Make(lastLocVec3.x - locationVec3.x, lastLocVec3.y - locationVec3.y, lastLocVec3.z - locationVec3.z);

        

        float rotX = GLKMathDegreesToRadians(diffVec3.x / 2.0);

        float rotY = GLKMathDegreesToRadians(diffVec3.y / 2.0);

        float rotZ = GLKMathDegreesToRadians(diffVec3.z / 2.0);

        

        bool isInvertible;

        GLKVector3 xAxis = GLKMatrix4MultiplyVector3(GLKMatrix4Invert(touchedObject.rotMatrix, &isInvertible), GLKVector3Make(1, 0, 0));

        touchedObject.rotMatrix = GLKMatrix4Rotate(touchedObject.rotMatrix, rotX, xAxis.x, xAxis.y, xAxis.z);

        

        GLKVector3 yAxis = GLKMatrix4MultiplyVector3(GLKMatrix4Invert(touchedObject.rotMatrix, &isInvertible), GLKVector3Make(0, 1, 0));

        touchedObject.rotMatrix = GLKMatrix4Rotate(touchedObject.rotMatrix, rotY, yAxis.x, yAxis.y, yAxis.z);

        

        GLKVector3 zAxis = GLKMatrix4MultiplyVector3(GLKMatrix4Invert(touchedObject.rotMatrix, &isInvertible), GLKVector3Make(0, 0, 1));

        touchedObject.rotMatrix = GLKMatrix4Rotate(touchedObject.rotMatrix, rotZ, zAxis.x, zAxis.y, zAxis.z);

 

 

step3. adjust in renderFrameQCAR

 

       ShaderUtils::multiplyMatrix(&modelViewMatrix.data[0], &detectedObject.rotMatrix.m[0], &modelViewMatrix.data[0]); 

How to get Quaternion or RotationMatrix from the Pose Matrix

July 20, 2012 - 1:40pm #2

The pose matrix that QCAR delivers is a 3x4 matrix row-major matrix. The 3x3 sub-matrix in left three columns is a pure rotation matrix (ortho-normal), whereas the right-most column is the translation vector.

The pose matrix represents the pose of the target as seen from the camera. Hence, the translation vector indicates where the target is as seen from the camera. A value of <0,0,0> means that camera and target are at the same position, whereas a value of <0,0,10> means that the target is 10 units away into the viewing direction of the camera (an seen in the middle of the camera image).

The rotation matrix represents how the target is rotated with respect to the camera plane. An identity matrix means that the target is parallel to the camera plane. This pose matrix tells where the target is with respect to the camera. This is exactly what is needed to draw an augmentation.

However, it does not tell how the camera is placed with respect to the target. If that is needed then the pose matrix needs to be inverted, which can easily be done by: [R | t]' = [R' | -R't].  Here, R and t are the rotation matrix and translation vector and ' is the matrix inverse. Please note that since R is a pure rotation matrix (ortho-normal) the inverse is the same as the transposed and hence trivial to calculate. Here is an image of the coordinate system set up by the pose matrix: https://ar.qualcomm.at/resources/images/coordinateSystems.jpg

Log in or register to post comments