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


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

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


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

示例1: CalculateFrictionImpulse

Vector3 RigidBodyContact::CalculateFrictionImpulse(Matrix3x3* inverseInertiaTensor)
{
    float inverseMass = Body[0]->GetInverseMass();

    // The equivalent of a cross-product in matrices is multiplication by a skew-symmetric matrix.
    // We calculate the matrix for converting between linear and angular quantities.
    Matrix3x3 impulseToTorque;
    impulseToTorque.SetSkewSymmetric(m_relativeContactPosition[0]);

    // Calculate the matrix to convert contact impulse to change in velocity in world coordinates
    Matrix3x3 deltaVelocityWorldspace = impulseToTorque;
    deltaVelocityWorldspace = deltaVelocityWorldspace * inverseInertiaTensor[0];
    deltaVelocityWorldspace = deltaVelocityWorldspace * impulseToTorque;
    deltaVelocityWorldspace *= -1;

    if (Body[1] != NULL)
    {
        impulseToTorque.SetSkewSymmetric(m_relativeContactPosition[1]);

        // Calculate the matrix to convert contact impulse to change in velocity in world coordinates
        Matrix3x3 deltaVelocityWorldspace2 = impulseToTorque;
        deltaVelocityWorldspace2 = deltaVelocityWorldspace2 * inverseInertiaTensor[1];
        deltaVelocityWorldspace2 = deltaVelocityWorldspace2 * impulseToTorque;
        deltaVelocityWorldspace2 *= -1;

        // Add to the total delta velocity and inverse mass
        deltaVelocityWorldspace = deltaVelocityWorldspace + deltaVelocityWorldspace2;
        inverseMass += Body[1]->GetInverseMass();
    }

    // Perform a change of basis to convert into contact coordinates
    Matrix3x3 deltaVelocity = m_contactToWorld.Transpose();
    deltaVelocity = deltaVelocity * deltaVelocityWorldspace;        // TODO multiplication order?
    deltaVelocity = deltaVelocity * m_contactToWorld;

    // Add in the linear velocity change
    deltaVelocity[0][0] += inverseMass;
    deltaVelocity[1][1] += inverseMass;
    deltaVelocity[2][2] += inverseMass;

    // Invert to get the impulse needed per unit velocity
    Matrix3x3 impulseMatrix = deltaVelocity.Inverse();

    // Find the target velocities to kill
    Vector3 velKill(m_desiredDeltaVelocity, -m_contactVelocity.y(), -m_contactVelocity.z());

    // Find the impulse to kill target velocities
    Vector3 impulseContact = impulseMatrix * velKill;

    // Check for exceeding friction
    float planarImpulse = sqrtf(impulseContact.y()*impulseContact.y() + impulseContact.z()*impulseContact.z());
    if (planarImpulse > impulseContact.x() * Friction)
    {
        // We need to use dynamic friction
        impulseContact.SetY(impulseContact.y() / planarImpulse);
        impulseContact.SetZ(impulseContact.z() / planarImpulse);
        impulseContact.SetX(deltaVelocity[0][0] +
            deltaVelocity[0][1] * Friction*impulseContact.y() +
            deltaVelocity[0][2] * Friction*impulseContact.z());
        impulseContact.SetX(m_desiredDeltaVelocity / impulseContact.x());
        impulseContact.SetY(impulseContact.y()*Friction*impulseContact.x());
        impulseContact.SetZ(impulseContact.z()*Friction*impulseContact.x());
    }
    return impulseContact;
}
开发者ID:gnleece,项目名称:Dogwood,代码行数:65,代码来源:RigidBodyContact.cpp


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