@Test public void testSetCamera() { Camera camera = new PerspectiveCamera(); Scene scene = new Scene(new Group(camera)); scene.setCamera(camera); assertEquals(scene.getCamera(), camera); scene.setCamera(camera); }
/** * The renderImage method renders the entire scene. * * @param scene The scene to be rendered */ public void renderImage(Scene scene) { // Get the output image Image image = scene.getImage(); Camera cam = scene.getCamera(); // Set the camera aspect ratio to match output image int width = image.getWidth(); int height = image.getHeight(); // Timing counters long startTime = System.currentTimeMillis(); // Do some basic setup Ray ray = new Ray(); Colord rayColor = new Colord(); int total = height * width; int counter = 0; int lastShownPercent = 0; double exposure = scene.getExposure(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { rayColor.setZero(); cam.getRay(ray, (x + 0.5) / width, (y + 0.5) / height); shadeRay(rayColor, scene, ray); rayColor.mul(exposure); image.setPixelColor(rayColor, x, y); counter++; if ((int) (100.0 * counter / total) != lastShownPercent) { lastShownPercent = (int) (100.0 * counter / total); System.out.println(lastShownPercent + "%"); } } } // Output time long totalTime = (System.currentTimeMillis() - startTime); System.out.println("Done. Total rendering time: " + (totalTime / 1000.0) + " seconds"); }
@Test public void testCameraUpdatesPG() { Scene scene = new Scene(new Group(), 300, 200); Camera cam = new ParallelCamera(); stage.setScene(scene); scene.setCamera(cam); Toolkit.getToolkit().firePulse(); // verify it has correct owner cam.setNearClip(20); Toolkit.getToolkit().firePulse(); NGCamera ngCamera = ((StubScene) scene.impl_getPeer()).getCamera(); assertEquals(20, ngCamera.getNearClip(), 0.00001); scene.setCamera(null); Toolkit.getToolkit().firePulse(); // verify owner was removed cam.setNearClip(30); Toolkit.getToolkit().firePulse(); assertEquals(20, ngCamera.getNearClip(), 0.00001); scene.setCamera(cam); Toolkit.getToolkit().firePulse(); // verify it has correct owner cam.setNearClip(40); Toolkit.getToolkit().firePulse(); assertEquals(40, ngCamera.getNearClip(), 0.00001); NGCamera oldCam = ngCamera; scene.setCamera(new ParallelCamera()); Toolkit.getToolkit().firePulse(); // verify owner was removed cam.setNearClip(50); Toolkit.getToolkit().firePulse(); ngCamera = scene.getCamera().impl_getPeer(); assertEquals(40, oldCam.getNearClip(), 0.00001); assertEquals(0.1, ngCamera.getNearClip(), 0.00001); }
@Test public void testSetNullCamera() { Scene scene = new Scene(new Group()); scene.setCamera(null); assertNull(scene.getCamera()); }
@Test public void testGetDefaultCamera() { Scene scene = new Scene(new Group()); assertNull(scene.getCamera()); }