/** * Sets this to a random rotation obtained from a completely uniform distribution. */ public Quaternion randomize (Random rand) { // pick angles according to the surface area distribution return fromAngles(MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat()), FloatMath.asin(MathUtil.lerp(-1f, +1f, rand.nextFloat())), MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat())); }
/** * Sets this to a random rotation obtained from a completely uniform distribution. */ public Quaternion randomize (Random rand) { // pick angles according to the surface area distribution return fromAngles(MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat()), FloatMath.asin(MathUtil.lerp(-1f, +1f, rand.nextFloat())), MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat())); }
/** * Linearly interpolates between two angles, taking the shortest path around the circle. * This assumes that both angles are in [-pi, +pi]. */ public static float lerpa (float a1, float a2, float t) { float ma1 = mirrorAngle(a1), ma2 = mirrorAngle(a2); float d = Math.abs(a2 - a1), md = Math.abs(ma1 - ma2); return (d <= md) ? lerp(a1, a2, t) : mirrorAngle(lerp(ma1, ma2, t)); }
/** * Linearly interpolates between two angles, taking the shortest path around the circle. * This assumes that both angles are in [-pi, +pi]. */ public static float lerpa (float a1, float a2, float t) { float ma1 = mirrorAngle(a1), ma2 = mirrorAngle(a2); float d = Math.abs(a2 - a1), md = Math.abs(ma1 - ma2); return (d <= md) ? lerp(a1, a2, t) : mirrorAngle(lerp(ma1, ma2, t)); }
@Override protected void paint (Clock clock, Entities entities) { float alpha = clock.alpha; Point op = _oldPos, p = _pos; for (int ii = 0, ll = entities.size(); ii < ll; ii++) { int eid = entities.get(ii); // interpolate between opos and pos and use that to update the sprite position opos.get(eid, op); pos.get(eid, p); // wrap our interpolated position as we may interpolate off the screen sprite.get(eid).setTranslation(wrapx(MathUtil.lerp(op.x, p.x, alpha)), wrapy(MathUtil.lerp(op.y, p.y, alpha))); } }