矩陣中的縮放值是會影響旋轉值的 經過乘以縮放的逆陣,來取正確的旋轉值:ide
osg::Matrix matrixSimple = osg::Matrix::identity(); matrixSimple.makeRotate(osg::Vec3(0, 0, 1), osg::Vec3(0, -1, 0)); osg::Quat q1 = matrixSimple.getRotate(); OSG_NOTICE << "1:\t"<< q1.x()<<"\t"<< q1.y()<<"\t"<<q1.z()<<"\t"<<q1.w() << std::endl; // 有縮放 旋轉值就錯了: osg::Matrix scale = osg::Matrix::scale(osg::Vec3(1.5, 1.2, 3.0)); matrixSimple*= scale; q1 = matrixSimple.getRotate(); OSG_NOTICE << "1:\t" << q1.x() << "\t" << q1.y() << "\t" << q1.z() << "\t" << q1.w() << std::endl; // 取正確的值: matrixSimple *= osg::Matrix::inverse(scale); q1 = matrixSimple.getRotate(); OSG_NOTICE << "1:\t" << q1.x() << "\t" << q1.y() << "\t" << q1.z() << "\t" << q1.w() << std::endl;
輸出: code