demianr
demianr

Reputation: 39

Drawing simple 90degrees triangle in javaFX

we started to learn javafx 3d and using TriangleMesh. i am trying to draw a simple right(90 degree) triangle.(0,0),(0,50),(50,0) whats wrong with my code?please

public class TT extends Application{



public void start(Stage primaryStage){
            TriangleMesh sqMesh=new TriangleMesh();

            sqMesh.getPoints().addAll(
                0.0f,0.0f,0.0f,  //1top
                0.0f,50.0f,0.0f,  //1left
                50.0f,0.0f,0.0f  //1right

            );

            sqMesh.getTexCoords().addAll(
                    0,0
                    );
            sqMesh.getFaces().addAll(
                0,0, 1,0, 2,0

            );

            Group group=new Group();
            MeshView sq=new MeshView();
            sq.setMesh(sqMesh);
            sq.setTranslateX(200);
            sq.setTranslateY(100);
            sq.setTranslateZ(0);
            group.getChildren().add(sq);
            StackPane root=new StackPane();
            Scene scene=new Scene(root,900,600);
            primaryStage.setScene(scene);
            primaryStage.show();
}

public static void main(String[] args) {
        launch(args);
}

}

Upvotes: 0

Views: 820

Answers (1)

Gal A.
Gal A.

Reputation: 322

First of all, you didn't add anything too the root StackPane. This is supposed to solve your problem.

root.getChildren().addAll(group);

However, the window size is very large relatively to the triangle, so I suggest to set the window size automatically to what in the window by creating the scene in the following way (without the size parameters):

Scene scene=new Scene(root);

And because the triangle's color is very similar to the background color, I also suggest you change the triangle's color to something more significant, like that:

sq.setMaterial(new PhongMaterial(Color.BLACK));

Upvotes: 1

Related Questions