java fx 过渡,Java FX示例

这篇博客介绍了如何使用JavaFX创建3D视图,包括Box、Sphere和Cylinder的基本实例,以及如何设置PhongMaterial、灯光和相机。作者详细展示了如何控制形状的位置、颜色和光照,以实现逼真的3D场景。
摘要由CSDN通过智能技术生成

下面是一个简单的例子:

Java代码

1. import javafx.application.Application; 2. import javafx.scene.*; 3. import javafx.scene.paint.Color;4. import javafx.scene.paint.PhongMaterial; 5. import javafx.scene.shape.*; 6. import javafx.stage.Stage;7.8. public class Shapes3DViewer extends Application {9. @Override public void start(Stage stage) { 10. PhongMaterial material = new PhongMaterial();11. material.setDiffuseColor(Color.LIGHTGRAY);12. material.setSpecularColor(Color.rgb(30, 30, 30));13. 14. Shape3D[] meshView = new Shape3D[] { 15. new Box(200, 200, 200),16. new Sphere(100),17. new Cylinder(100, 200), 18. };19. 20. for (int i=0; i!=3; ++i) {21. meshView[i].setMaterial(material); 22. meshView[i].setTranslateX((i + 1) *           220);23. meshView[i].setTranslateY(500); 24. meshView[i].setTranslateZ(20); 25. meshView[i].setDrawMode(DrawMode.FILL); 26. meshView[i].setCullFace(CullFace.BACK); 27. }; 28. 29. PointLight pointLight = new PointLight(Color.ANTIQUEWHITE); 30. pointLight.setTranslateX(800); 31. pointLight.setTranslateY(-100);32. pointLight.setTranslateZ(-1000); 33.34. Group root = new Group(meshView); 35. root.getChildren().add(pointLight); 36. 37. Scene scene = new Scene(root, 800, 800, true);38. scene.setFill(Color.rgb(10, 10, 40)); 39. scene.setCamera(new PerspectiveCamera(false));40. stage.setScene(scene); 41. stage.show(); 42. } 43. 44. public static void main(String[] args) { 45. launch(args); 46. } 47. }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值