@Override public int getMaxBalance() { int maxBalance = 0; for (int i = 0; i < m_nodeCapacity; ++i) { if (m_height[i] <= 1) { continue; } assert (m_child1[i] != NULL_NODE); int child1 = m_child1[i]; int child2 = m_child2[i]; int balance = JBoxUtils.abs(m_height[child2] - m_height[child1]); maxBalance = JBoxUtils.max(maxBalance, balance); } return maxBalance; }
/** * Extract the angle from this matrix (assumed to be a rotation matrix). * * @return angle */ public final float getAngle() { return JBoxUtils.atan2(ex.y, ex.x); }
JBoxUtils.clamp(vcp.tangentImpulse + lambda, -maxFriction, maxFriction); lambda = newImpulse - vcp.tangentImpulse; vcp.tangentImpulse = newImpulse;
public final static float distance(Vec2 v1, Vec2 v2) { return sqrt(distanceSquared(v1, v2)); } }
C1.y = aB - aA - m_referenceAngle; float linearError = JBoxUtils.abs(C1.x); float angularError = JBoxUtils.abs(C1.y); if (m_enableLimit) { float translation = Vec2.dot(axis, d); if (JBoxUtils.abs(m_upperTranslation - m_lowerTranslation) < 2.0f * JBoxSettings.linearSlop) { JBoxUtils.clamp(translation, -JBoxSettings.maxLinearCorrection, JBoxSettings.maxLinearCorrection); linearError = JBoxUtils.max(linearError, JBoxUtils.abs(translation)); active = true; } else if (translation <= m_lowerTranslation) { JBoxUtils.clamp(translation - m_lowerTranslation + JBoxSettings.linearSlop, -JBoxSettings.maxLinearCorrection, 0.0f); linearError = JBoxUtils.max(linearError, m_lowerTranslation - translation); active = true; } else if (translation >= m_upperTranslation) { JBoxUtils.clamp(translation - m_upperTranslation - JBoxSettings.linearSlop, 0.0f, JBoxSettings.maxLinearCorrection); linearError = JBoxUtils.max(linearError, translation - m_upperTranslation); active = true;
float oldImpulse = m_motorImpulse; float maxImpulse = data.step.dt * m_maxMotorForce; m_motorImpulse = JBoxUtils.clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_motorImpulse - oldImpulse; m_impulse.z = JBoxUtils.max(m_impulse.z, 0.0f); } else if (m_limitState == LimitState.AT_UPPER) { m_impulse.z = JBoxUtils.min(m_impulse.z, 0.0f);
JBoxUtils.clamp(angle - m_lowerAngle, -JBoxSettings.maxAngularCorrection, JBoxSettings.maxAngularCorrection); limitImpulse = -m_motorMass * C; angularError = JBoxUtils.abs(C); } else if (m_limitState == LimitState.AT_LOWER) { float C = angle - m_lowerAngle; C = JBoxUtils.clamp(C + JBoxSettings.angularSlop, -JBoxSettings.maxAngularCorrection, 0.0f); limitImpulse = -m_motorMass * C; } else if (m_limitState == LimitState.AT_UPPER) { C = JBoxUtils.clamp(C - JBoxSettings.angularSlop, 0.0f, JBoxSettings.maxAngularCorrection); limitImpulse = -m_motorMass * C;
int n = JBoxUtils.min(num, JBoxSettings.maxPolygonVertices); boolean unique = true; for (int j = 0; j < tempCount; ++j) { if (JBoxUtils.distanceSquared(v, ps[j]) < 0.5f * JBoxSettings.linearSlop) { unique = false; break;
for (float y = JBoxUtils.floor(aabb.lowerBound.y / stride) * stride; y < upperBoundY; y += stride) { for (float x = JBoxUtils.floor(aabb.lowerBound.x / stride) * stride; x < upperBoundX; x += stride) { Vec2 p = tempVec; pair.flags = contact.flags; pair.strength = groupDef.getStrength(); pair.distance = JBoxUtils.distance(m_positionBuffer.data[a], m_positionBuffer.data[b]); m_pairCount++;
/** * Create a chain with isolated end vertices. * * @param vertices an array of vertices, these are copied * @param count the vertex count */ public void createChain(final Vec2 vertices[], int count) { assert (m_vertices == null && m_count == 0); assert (count >= 2); m_count = count; m_vertices = new Vec2[m_count]; for (int i = 1; i < m_count; i++) { Vec2 v1 = vertices[i - 1]; Vec2 v2 = vertices[i]; // If the code crashes here, it means your vertices are too close together. if (JBoxUtils.distanceSquared(v1, v2) < JBoxSettings.linearSlop * JBoxSettings.linearSlop) { throw new RuntimeException("Vertices of chain shape are too close together"); } } for (int i = 0; i < m_count; i++) { m_vertices[i] = new Vec2(vertices[i]); } m_hasPrevVertex = false; m_hasNextVertex = false; m_prevVertex.setZero(); m_nextVertex.setZero(); }
public static final float pow(float a, float b) { if (JBoxSettings.FAST_POW) { return fastPow(a, b); } else { return (float) StrictMath.pow(a, b); } }
public static final float atan2(final float y, final float x) { if (JBoxSettings.FAST_ATAN2) { return fastAtan2(y, x); } else { return (float) StrictMath.atan2(y, x); } }
public static final int floor(final float x) { if (JBoxSettings.FAST_FLOOR) { return fastFloor(x); } else { return (int) StrictMath.floor(x); } }