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


C++ Contact::bodyA方法代码示例

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


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

示例1: solvePositions

void PhysicsWorld::solvePositions(Contact & contact)
{
    if (!contact.intersect())
    {
        return;
    }

    contact.update();

    auto & bodyA = contact.bodyA();
    auto & bodyB = contact.bodyB();

    auto & transformA = bodyA.transform();
    auto & transformB = bodyB.transform();

    auto mA = bodyA.inverseMass();
    auto mB = bodyB.inverseMass();

    auto & iA = bodyA.worldInverseInertia();
    auto & iB = bodyB.worldInverseInertia();

    auto & cA = transformA.position();
    auto & cB = transformB.position();

    for (uint p = 0; p < contact.numPoints(); p++)
    {
        auto & point = contact.point(p);

        auto & n = point.normal;

        auto position = point.position;
        auto separation = -point.depth;

        auto rA = position - cA;
        auto rB = position - cB;

        // Track max constraint error.
        //  auto minSeparation = std::min(minSeparation, separation);

        // Prevent large corrections and allow slop.
        auto C = std::min(std::max(0.5f * (separation + LINEAR_SLOP), -MAX_LINEAR_CORRECTION), 0.0f);

        // Compute the effective mass.
        auto normalMass = point.normalMass;

        // Compute normal impulse
        auto impulse = normalMass > 0.0f ? -C / normalMass : 0.0f;

        auto P = impulse * n;

        std::cout << P << " " << separation << " " << (-mA * P) << " " << (mB * P) << std::endl;

        transformA.setPosition(transformA.position() - mA * P);
        transformA.setOrientation(QuaternionAxisRotation(transformA.orientation(), iA * glm::cross(rA, -P)));

        transformB.setPosition(transformB.position() + mB * P);
        transformB.setOrientation(QuaternionAxisRotation(transformB.orientation(), iB * glm::cross(rB, P)));
    }
}
开发者ID:mrzzzrm,项目名称:Deliberation2,代码行数:59,代码来源:PhysicsWorld.cpp

示例2: warmStart

void PhysicsWorld::warmStart(Contact & contact) const
{
    if (!contact.intersect())
    {
        return;
    }

    auto & bodyA = contact.bodyA();
    auto & bodyB = contact.bodyB();

    auto mA = bodyA.inverseMass();
    auto & iA = bodyA.worldInverseInertia();
    auto & vA = bodyA.linearVelocity();
    auto & wA = bodyA.angularVelocity();
    auto & cA = bodyA.transform().position();

    auto mB = bodyB.inverseMass();
    auto & iB = bodyB.worldInverseInertia();
    auto & vB = bodyB.linearVelocity();
    auto & wB = bodyB.angularVelocity();
    auto & cB = bodyB.transform().position();

    for (uint p = 0; p < contact.numPoints(); p++)
    {
        auto & point = contact.point(p);

        auto & n = point.normal;

        auto rA = point.position - cA;
        auto rB = point.position - cB;

        auto lambda = point.normalImpulseAccumulator;

        auto J = lambda * n;

        bodyA.setLinearVelocity(vA - mA * J);
        bodyA.setAngularVelocity(wA - iA * glm::cross(rA, J));

        bodyB.setLinearVelocity(vB + mB * J);
        bodyB.setAngularVelocity(wB + iB * glm::cross(rB, J));
    }
}
开发者ID:mrzzzrm,项目名称:Deliberation2,代码行数:42,代码来源:PhysicsWorld.cpp

示例3: solveContactVelocities

void PhysicsWorld::solveContactVelocities(Contact & contact)
{
    if (!contact.intersect())
    {
        return;
    }

    auto & bodyA = contact.bodyA();
    auto & bodyB = contact.bodyB();

    auto mA = bodyA.inverseMass();
    auto & iA = bodyA.worldInverseInertia();
    auto & vA = bodyA.linearVelocity();
    auto & wA = bodyA.angularVelocity();
    auto & cA = bodyA.transform().position();

    auto mB = bodyB.inverseMass();
    auto & iB = bodyB.worldInverseInertia();
    auto & vB = bodyB.linearVelocity();
    auto & wB = bodyB.angularVelocity();
    auto & cB = bodyB.transform().position();

    // Coefficient of restitution
    auto e = contact.restitution();

    /**
     * Solve tangent velocities
     */
    for (uint p = 0; p < contact.numPoints(); p++)
    {
        auto & point = contact.point(p);

        auto rA = point.position - cA;
        auto rB = point.position - cB;

        // Relative velocity along normal
        auto vra = bodyA.localVelocity(rA);
        auto vrb = bodyB.localVelocity(rB);
        auto vRel = vrb - vra;
        auto vRelNormal = glm::dot(point.normal, vRel);

        // Relative velocity along tangent
        auto vRelTangent = vRel - (vRelNormal * point.normal);

        if (vRelTangent == glm::vec3(0.0f)) {
            continue;
        }

        auto tangent = glm::normalize(vRelTangent);

        auto tangentMass = glm::dot(glm::cross(iA * glm::cross(rA, tangent), rA) +
                                    glm::cross(iB * glm::cross(rB, tangent), rB), tangent) + mA + mB;

        if (tangentMass == 0.0f) {
            continue;
        }

        auto lambda = -glm::length(vRelTangent) / tangentMass;

        auto maxFriction = contact.friction() * point.normalImpulseAccumulator;
        auto newImpulse = std::max(-maxFriction, std::min<float>(maxFriction, point.tangentImpulseAccumulator + lambda));
        lambda = newImpulse - point.tangentImpulseAccumulator;

        auto P = lambda * tangent;

        bodyA.setLinearVelocity(vA - mA * P);
        bodyA.setAngularVelocity(wA - iA * glm::cross(rA, P));

        bodyB.setLinearVelocity(vB + mB * P);
        bodyB.setAngularVelocity(wB + iB * glm::cross(rB, P));
    }

    /**
     * Solve normal velocities
     */
    for (uint p = 0; p < contact.numPoints(); p++)
    {
        auto & point = contact.point(p);

        auto rA = point.position - cA;
        auto rB = point.position - cB;

        auto & n = point.normal;
        auto normalMass = point.normalMass;
        auto velocityBias = point.velocityBias;

        // Relative velocity along normal
        auto vra = bodyA.localVelocity(rA);
        auto vrb = bodyB.localVelocity(rB);
        auto vRel = glm::dot(n, vrb - vra);

        //
        auto vDelta = velocityBias - vRel;

        auto lambda = vDelta / normalMass;

        auto newNormalImpulseAccumulator = std::max(lambda + point.normalImpulseAccumulator, 0.0f);
        lambda = newNormalImpulseAccumulator - point.normalImpulseAccumulator;
        point.normalImpulseAccumulator += lambda;

//.........这里部分代码省略.........
开发者ID:mrzzzrm,项目名称:Deliberation2,代码行数:101,代码来源:PhysicsWorld.cpp


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