Java Reference
In-Depth Information
public static void main(String[] args) {
launch(args);
}
private static class Model {
private ObjectProperty<Material> material = new SimpleObjectProperty<>(
this, "material", new PhongMaterial());
public Material getMaterial() {
return material.get();
}
public ObjectProperty<Material> materialProperty() {
return material;
}
public void setMaterial(Material material) {
this.material.set(material);
}
}
private static class View {
public static final int SPHERE_RADIUS = 200;
public Scene scene;
public Sphere sphere;
private View(Model model) {
sphere = new Sphere(SPHERE_RADIUS);
sphere.materialProperty().bind(model.materialProperty());
EventHandler<javafx.scene.input.MouseEvent> handler = event -> {
PickResult pickResult = event.getPickResult();
Point3D point = pickResult.getIntersectedPoint();
model.setMaterial(new PhongMaterial(makeColorOutOfPoint3D(point)));
};
sphere.setOnMouseClicked(handler);
sphere.setOnMouseDragged(handler);
Group group = new Group(sphere);
group.setTranslateX(320);
group.setTranslateY(240);
scene = new Scene(group, 640, 480);
}
private Color makeColorOutOfPoint3D(Point3D point) {
double x = point.getX();
double y = point.getY();
double z = point.getZ();
return Color.color(normalize(x), normalize(y), normalize(z));
}
Search WWH ::




Custom Search