use of javafx.animation.Transition in project FXyzLib by Birdasaur.
the class SimpleRayTest method animateRayTo.
/**
* Creates and launches a custom Transition animation
*
* @param r The Ray that holds the info
* @param tx to x
* @param ty to y
* @param tz to z
* @param dps distance per step to move ray
* @param time length of animation
*/
private void animateRayTo(final Ray r, final Sphere target, final Duration time) {
final Transition t = new Transition() {
protected Ray ray;
protected Sphere s;
protected double dist;
{
this.ray = r;
this.s = new Sphere(5);
s.setTranslateX((ray.getOrigin()).getX());
s.setTranslateY((ray.getOrigin()).getY());
s.setTranslateZ((ray.getOrigin()).getZ());
s.setMaterial(highlight);
rayLight.getScope().add(s);
this.dist = ray.getOrigin().distance(Point3D.ZERO.add(target.getTranslateX(), target.getTranslateY(), target.getTranslateZ()));
setCycleDuration(time);
this.setInterpolator(Interpolator.LINEAR);
this.setOnFinished(e -> {
if (target.getBoundsInParent().contains(ray.getPosition())) {
target.setMaterial(highlight);
PauseTransition t = new PauseTransition(Duration.millis(750));
t.setOnFinished(pe -> {
reset();
root.getChildren().removeAll(s);
s = null;
});
t.playFromStart();
}
});
root.getChildren().add(s);
}
@Override
protected void interpolate(double frac) {
// frac-> 0.0 - 1.0
// project ray
ray.project(dist * frac);
// set the sphere to ray position
s.setTranslateX(ray.getPosition().getX());
s.setTranslateY(ray.getPosition().getY());
s.setTranslateZ(ray.getPosition().getZ());
}
};
t.playFromStart();
}
use of javafx.animation.Transition in project FXyzLib by Birdasaur.
the class CameraController method setCamera.
public void setCamera(AdvancedCamera camera) {
this.camera = camera;
switch(animPref) {
case TIMELINE:
timeline.getKeyFrames().addAll(new KeyFrame(Duration.millis(15), e -> {
new Timeline(new KeyFrame[] { new KeyFrame(Duration.ONE, ev -> {
update();
}) }).play();
}));
timeline.play();
break;
case TIMER:
timer.start();
break;
case TRANSITION:
transition.play();
break;
case ANIMATION:
break;
}
}
Aggregations