Tag: quaternions

使用四元数的Arcball旋转(使用iOS GLKit)

我正在寻找一个四元数三维模型arcball旋转的简单实现, 特别是在iOS上使用GLKit 。 到目前为止,我已经检查了以下来源: 使用GLKit进行Arcball旋转 如何使用OpenGL触摸旋转3D对象 我也一直在尝试从这里和这里了解源代码和math。 我可以旋转我的物体,但是它一直在某个angular度跳跃,所以我担心万向节锁正在发挥作用。 我正在使用手势识别器来控制旋转(平移手势会影响滚动和偏航,旋转手势会影响音高)。 我附上我的四元数处理以及模型视图matrix转换的代码。 variables: GLKQuaternion rotationE; 四元数处理: – (void)rotateWithXY:(float)x and:(float)y { const float rate = M_PI/360.0f; GLKVector3 up = GLKVector3Make(0.0f, 1.0f, 0.0f); GLKVector3 right = GLKVector3Make(1.0f, 0.0f, 0.0f); up = GLKQuaternionRotateVector3(GLKQuaternionInvert(self.rotationE), up); self.rotationE = GLKQuaternionMultiply(self.rotationE, GLKQuaternionMakeWithAngleAndVector3Axis(x*rate, up)); right = GLKQuaternionRotateVector3(GLKQuaternionInvert(self.rotationE), right); self.rotationE = GLKQuaternionMultiply(self.rotationE, GLKQuaternionMakeWithAngleAndVector3Axis(y*rate, right)); } – […]