【问题标题】:OpenGL : switching and inverting axisOpenGL:切换和反转轴
【发布时间】: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


    【解决方案1】:

    一个 3x3 矩阵,例如您的旋转矩阵,应用为:

    [a b c] [x]    [a*x + b*y + c*z]    x * (a, e, i) +
    [e f g] [y]  = [e*x + f*y + g*z] =  y * (b, f, j) +
    [i j k] [z]    [i*x + j*y + k*z]    z * (c, g, z)
    

    即它实际上是三个向量。在您的rotMatrix 中,(m11, m12, m13) 是告诉您转换后的 x 轴将采用的方向的向量,(m21, m22, m23) 是 y,(m31, m32, m33) 是 z。

    如果您当前用于 x 向量的内容是您实际想要用于 y 值的内容,则只需交换列。如果你想否定一个轴,只需否定列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2020-11-29
      • 2017-12-18
      • 2014-09-22
      相关资源
      最近更新 更多