iPhone rotation quaternion absolute coordinates?

跟風遠走 提交于 2019-12-25 03:18:12

问题


I have an iPhone with gyroscope.

Let's say I have a quaternion of the phone rotation Q.

I want to show points on screen relative of the world absolute coordinates. So with every rotation of my phone this points will be "still" in the real 3d space (sort of augmented reality). Let's say it is 4 points forming a rectangle.

So I have created 4 points in 3d space relative to my phone screen and apply the transformation of Q to each of it.

I thought it should be very simple but my points get transformed not relative to the world coordinates but to the something coordinates I don't understand, may be phone axis related?. Could you please help me with this? I need to create new view on the screen which will be projection from the virtual points in absolute 3d space to the rotated camera.

My rotation results seems right as long as I am not rotating the phone along its 'normal' axis (perpendicular to screen). But rotation on that direction results in completely wrong points translation.

Pseudocode included.

motionManager.StartDeviceMotionUpdates

        Quaternion Q;//quaternion read from CMAttitude above, relative frame: XArbitraryZVertical
        var Qi=Q.Conjugate;

        var vX = new Vector3d (-1, 0, 2);
        var vY = new Vector3d (1, 0, 2);
        var vZ = new Vector3d (1, 0, -2);
        var vW = new Vector3d (-1, 0, -2);

        var vXn=Vector3d.Transform(vX,Qi);
        var vYn=Vector3d.Transform(vX,Qi);
        var vZn=Vector3d.Transform(vX,Qi);
        var vWn=Vector3d.Transform(vW,Qi);

        var convertPixels = 50;

        vXn = vXn * convertPixels;
        vYn = vYn * convertPixels;
        vZn = vZn * convertPixels;
        vWn = vWn * convertPixels;

        //screen projection

        X.Frame = new RectangleF (new PointF ((float)(videoArea.Width / 2 + vXn.X), (float)(videoArea.Height / 2 + vXn.Z)), new SizeF (10, 10));
        Y.Frame = new RectangleF (new PointF ((float)(videoArea.Width / 2 + vYn.X), (float)(videoArea.Height / 2 + vYn.Z)), new SizeF (10, 10));
        Z.Frame = new RectangleF (new PointF ((float)(videoArea.Width / 2 + vZn.X), (float)(videoArea.Height / 2 + vZn.Z)), new SizeF (10, 10));
        W.Frame = new RectangleF (new PointF ((float)(videoArea.Width / 2 + vWn.X), (float)(videoArea.Height / 2 + vWn.Z)), new SizeF (10, 10));

回答1:


Finally I done it with OpenGL matrices. I use multiplication of the rotation matrix given from phone and the generated projection matrix. The key feature was transforming the coordinates of rotation from the iPhone to OpenGL (right handed to left-handed). I got the new axis of rotation with -x and -y, created the new rotation matrix from this new axis and angle. And that matrix gives me the right results.



来源:https://stackoverflow.com/questions/25363781/iphone-rotation-quaternion-absolute-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!