public void prepare() { maxX = calcMaxX(curve); for (Point p : curve) { p.x = p.x / maxX; } }
public float getValue(final float x) { Point p0 = curve.get(0); for (int i = 1; i < curve.size(); i++) { Point p1 = curve.get(i); if (isInInterval(x, p0, p1)) { return calcValue(x, p0, p1); } p0 = p1; } if (x > curve.get(curve.size() - 1).x) { return curve.get(curve.size() - 1).y; } else if (x < curve.get(0).x) { return curve.get(0).y; } else { return 0.0f; } }
@Nullable public LinearInterpolator toLinearInterpolator() { if (values.isEmpty()) { return null; } if (!containsTimeValues()) { return null; } LinearInterpolator interpolator = new LinearInterpolator(); for (Attributes p : values) { interpolator.addPoint(p.getAsFloat("time"), p.getAsFloat("value")); } return interpolator; }
@Override public void execute( @Nonnull final Element element, final float normalizedTime, @Nullable final Falloff falloff, @Nonnull final NiftyRenderEngine r) { if (interpolator != null) { r.setColorAlpha(interpolator.getValue(normalizedTime)); } else { Alpha a = start.linear(end, normalizedTime); r.setColorAlpha(a.getAlpha()); } }
@Nullable public LinearInterpolator getInterpolator() { if (effectValues == null) { return null; } LinearInterpolator interpolator = getEffectPropertiesValueLazy().toLinearInterpolator(); if (interpolator == null) { return null; } interpolator.prepare(); return interpolator; }
void applyEffectValues(@Nonnull final EffectProperties effectProperties) { if (!effectValues.isEmpty()) { for (EffectValueType effectValueType : effectValues) { effectProperties.addEffectValue(effectValueType.getAttributes()); } if (effectProperties.isTimeInterpolator()) { LinearInterpolator interpolator = effectProperties.getInterpolator(); if (interpolator != null) { effectProperties.setProperty("length", String.valueOf((long) interpolator.getMaxX())); } } } }
@Override public void execute( @Nonnull final Element element, final float normalizedTime, @Nullable final Falloff falloff, @Nonnull final NiftyRenderEngine r) { float scale; if (falloff == null) { if (interpolator != null) { scale = interpolator.getValue(normalizedTime); } else { scale = startSize + normalizedTime * (endSize - startSize); } } else { scale = 1.0f + falloff.getFalloffValue() * imageSize.getValue(1.0f); } r.setImageScale(scale); }