



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 邮储银行2025呼伦贝尔市小语种岗笔试题及答案
- 建设银行2025佛山市小语种岗笔试题及答案
- 交通银行2025信息科技岗笔试题及答案辽宁地区
- 教师招聘之《小学教师招聘》通关训练试卷详解及参考答案详解【培优b卷】
- 教师招聘之《小学教师招聘》考前冲刺试卷及答案详解(典优)
- 2025内蒙古呼伦贝尔学院招聘35人笔试备考及答案详解(历年真题)
- 2025年教师招聘之《幼儿教师招聘》综合提升测试卷及参考答案详解【基础题】
- 呼伦贝尔农垦集团笔试试题附答案详解(突破训练)
- 2025年公安招警考试面试试题及答案
- 2025年教师招聘之《幼儿教师招聘》每日一练试卷含答案详解(完整版)
- 中国心力衰竭基层诊断与治疗指南(2024年)更新解读(完整版)
- 部编语文三年级上册教案教学设计
- 2023年中小学“学宪法 讲宪法”应知应会知识竞赛题库及答案
- 食为天:2024中国食品饮料行业白皮书
- 慢性肾脏病的用药指导
- 2024版《立体构成》全套课件完整版
- 九年级初中语文阅读理解专项训练及答案带解析
- 海外医疗旅游咨询与服务合同
- 智慧监狱大数据信息化系统建设方案
- 电子商务平台用户服务手册
- 家长进课堂-小学生建筑知识课件002230
评论
0/150
提交评论