美文网首页
iOS SceneKit欧拉角转四元数

iOS SceneKit欧拉角转四元数

作者: pokeey | 来源:发表于2018-07-16 17:08 被阅读0次

    使用欧拉角

        self.shipNode.eulerAngles = SCNVector3Make(pitch, -yaw, -roll);
    

    使用欧拉角会造成万向锁,转成四元数就没有问题了

        float fCosHRoll = cos(-roll * .5f);
        float fSinHRoll = sin(-roll * .5f);
        float fCosHPitch = cos(pitch * .5f);
        float fSinHPitch = sin(pitch * .5f);
        float fCosHYaw = cos(-yaw * .5f);
        float fSinHYaw = sin(-yaw * .5f);
     
        float w = fCosHRoll * fCosHPitch * fCosHYaw + fSinHRoll * fSinHPitch * fSinHYaw;
        float x = fCosHRoll * fSinHPitch * fCosHYaw + fSinHRoll * fCosHPitch * fSinHYaw;
        float y = fCosHRoll * fCosHPitch * fSinHYaw - fSinHRoll * fSinHPitch * fCosHYaw;
        float z = fSinHRoll * fCosHPitch * fCosHYaw - fCosHRoll * fSinHPitch * fSinHYaw;
     
        
        self.shipNode.orientation = SCNVector4Make(x, y, z,w);
    

    相关文章

      网友评论

          本文标题:iOS SceneKit欧拉角转四元数

          本文链接:https://www.haomeiwen.com/subject/ngbbpftx.html