/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.scene.light.PointLight; import javafx.scene.material.PhongMaterial; import javafx.scene.paint.Color; import javafx.scene.shape3d.Sphere; import javafx.stage.Stage; /** * * @author Andrew Glushchenko */ public class LightReinitTestApp extends Application { private static int WIDTH = 500; private static int HEIGHT = 500; private Group root = null; private EarthMoonSunTestGroup testGroup = null; PointLight vl = null; Scene scene; public void openPage() { testGroup = new EarthMoonSunTestGroup(); vl = new PointLight(Color.YELLOW); testGroup.setLighting(new Group(vl)); root = new Group(testGroup); root.setTranslateX(WIDTH / 2); root.setTranslateY(HEIGHT / 2); if (scene == null) { scene = new Scene(root, WIDTH, HEIGHT); PerspectiveCamera camera = new PerspectiveCamera(false); scene.setCamera(camera); initKeys(); } else { scene.setRoot(root); } } private void initKeys() { scene.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent t) { openPage(); } }); } @Override public void start(Stage stage) throws Exception { openPage(); stage.setScene(scene); stage.show(); } static { System.setProperty("prism.dirtyopts", "false"); } public static void main(String[] args) { launch(args); } public class EarthMoonSunTestGroup extends Group { public final static double SCALE = 50; private Sphere earth; private Sphere moon; private PhongMaterial materialEarth; private PhongMaterial materialMoon; public EarthMoonSunTestGroup() { materialEarth = new PhongMaterial(); materialMoon = new PhongMaterial(); materialMoon.setDiffuseColor(Color.LIGHTGRAY); materialMoon.setSpecularColor(Color.rgb(30, 30, 30)); earth = new Sphere(3); moon = new Sphere(1); moon.setTranslateX(5 * SCALE); earth.setMaterial(materialEarth); moon.setMaterial(materialMoon); moon.setScaleX(SCALE); moon.setScaleY(SCALE); moon.setScaleZ(SCALE); earth.setScaleX(SCALE); earth.setScaleY(SCALE); earth.setScaleZ(SCALE); getChildren().addAll(earth, moon); } public void setLighting(Group light) { light.setTranslateX(10 * SCALE); getChildren().add(light); } } }