Search in sources :

Example 1 with Velocity

use of spacegraph.space2d.phys.dynamics.contacts.Velocity in project narchy by automenta.

the class RopeJoint method solveVelocityConstraints.

@Override
public void solveVelocityConstraints(final SolverData data) {
    float targetLength = targetLength();
    Velocity VA = data.velocities[indexA];
    Tuple2f vA = VA;
    float wA = VA.w;
    Velocity VB = data.velocities[indexB];
    Tuple2f vB = VB;
    float wB = VB.w;
    // Cdot = dot(u, v + cross(w, r))
    Tuple2f vpA = pool.popVec2();
    Tuple2f vpB = pool.popVec2();
    Tuple2f temp = pool.popVec2();
    Tuple2f.crossToOutUnsafe(wA, m_rA, vpA);
    vpA.added(vA);
    Tuple2f.crossToOutUnsafe(wB, m_rB, vpB);
    vpB.added(vB);
    float dLen = length - targetLength;
    float Cdot = Tuple2f.dot(m_u, temp.set(vpB).subbed(vpA));
    // Predictive constraint.
    // if (dLen < 0.0f) {
    Cdot += data.step.inv_dt * Math.abs(dLen) * positionFactor;
    // }
    float impulse = -m_mass * Cdot;
    float oldImpulse = m_impulse;
    m_impulse = MathUtils.min(0.0f, m_impulse + impulse);
    impulse = m_impulse - oldImpulse;
    float Px = impulse * m_u.x;
    float Py = impulse * m_u.y;
    vA.x -= m_invMassA * Px;
    vA.y -= m_invMassA * Py;
    VA.w = wA - m_invIA * (m_rA.x * Py - m_rA.y * Px);
    vB.x += m_invMassB * Px;
    vB.y += m_invMassB * Py;
    VB.w = wB + m_invIB * (m_rB.x * Py - m_rB.y * Px);
    pool.pushVec2(3);
// data.velocities[m_indexA].v = vA;
// data.velocities[m_indexB].v = vB;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Velocity(spacegraph.space2d.phys.dynamics.contacts.Velocity)

Aggregations

Velocity (spacegraph.space2d.phys.dynamics.contacts.Velocity)1 Tuple2f (spacegraph.util.math.Tuple2f)1