/** * Extract the angle from this matrix (assumed to be a rotation matrix). * * @return */ public final float getAngle() { return MathUtils.atan2(ex.y, ex.x); }
@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 = MathUtils.abs(m_height[child2] - m_height[child1]); maxBalance = MathUtils.max(maxBalance, balance); } return maxBalance; }
C1.y = aB - aA - m_referenceAngle; float linearError = MathUtils.abs(C1.x); float angularError = MathUtils.abs(C1.y); if (m_enableLimit) { float translation = Vec2.dot(axis, d); if (MathUtils.abs(m_upperTranslation - m_lowerTranslation) < 2.0f * Settings.linearSlop) { MathUtils.clamp(translation, -Settings.maxLinearCorrection, Settings.maxLinearCorrection); linearError = MathUtils.max(linearError, MathUtils.abs(translation)); active = true; } else if (translation <= m_lowerTranslation) { MathUtils.clamp(translation - m_lowerTranslation + Settings.linearSlop, -Settings.maxLinearCorrection, 0.0f); linearError = MathUtils.max(linearError, m_lowerTranslation - translation); active = true; } else if (translation >= m_upperTranslation) { MathUtils.clamp(translation - m_upperTranslation - Settings.linearSlop, 0.0f, Settings.maxLinearCorrection); linearError = MathUtils.max(linearError, translation - m_upperTranslation); active = true;
MathUtils.clamp(angle - m_lowerAngle, -Settings.maxAngularCorrection, Settings.maxAngularCorrection); limitImpulse = -m_motorMass * C; angularError = MathUtils.abs(C); } else if (m_limitState == LimitState.AT_LOWER) { float C = angle - m_lowerAngle; C = MathUtils.clamp(C + Settings.angularSlop, -Settings.maxAngularCorrection, 0.0f); limitImpulse = -m_motorMass * C; } else if (m_limitState == LimitState.AT_UPPER) { C = MathUtils.clamp(C - Settings.angularSlop, 0.0f, Settings.maxAngularCorrection); limitImpulse = -m_motorMass * C;
@Override public void step(TestbedSettings settings) { boolean advanceRay = settings.pause == false || settings.singleStep; super.step(settings); addTextLine("Press 1-5 to drop stuff"); float L = 25.0f; Vec2 point1 = new Vec2(0.0f, 10.0f); Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle))); Vec2 point2 = point1.add(d); callback.m_fixture = null; getWorld().raycast(callback, point1, point2); if (callback.m_fixture != null) { getDebugDraw().drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f)); getDebugDraw().drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f)); Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point); getDebugDraw().drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f)); } else { getDebugDraw().drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f)); } if (advanceRay) { m_angle += 0.25f * MathUtils.PI / 180.0f; } }
MathUtils.clamp(vcp.tangentImpulse + lambda, -maxFriction, maxFriction); lambda = newImpulse - vcp.tangentImpulse; vcp.tangentImpulse = newImpulse;
float oldImpulse = m_motorImpulse; float maxImpulse = data.step.dt * m_maxMotorForce; m_motorImpulse = MathUtils.clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_motorImpulse - oldImpulse; m_impulse.z = MathUtils.max(m_impulse.z, 0.0f); } else if (m_limitState == LimitState.AT_UPPER) { m_impulse.z = MathUtils.min(m_impulse.z, 0.0f);
for (float y = MathUtils.floor(aabb.lowerBound.y / stride) * stride; y < upperBoundY; y += stride) { for (float x = MathUtils.floor(aabb.lowerBound.x / stride) * stride; x < upperBoundX; x += stride) { Vec2 p = tempVec; pair.flags = contact.flags; pair.strength = groupDef.strength; pair.distance = MathUtils.distance(m_positionBuffer.data[a], m_positionBuffer.data[b]); m_pairCount++;
public final void normalize() { float d = MathUtils.TWOPI * MathUtils.floor(a0 / MathUtils.TWOPI); a0 -= d; a -= d; }
public static final int floor(final float x) { if (Settings.FAST_FLOOR) { return fastFloor(x); } else { return (int) StrictMath.floor(x); } }
public static final int ceil(final float x) { if (Settings.FAST_CEIL) { return fastCeil(x); } else { return (int) StrictMath.ceil(x); } }
public static final float atan2(final float y, final float x) { if (Settings.FAST_ATAN2) { return fastAtan2(y, x); } else { return (float) StrictMath.atan2(y, x); } }
public void runFastPowTest(float argRandom) { float a = MathUtils.fastPow(argRandom, MathUtils.randomFloat(-100, 100)); aStore += a; }
public void runFastAtan2Test(float argRandom) { float a = MathUtils.fastAtan2(argRandom, MathUtils.randomFloat(-10000, 10000)); aStore += a; }
public static final float pow(float a, float b) { if (Settings.FAST_POW) { return fastPow(a, b); } else { return (float) StrictMath.pow(a, b); } }
@Override public void step(TestbedSettings settings) { super.step(settings); float hz = settings.getSetting(TestbedSettings.Hz).value; if (hz > 0) { m_time += 1 / hz; } m_joint.setMotorSpeed(0.05f * MathUtils.cos(m_time) * MathUtils.PI); }