public void calculateCarouselCoordinates() { double visibleAngle = Math.PI * 0.75; double visibleCellsCount = getVisibleCellsCount(); double angleOnCarousel = visibleAngle / visibleCellsCount * index + Math.PI * 0.5; double carouselRadius = getSkinnable().getWidth() * getSkinnable().getRadiusRatio(); double halfCellWidth = cell.prefWidth(50) * 0.5; double h = cell.prefHeight(50); double maxCellHeight = getSkinnable().getMaxCellHeight(); double uy = -maxCellHeight * 0.5 + (maxCellHeight - h) * getSkinnable().getCellAlignment(); double ly = uy + h + reflectionSpace; double cos = Math.cos(angleOnCarousel); double sin = -Math.sin(angleOnCarousel); ul = new Point3D( (carouselRadius + halfCellWidth) * cos, uy, (carouselRadius + halfCellWidth) * sin); ur = new Point3D( (carouselRadius - halfCellWidth) * cos, uy, (carouselRadius - halfCellWidth) * sin); ll = new Point3D( (carouselRadius + halfCellWidth) * cos, ly, (carouselRadius + halfCellWidth) * sin); lr = new Point3D( (carouselRadius - halfCellWidth) * cos, ly, (carouselRadius - halfCellWidth) * sin); if (reflection != null) { ulReflection = new Point3D( (carouselRadius + halfCellWidth) * cos, uy + h + reflectionTop, (carouselRadius + halfCellWidth) * sin); urReflection = new Point3D( (carouselRadius - halfCellWidth) * cos, uy + h + reflectionTop, (carouselRadius - halfCellWidth) * sin); } // Equivalent code: // Point3D ul = new Point3D(carouselRadius / scaleFactor + w / 2, -h / 2, 0); // Point3D ur = new Point3D(carouselRadius / scaleFactor - w / 2, -h / 2, 0); // Point3D ll = new Point3D(carouselRadius / scaleFactor + w / 2, h / 2, 0); // Point3D lr = new Point3D(carouselRadius / scaleFactor - w / 2, h / 2, 0); // // Point3D carouselAxis = new Point3D(0, 0, 0); // // ul = rotateY(ul, carouselAxis, angleOnCarousel); // ur = rotateY(ur, carouselAxis, angleOnCarousel); // ll = rotateY(ll, carouselAxis, angleOnCarousel); // lr = rotateY(lr, carouselAxis, angleOnCarousel); }
public PerspectiveTransform build() { double w = cell.prefWidth(50); double h = cell.prefHeight(50); double viewDistance = getWidth() * getSkinnable().getViewDistanceRatio() + getWidth() * getSkinnable().getRadiusRatio(); double fov = getSkinnable().getFieldOfViewRatio() * getSkinnable().getWidth(); double cw = w / 2; double ch = h / 2; Point2D ul2d = project(ul, viewDistance, fov, cw, ch); Point2D ur2d = project(ur, viewDistance, fov, cw, ch); Point2D ll2d = project(ll, viewDistance, fov, cw, ch); Point2D lr2d = project(lr, viewDistance, fov, cw, ch); perspectiveTransform = new PerspectiveTransform( ul2d.getX(), ul2d.getY(), ur2d.getX(), ur2d.getY(), lr2d.getX(), lr2d.getY(), ll2d.getX(), ll2d.getY()); if (reflection != null) { ulReflection2d = project(ulReflection, viewDistance, fov, cw, ch); urReflection2d = project(urReflection, viewDistance, fov, cw, ch); perspectiveTransform.setInput(reflection); } return perspectiveTransform; }
public void addReflection() { double reflectionMaxHeight = 50; double h = cell.prefHeight(50); double verticalAlignment = getSkinnable().getCellAlignment(); double maxCellHeight = getSkinnable().getMaxCellHeight(); double topOfCell = (maxCellHeight - h) * verticalAlignment; double reflectionTop = 2 * (maxCellHeight - topOfCell - h); double reflectionTopOpacity = 0.5 - 0.5 / reflectionMaxHeight * reflectionTop / 2; double reflectionBottomOpacity = 0; double reflectionPortion = (reflectionMaxHeight - reflectionTop / 2) / h; if (reflectionPortion < 0 || reflectionTopOpacity < 0) { reflectionTopOpacity = 0; reflectionPortion = 0; } if (reflectionPortion > 1) { reflectionBottomOpacity = 0.5 - 0.5 / reflectionPortion; reflectionPortion = 1; } double reflectionHeight = h * reflectionPortion; // System.err.println(">>> cell : " + cell.getSkin()); // Insets insets = ((StackPane)cell // .getSkin() // .getNode()) // .getInsets(); // double insetHeight = insets.getBottom(); // reflection = new Blend( // BlendMode.OVERLAY, // new Reflection(reflectionTop - insetHeight - 1, reflectionPortion, // reflectionTopOpacity, reflectionBottomOpacity), // new ColorInput(0.0, reflectionTop + h, w, reflectionHeight, Color.WHITE) // ); if (reflectionPortion > 0) { this.reflection = new Reflection( reflectionTop, reflectionPortion, reflectionTopOpacity, reflectionBottomOpacity); this.reflectionTop = reflectionTop; this.reflectionSpace = reflectionHeight + reflectionTop; } }
@Override public Shape layoutCell(CarouselCell<T> cell, double index) { CellConfigurator configurator = new CellConfigurator(cell, index); if (getSkinnable().getReflectionEnabled()) { configurator.addReflection(); } configurator.calculateCarouselCoordinates(); configurator.applyViewRotation(); PerspectiveTransform perspectiveTransform = configurator.build(); cell.setEffect(perspectiveTransform); return configurator.getReflectionClip(); }