当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix3x3::trace方法代码示例

本文整理汇总了C++中Matrix3x3::trace方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3x3::trace方法的具体用法?C++ Matrix3x3::trace怎么用?C++ Matrix3x3::trace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix3x3的用法示例。


在下文中一共展示了Matrix3x3::trace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: matrix

void QuaternionTest::matrix() {
    Vector3 axis = Vector3(-3.0f, 1.0f, 5.0f).normalized();

    Quaternion q = Quaternion::rotation(Deg(37.0f), axis);
    Matrix3x3 m = Matrix4::rotation(Deg(37.0f), axis).rotationScaling();

    /* Verify that negated quaternion gives the same rotation */
    CORRADE_COMPARE(q.toMatrix(), m);
    CORRADE_COMPARE((-q).toMatrix(), m);

    std::ostringstream o;
    Error::setOutput(&o);
    Quaternion::fromMatrix(m*2);
    CORRADE_COMPARE(o.str(), "Math::Quaternion::fromMatrix(): the matrix is not orthogonal\n");

    /* Trace > 0 */
    CORRADE_VERIFY(m.trace() > 0.0f);
    CORRADE_COMPARE(Quaternion::fromMatrix(m), q);

    /* Trace < 0, max is diagonal[2] */
    Matrix3x3 m2 = Matrix4::rotation(Deg(130.0f), axis).rotationScaling();
    Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis);
    CORRADE_VERIFY(m2.trace() < 0.0f);
    CORRADE_VERIFY(m2.diagonal()[2] > std::max(m2.diagonal()[0], m2.diagonal()[1]));
    CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2);

    /* Trace < 0, max is diagonal[1] */
    Vector3 axis2 = Vector3(-3.0f, 5.0f, 1.0f).normalized();
    Matrix3x3 m3 = Matrix4::rotation(Deg(130.0f), axis2).rotationScaling();
    Quaternion q3 = Quaternion::rotation(Deg(130.0f), axis2);
    CORRADE_VERIFY(m3.trace() < 0.0f);
    CORRADE_VERIFY(m3.diagonal()[1] > std::max(m3.diagonal()[0], m3.diagonal()[2]));
    CORRADE_COMPARE(Quaternion::fromMatrix(m3), q3);

    /* Trace < 0, max is diagonal[0] */
    Vector3 axis3 = Vector3(5.0f, -3.0f, 1.0f).normalized();
    Matrix3x3 m4 = Matrix4::rotation(Deg(130.0f), axis3).rotationScaling();
    Quaternion q4 = Quaternion::rotation(Deg(130.0f), axis3);
    CORRADE_VERIFY(m4.trace() < 0.0f);
    CORRADE_VERIFY(m4.diagonal()[0] > std::max(m4.diagonal()[1], m4.diagonal()[2]));
    CORRADE_COMPARE(Quaternion::fromMatrix(m4), q4);
}
开发者ID:BeiLuoShiMen,项目名称:magnum,代码行数:42,代码来源:QuaternionTest.cpp

示例2: set

void Quaternion::set(const Matrix3x3& rotation)
{
    float trace = rotation.trace();
		
    if(trace > 0.0f)
    {
        float s = 0.f / sqrt(trace + 1.0f);
         w = 0.25f / s;
         x = (rotation[2].y - rotation[1].z) * s;
         y = (rotation[0].z - rotation[2].x) * s;
         z = (rotation[1].x - rotation[0].y) * s;
    }
    else if((rotation[0].x > rotation[1].y) && (rotation[0].x > rotation[2].z))
    {
        float s = sqrt(rotation[0].x - rotation[1].y - rotation[2].z + 1.0f) * 2;
        float invS = 1.0f / s;
        w = (rotation[2].y - rotation[1].z) * invS;
        x = 0.25f * s;
        y = (rotation[0].y + rotation[1].x) * invS;
        z = (rotation[0].z + rotation[2].x) * invS;		
    }
    else if(rotation[1].y > rotation[2].z)
    {
        float s = sqrt(rotation[1].y - rotation[0].x - rotation[2].z + 1.0f) * 2;
        float invS = 1.0f / s;
        w = (rotation[0].z - rotation[2].x) * invS;
        x = (rotation[0].y + rotation[1].x) * invS;
        y = 0.25f * s;
        z = (rotation[1].y + rotation[2].y) * invS;		
    }
    else
    {
        float s = sqrt(rotation[2].z - rotation[0].x - rotation[1].y + 1.0f) * 2;
        float invS = 1.0f / s;
        w = (rotation[1].x - rotation[0].x) * invS;
        x = (rotation[0].z + rotation[2].x) * invS;
        y = (rotation[1].z + rotation[2].y) * invS;
        z = 0.25f * s;
    }
}
开发者ID:A-K,项目名称:Huurre3D,代码行数:40,代码来源:Quaternion.cpp


注:本文中的Matrix3x3::trace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。