javafx方块系统_第1页
javafx方块系统_第2页
javafx方块系统_第3页
javafx方块系统_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/* * Copyright (c) 2008, 2012 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. */import javafx.scene.transform.Rotate;import javafx.scene.PerspectiveCamera;import javafx.scene.transform.Translate;import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.stage.Stage;import javafx.animation.Animation;import javafx.animation.KeyFrame;import javafx.animation.KeyValue;import javafx.animation.Timeline;import javafx.scene.Node;import javafx.scene.paint.Color;import javafx.scene.shape.RectangleBuilder;import javafx.util.Duration;/* * A sample that demonstrates an animated rotation of 3D cubes. When the * application runs in standAlone mode, the scene must be constructed with * the depthBuffer argument set to true, and the root node must have depthTest * set to true. * * see javafx.scene.transform.Rotate * see javafx.scene.paint.Color * see javafx.scene.shape.RectangleBuilder */public class CubeSample extends Application private Timeline animation; private void init(Stage primaryStage) Group root = new Group(); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 400,150,true); primaryStage.getScene().setCamera(new PerspectiveCamera(); root.getTransforms().addAll( new Translate(400 / 2, 150 / 2), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent(); public Node create3dContent() Cube c1 = new Cube(50,Color.RED,1); c1.rx.setAngle(45); c1.ry.setAngle(45); Cube c2 = new Cube(50,Color.GREEN,1); c2.setTranslateX(100); c2.rx.setAngle(45); c2.ry.setAngle(45); Cube c3 = new Cube(50,Color.ORANGE,1); c3.setTranslateX(-100); c3.rx.setAngle(45); c3.ry.setAngle(45); animation = new Timeline(); animation.getKeyFrames().addAll( new KeyFrame(Duration.ZERO, new KeyValue(c1.ry.angleProperty(), 0d), new KeyValue(c2.rx.angleProperty(), 0d), new KeyValue(c3.rz.angleProperty(), 0d) ), new KeyFrame(Duration.seconds(1), new KeyValue(c1.ry.angleProperty(), 360d), new KeyValue(c2.rx.angleProperty(), 360d), new KeyValue(c3.rz.angleProperty(), 360d) ); animation.setCycleCount(Animation.INDEFINITE); return new Group(c1,c2,c3); public void play() animation.play(); Override public void stop() animation.pause(); public class Cube extends Group final Rotate rx = new Rotate(0,Rotate.X_AXIS); final Rotate ry = new Rotate(0,Rotate.Y_AXIS); final Rotate rz = new Rotate(0,Rotate.Z_AXIS); public Cube(double size, Color color, double shade) getTransforms().addAll(rz, ry, rx); getChildren().addAll( RectangleBuilder.create() / back face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.5*shade), 1.0) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(0.5*size) .build(), RectangleBuilder.create() / bottom face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.4*shade), 1.0) .translateX(-0.5*size) .translateY(0) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() / right face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0) .translateX(-1*size) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() / left face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.2*shade), 1.0) .translateX(0) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() / top face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.1*shade), 1.0) .translateX(-0.5*size) .translateY(-1*size) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() / top face .width(size).height(size) .fill(color) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(-0.5*size) .build() ); public double getSampleWidth() return 400; public dou

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论