【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转

//绕着与axis平行的任意轴旋转

    void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 axis)

    {

        AniNodeMap::iterator itr = _anMap.find(name);

        if(itr != _anMap.end())

        {

            osg::Quat quat;

            quat.makeRotate(angle, axis);



            //先移动到axis,旋转,然后再移动到axisPos

            osg::Matrix matrix = osg::Matrix::translate(axisPos) * 

                osg::Matrix::rotate(quat) * 

                osg::Matrix::translate(-axisPos);



            if(itr->second)

            {

                osg::Matrix matrix1 = dynamic_cast<osg::MatrixTransform*>(itr->second)->getMatrix();

                matrix1 *= matrix;

                dynamic_cast<osg::MatrixTransform*>(itr->second)->setMatrix(matrix1);

            }

        }

    }

你可能感兴趣的:(axis)