【发布时间】:2016-03-16 13:21:27
【问题描述】:
我正在使用陀螺仪并获取我将用于在 SceneKit 上旋转对象的旋转矩阵。
来自陀螺仪的旋转矩阵使用 iPhone 的轴:
但我的应用程序可以横向使用主页按钮。所以,我的轴是:
- x = iphone 的 Y
- y = 否定 iphone的X
- z = iphone 的 Z
所以,我需要从基于 [x,y,z] 的加速度计接收到的旋转矩阵,并创建一个新的 [y, -x, -z] ...(是的,负 Z,因为对于这种特殊情况,我需要对象相对于 Z 旋转)。
好的,让它负旋转很容易,但是如何将轴 X 和 Y 从原始矩阵切换到新矩阵?
这是我目前所拥有的:
// I create a GLKMatrix4 from the CMRotationMatrix
GLKMatrix4 transform = GLKMatrix4Make(rotMatrix.m11, rotMatrix.m21, rotMatrix.m31, 0.0,
rotMatrix.m12, rotMatrix.m22, rotMatrix.m32, 0.0,
rotMatrix.m13, rotMatrix.m23, rotMatrix.m33, 0.0,
0.0, 0.0, 0.0, 1.0);
GLKMatrix4 negativeX = GLKMatrix4MakeXRotation(-M_PI);
GLKMatrix4 rotate = GLKMatrix4Multiply(transform, negativeX);
GLKMatrix4 negativeZ = GLKMatrix4MakeZRotation(-M_PI);
rotate = GLKMatrix4Multiply(rotate, negativeZ);
// ok, now I have [-x, y, -z]
// how do I switch X and Y and transform that into [y, -x, -z]?
【问题讨论】:
标签: iphone opengl-es rotational-matrices