Search in sources :

Example 1 with Transition

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();
}
Also used : Sphere(javafx.scene.shape.Sphere) Transition(javafx.animation.Transition) PauseTransition(javafx.animation.PauseTransition) PauseTransition(javafx.animation.PauseTransition) Ray(org.fxyz.geometry.Ray)

Example 2 with Transition

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;
    }
}
Also used : Scene(javafx.scene.Scene) KeyFrame(javafx.animation.KeyFrame) MouseEvent(javafx.scene.input.MouseEvent) AnimationPreference(org.fxyz.utils.AnimationPreference) Timeline(javafx.animation.Timeline) KeyEvent(javafx.scene.input.KeyEvent) ScrollEvent(javafx.scene.input.ScrollEvent) Transition(javafx.animation.Transition) AdvancedCamera(org.fxyz.cameras.AdvancedCamera) MIDDLE(javafx.scene.input.MouseButton.MIDDLE) SECONDARY(javafx.scene.input.MouseButton.SECONDARY) Transformable(org.fxyz.extras.Transformable) AnimationTimer(javafx.animation.AnimationTimer) Duration(javafx.util.Duration) Point2D(javafx.geometry.Point2D) Animation(javafx.animation.Animation) SubScene(javafx.scene.SubScene) PRIMARY(javafx.scene.input.MouseButton.PRIMARY) Timeline(javafx.animation.Timeline) KeyFrame(javafx.animation.KeyFrame)

Aggregations

Transition (javafx.animation.Transition)2 Animation (javafx.animation.Animation)1 AnimationTimer (javafx.animation.AnimationTimer)1 KeyFrame (javafx.animation.KeyFrame)1 PauseTransition (javafx.animation.PauseTransition)1 Timeline (javafx.animation.Timeline)1 Point2D (javafx.geometry.Point2D)1 Scene (javafx.scene.Scene)1 SubScene (javafx.scene.SubScene)1 KeyEvent (javafx.scene.input.KeyEvent)1 MIDDLE (javafx.scene.input.MouseButton.MIDDLE)1 PRIMARY (javafx.scene.input.MouseButton.PRIMARY)1 SECONDARY (javafx.scene.input.MouseButton.SECONDARY)1 MouseEvent (javafx.scene.input.MouseEvent)1 ScrollEvent (javafx.scene.input.ScrollEvent)1 Sphere (javafx.scene.shape.Sphere)1 Duration (javafx.util.Duration)1 AdvancedCamera (org.fxyz.cameras.AdvancedCamera)1 Transformable (org.fxyz.extras.Transformable)1 Ray (org.fxyz.geometry.Ray)1