Java Reference
In-Depth Information
Group group = new Group(box, camera);
scene = new Scene(group, 640, 480);
scene.setCamera(camera);
}
public void animate() {
Timeline timeline = new Timeline(
new KeyFrame(Duration.seconds(0),
new KeyValue(translateZ.zProperty(), -20),
new KeyValue(rotateX.angleProperty(), 90),
new KeyValue(rotateY.angleProperty(), 90),
new KeyValue(rotateZ.angleProperty(), 90)),
new KeyFrame(Duration.seconds(5),
new KeyValue(translateZ.zProperty(), -80),
new KeyValue(rotateX.angleProperty(), -90),
new KeyValue(rotateY.angleProperty(), -90),
new KeyValue(rotateZ.angleProperty(), -90))
);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
}
}
Notice that the camera needs to be added as a Node to the scene so that we can apply transforms to it. It also
needs to be set as the camera to be used by the scene for rendering the 3D model.
When the program in Listing 10-5 is run, the PerspectiveCamera Example window in Figure 10-6 is displayed. We
can see the box being viewed from different angles and at different distances from the eye. The box becomes smaller
as the camera moves away from it.
Figure 10-6. The PerspectiveCameraExample program
 
Search WWH ::




Custom Search