+-

我想用 JavaFX 8(3D)绘制3D图形.我已经知道3D绘图球的一些基础知识,首先着色球体并添加阴影,然后是球体的一些光和初始化.我的问题是我想通过使用圆柱体来加入球体,但是如果在两个球体之间存在例如2个圆柱体,则它必须是弧形或弯曲的圆柱体(我不知道这是否可能).我已经尝试过,但没有任何东西出现,即使出现了一些东西,它只是一个圆柱体(不像一条线条那么小).
另一个问题,我想知道旋转如何在这种情况下有所帮助.
最后一个问题,是否可以制作滚动条或仅使用Zoom事件?谢谢.
图片来自:Here
这是我的代码:
import java.util.ArrayList;
import java.util.Random;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class Graphe3D extends Application {
Group root;
PhongMaterial material;
ArrayList<Sphere> sphere;
@Override
public void start(Stage primaryStage) {
sphere=new ArrayList<>();
root=new Group();
material= new PhongMaterial();
for(int i=0;i<3;i++){
sphere.add(new Sphere(50));
//Sphere Color
material.setDiffuseColor(Color.RED);
//Shadow Color
material.setSpecularColor(Color.rgb(30, 30, 30));
//Init Sphere
sphere.get(i).setMaterial(material);
sphere.get(i).setTranslateX(new Random().nextInt(600));//set location X,Y and Z
sphere.get(i).setTranslateY(new Random().nextInt(600));
sphere.get(i).setTranslateZ(50); // ?
sphere.get(i).setDrawMode(DrawMode.FILL);
sphere.get(i).setCullFace(CullFace.BACK);// ?
//Create Light
PointLight pointLight = new PointLight(Color.ANTIQUEWHITE);
pointLight.setTranslateX(800);
pointLight.setTranslateY(-100);
pointLight.setTranslateZ(-1000);
root.getChildren().add(pointLight); //ajout de lumiere
root.getChildren().add(sphere.get(i)); //ajout des spheres au scene(root)
}
//Display
Scene scene = new Scene(root);
scene.setFill(Color.rgb(10, 10, 40));
scene.setCamera(new PerspectiveCamera(false));
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
最佳答案
molecule sample application from Oracle完成了你要求的大部分内容.阅读链接教程并研究为示例应用程序提供的源代码.
关于你的几个问题.
if there is for example 2 cylinder between two sphere it must an arc or curved cylinder
这个有可能.您必须生成自定义TriangleMesh而不是使用预先构建的Cylinder类.基本上,您需要创建一个椭圆Torus并仅在两个节点之间显示Torus的圆弧部分.我不会在StackOverflow答案的上下文中提供有关如何执行此操作的详细说明.
I want to know how the rotation can help in such situation and last question is it possible to make a scrollbar or just using event of Zoom ?
研究之前链接的Molecule示例代码,因为它具有旋转和缩放功能.
点击查看更多相关文章
转载注明原文:使用JavaFX8 3D加入带有圆柱体的两个球体 - 乐贴网