Java Reference
In-Depth Information
scene.setOnMouseDragged((MouseEvent event) -> {
angleX.set(anchorAngleX - (anchorY - event.getSceneY()));
angleY.set(anchorAngleY + anchorX - event.getSceneX());
});
PointLight pointLight = new PointLight(Color.WHITE);
pointLight.setTranslateX(300);
pointLight.setTranslateY(200);
pointLight.setTranslateZ(-2000);
root.getChildren().add(pointLight);
scene.setCamera(camera);
stage.setScene(scene);
// SubScene code
Label zLabel = new Label("Z");
zSlider = new Slider(-200, 3000, -200);
meshCheckBox = new CheckBox("Wireframe");
HBox subSceneGroup = new HBox(70, new HBox(10, zLabel, zSlider),
meshCheckBox, facePickedLabel);
subSceneGroup.setPadding(new Insets(10, 10, 10, 10));
SubScene subScene = new SubScene(subSceneGroup, 640, 50);
root.getChildren().add(subScene);
// Setup binding
zSlider.valueProperty().bindBidirectional(zPos);
parent.translateZProperty().bind(zPos);
meshCheckBox.selectedProperty().bindBidirectional(showWireframe);
cube.drawModeProperty().bind(new When(showWireframe)
.then(DrawMode.LINE).otherwise(DrawMode.FILL));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The user can control the rotation about the x and y axis by dragging the mouse on the screen. When the user
clicks on the scene, the face number of the intersected face is displayed in the control panel. Notice that if you click
on the part of the screen outside of the MeshView cube, the face number displayed will be -1, which is the numerical
value of the FACE_UNDEFINED constant in PickResult . Otherwise it will show the face number of one of the 12 faces.
The cube has six sides, each of which is represented by two triangles in the TriangleMesh .
When the program in Listing 10-11 is run, the MeshCubePickDemo window in Figure 10-14 is displayed. You can
click on or drag the mouse over the cube to see the faces of the cube.
Search WWH ::




Custom Search