@Override public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { final Rotation xfq = xf.q; float centerx = xfq.c * m_p.x - xfq.s * m_p.y + xf.p.x; float centery = xfq.s * m_p.x + xfq.c * m_p.y + xf.p.y; float dx = p.x - centerx; float dy = p.y - centery; float d1 = JBoxUtils.sqrt(dx * dx + dy * dy); normalOut.x = dx * 1 / d1; normalOut.y = dy * 1 / d1; return d1 - radius; }
/** * Friction mixing law. The idea is to allow either fixture to drive the restitution to zero. For * example, anything slides on ice. * * @param friction1 * @param friction2 * @return */ public static final float mixFriction(float friction1, float friction2) { return JBoxUtils.sqrt(friction1 * friction2); }
/** * Friction mixing law. Feel free to customize this. * * @param friction1 friction1 * @param friction2 friction2 * @return mixed friction */ public static float mixFriction(float friction1, float friction2) { return JBoxUtils.sqrt(friction1 * friction2); }
void solveSpring(final TimeStep step) { float springStrength = step.inv_dt * m_springStrength; for (int k = 0; k < m_pairCount; k++) { final Pair pair = m_pairBuffer[k]; if ((pair.flags & ParticleTypeInternal.b2_springParticle) != 0) { int a = pair.indexA; int b = pair.indexB; final Vec2 pa = m_positionBuffer.data[a]; final Vec2 pb = m_positionBuffer.data[b]; final float dx = pb.x - pa.x; final float dy = pb.y - pa.y; float r0 = pair.distance; float r1 = JBoxUtils.sqrt(dx * dx + dy * dy); if (r1 == 0) r1 = Float.MAX_VALUE; float strength = springStrength * pair.strength; final float fx = strength * (r0 - r1) / r1 * dx; final float fy = strength * (r0 - r1) / r1 * dy; final Vec2 va = m_velocityBuffer.data[a]; final Vec2 vb = m_velocityBuffer.data[b]; va.x -= fx; va.y -= fy; vb.x += fx; vb.y += fy; } } }
float d1 = JBoxUtils.sqrt(dx * dx + dy * dy); if (d1 > 0) { normalOut.x = 1 / d1 * dx;
public final static float distance(Vec2 v1, Vec2 v2) { return sqrt(distanceSquared(v1, v2)); } }
public void addContact(int a, int b) { assert (a != b); Vec2 pa = m_positionBuffer.data[a]; Vec2 pb = m_positionBuffer.data[b]; float dx = pb.x - pa.x; float dy = pb.y - pa.y; float d2 = dx * dx + dy * dy; // assert(d2 != 0); if (d2 < m_squaredDiameter) { if (m_contactCount >= m_contactCapacity) { int oldCapacity = m_contactCapacity; int newCapacity = m_contactCount != 0 ? 2 * m_contactCount : JBoxSettings.minParticleBufferCapacity; m_contactBuffer = BufferUtils.reallocateBuffer(ParticleContact.class, m_contactBuffer, oldCapacity, newCapacity); m_contactCapacity = newCapacity; } float invD = d2 != 0 ? JBoxUtils.sqrt(1 / d2) : Float.MAX_VALUE; ParticleContact contact = m_contactBuffer[m_contactCount]; contact.indexA = a; contact.indexB = b; contact.flags = m_flagsBuffer.data[a] | m_flagsBuffer.data[b]; contact.weight = 1 - d2 * invD * m_inverseDiameter; contact.normal.x = invD * dx; contact.normal.y = invD * dy; m_contactCount++; } }
float a = -(c + JBoxUtils.sqrt(sigma));
distance = JBoxUtils.sqrt(minDistance2); normalOut.x = xfqc * minDistanceX - xfqs * minDistanceY; normalOut.y = xfqs * minDistanceX + xfqc * minDistanceY;
float dx = positions[bodies[next].m_islandIndex].c.x - positions[bodies[i].m_islandIndex].c.x; float dy = positions[bodies[next].m_islandIndex].c.y - positions[bodies[i].m_islandIndex].c.y; float dist = JBoxUtils.sqrt(dx * dx + dy * dy); if (dist < JBoxSettings.EPSILON) { dist = 1.0f; delta.mulLocal(JBoxSettings.maxLinearCorrection / JBoxUtils.sqrt(normSqrd));
float rc = Vec2.dot(oa, pa) + Vec2.dot(ob, pb) + Vec2.dot(oc, pc); float r2 = rs * rs + rc * rc; float invR = r2 == 0 ? Float.MAX_VALUE : JBoxUtils.sqrt(1f / r2); rs *= invR; rc *= invR;
float ratio = JBoxSettings.maxTranslation / JBoxUtils.sqrt(translationx * translationx + translationy * translationy); v.mulLocal(ratio);
float determinant = pv * pv - v2 * (p2 - m_squaredDiameter); if (determinant >= 0) { float sqrtDeterminant = JBoxUtils.sqrt(determinant);
float v2 = v.x * v.x + v.y * v.y; if (v2 > criticalVelocytySquared) { float a = v2 == 0 ? Float.MAX_VALUE : JBoxUtils.sqrt(criticalVelocytySquared / v2); v.x *= a; v.y *= a;
/ JBoxUtils.sqrt(translationx * translationx + translationy * translationy); v.x *= ratio; v.y *= ratio;