Use rotation vector from Aruco in Unity3d
Hi, I am using OpenCV, Aruco and Unity3d for an augmented reality application. I would like to spawn objects on detected aruco markers, and the position is fine, but I cannot get the rotation right. Aruco gives a vector with 3 elements for the rotation, and as far as I found out it is an axis-angle representation with the angle being the module of the vector. I tried to get the rotation matrix with Rodrigues and use this approach to get to the Quaternion for Unity3d, but the values are almost always 0, sometimes they jump to random angles.
Then I saw that Unity has a Quaternion.AngleAxis function that I tried to use like this:
float theta = (float)(Math.Sqrt(m.x*m.x + m.y*m.y + m.z*m.z)*180/Math.PI);
Vector3 axis = new Vector3 (m.x, -m.y, m.z); //multiply m.y by -1 since in Unity y-axis points upward
Quaternion rot = Quaternion.AngleAxis (theta, axis);
The values seem to be fine now, and the rotation looks good as long as the marker is only rotated along one axis. For example if I rotate the marker to the left and then tilt it forwards, in unity the marker does not tilt forwards but brings it right side to the front (I do not know how to describe this any better).
Has anybody tried this? Any idea on how to convert the values? I guess that somehow the axes are different, but I cannot figure out what to change.