@Override public boolean isZero (final float margin) { return len2() < margin; }
@Override public boolean isZero (final float margin) { return len2() < margin; }
@Override public boolean isUnit (final float margin) { return Math.abs(len2() - 1f) < margin; }
@Override public boolean isUnit (final float margin) { return Math.abs(len2() - 1f) < margin; }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
@Override public Vector2 clamp (float min, float max) { final float len2 = len2(); if (len2 == 0f) return this; float max2 = max * max; if (len2 > max2) return scl((float)Math.sqrt(max2 / len2)); float min2 = min * min; if (len2 < min2) return scl((float)Math.sqrt(min2 / len2)); return this; }
@Override public Vector2 clamp (float min, float max) { final float len2 = len2(); if (len2 == 0f) return this; float max2 = max * max; if (len2 > max2) return scl((float)Math.sqrt(max2 / len2)); float min2 = min * min; if (len2 < min2) return scl((float)Math.sqrt(min2 / len2)); return this; }
@Override public boolean isUnit (final float margin) { return Math.abs(len2() - 1f) < margin; }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
float maxLength2 = 80*80; Vector2 v = ball.getLinearVelocity(); if (v.len2() > maxLength2) { v.setLength2(maxLength2); }
@Override public Vector2 clamp (float min, float max) { final float len2 = len2(); if (len2 == 0f) return this; float max2 = max * max; if (len2 > max2) return scl((float)Math.sqrt(max2 / len2)); float min2 = min * min; if (len2 < min2) return scl((float)Math.sqrt(min2 / len2)); return this; }
@Override public Vector2 clamp (float min, float max) { final float len2 = len2(); if (len2 == 0f) return this; float max2 = max * max; if (len2 > max2) return scl((float)Math.sqrt(max2 / len2)); float min2 = min * min; if (len2 < min2) return scl((float)Math.sqrt(min2 / len2)); return this; }
private void updateFactors (CarDescriptor carDescriptor) { // speed/force normalized factors currVelocityLenSquared = carDescriptor.velocity_wc.len2(); currThrottle = carDescriptor.throttle; currSpeedFactor = AMath.fixup(AMath.clamp(currVelocityLenSquared / CarMaxSpeedSquared, 0f, 1f)); // currBrakeFactor = AMath.fixup(AMath.clamp(carDescriptor.brake / CarMaxForce, 0f, 1f)); currForceFactor = AMath.fixup(AMath.clamp(currThrottle / CarMaxForce, 0f, 1f)); }
private void handleFriction () { isOutOfTrack = frictionMean.getMean() < -0.3; if (isOutOfTrack && !notifiedOutOfTrack) { notifiedOutOfTrack = true; GameEvents.playerCar.trigger(this, CarEvent.Type.onOutOfTrack); } else if (!isOutOfTrack && notifiedOutOfTrack) { GameEvents.playerCar.trigger(this, CarEvent.Type.onBackInTrack); notifiedOutOfTrack = false; } // FIXME, move these hard-coded values out of here if (isOutOfTrack && carDesc.velocity_wc.len2() > 10) { carDesc.velocity_wc.scl(GameplaySettings.DampingFriction); } }