Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182857
  • 博文数量: 92
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1413
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-04 21:12
文章分类
文章存档

2013年(92)

我的朋友

分类: 信息化

2013-04-19 05:35:34

程序完结思路: 在javafx中Node方针有一个effect特色,可以用于完结各种特效。PerspectiveTransform特效可以使Node方针完结透视转换。因此我们可以通过核算透视转换中每个点的方位来完结3D翻转特效。 在线工作 源码下载 完结进程: 1、定义FlipView方针。包含以下特色:         //正面视图
	public Node frontNode;
	//不好视图  
	public Node backNode;
	//能否翻转
	boolean flipped = false;
	//翻转角度
	DoubleProperty time = new SimpleDoubleProperty(Math.PI / 2);
	//正面翻转特效
	PerspectiveTransform frontEffect = new PerspectiveTransform();
	//不好翻转特效
	PerspectiveTransform backEffect = new PerspectiveTransform();
 ?create方法回来需要闪现的内容: private void create() {
		time.addListener(new ChangeListener() {
			@Override
			public void changed(ObservableValue arg0,
					Number arg1, Number arg2) {
				setPT(frontEffect, time.get());
				setPT(backEffect, time.get());
			}
		});
		anim.getKeyFrames().addAll(frame1, frame2);
		backNode.visibleProperty().bind(
				Bindings.when(time.lessThan(0)).then(true).otherwise(false));

		frontNode.visibleProperty().bind(
				Bindings.when(time.lessThan(0)).then(false).otherwise(true));
		setPT(frontEffect, time.get());
		setPT(backEffect, time.get());
		frontNode.setEffect(frontEffect);
		backNode.setEffect(backEffect);
		getChildren().addAll(backNode, frontNode);
	}
 ?以上代码需要注重的是: 跟着time值的改动frontEffect和backEffect的值也会跟着转换。 2、PerspectiveTransform特效的完结使用了Math.sin()和Math.cos()方法仿照3D角度转换。 具体完结如下: private void setPT(PerspectiveTransform pt, double t) {
		double width = 200;
		double height = 200;
		double radius = width / 2;
		double back = height / 10;
		pt.setUlx(radius - Math.sin(t) * radius);
		pt.setUly(0 - Math.cos(t) * back);
		pt.setUrx(radius   Math.sin(t) * radius);
		pt.setUry(0   Math.cos(t) * back);
		pt.setLrx(radius   Math.sin(t) * radius);
		pt.setLry(height - Math.cos(t) * back);
		pt.setLlx(radius - Math.sin(t) * radius);
		pt.setLly(height   Math.cos(t) * back);
	}
 ?3、角度转换在1秒的时间内从3.14/2转换到-3.14/2。 KeyFrame frame1 = new KeyFrame(Duration.ZERO, new KeyValue(time,
			Math.PI / 2, Interpolator.LINEAR));
	KeyFrame frame2 = new KeyFrame(Duration.seconds(1),
			new EventHandler() {
				@Override
				public void handle(ActionEvent event) {
					flipped = !flipped;
				}
			}, new KeyValue(time, -Math.PI / 2, Interpolator.LINEAR));
 ?4、FlipView方针的创建:通过结构函数可以很便当的创建FlipView方针. ImageView image1 = new ImageView(new Image(getClass()
				.getResourceAsStream("lion1.png")));
ImageView image2 = new ImageView(new Image(getClass()
				.getResourceAsStream("lion2.png")));
FlipView flip = new FlipView(image1, image2);
 ?5、效果图: 在线工作 源码下载 ?  
阅读(790) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~