/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package colorcube; /** * * @author ckyang */ import javafx.application.Application; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class NearAndFarClipTest extends Application { private Scene createClipPlanes(Stage stage) { stage.setTitle("Near and Far Clip Test"); Rectangle insideRect = new Rectangle(50, 50, Color.GREEN); insideRect.setLayoutX(225); insideRect.setLayoutY(225); insideRect.setTranslateZ(-747.7114); Rectangle insideNearClip = new Rectangle(20, 20, Color.BLUE); insideNearClip.setLayoutX(240); insideNearClip.setLayoutY(240); insideNearClip.setTranslateZ(-839.7114); Rectangle outsideNearClip = new Rectangle(20, 20, Color.YELLOW); outsideNearClip.setLayoutX(240); outsideNearClip.setLayoutY(240); outsideNearClip.setTranslateZ(-839.7115); Rectangle insideFarClip = new Rectangle(3000, 3000, Color.RED); insideFarClip.setTranslateX(-1250); insideFarClip.setTranslateY(-1250); insideFarClip.setTranslateZ(8397.114); Rectangle outsideFarClip = new Rectangle(4000, 4000, Color.CYAN); outsideFarClip.setTranslateX(-1750); outsideFarClip.setTranslateY(-1750); outsideFarClip.setTranslateZ(8398.115); Group root = new Group(); // Render in painter order (far to near) root.getChildren().addAll(outsideFarClip, insideFarClip, insideRect, insideNearClip, outsideNearClip); // Intentional set depth buffer to false to reduce test complexity Scene scene = new Scene(root, 500, 500, false); PerspectiveCamera camera = new PerspectiveCamera(); camera.setFieldOfView(30); camera.setNearClip(0.1); camera.setFarClip(10); scene.setCamera(camera); return scene; } @Override public void start(Stage stage) { Scene scene = createClipPlanes(stage); scene.setFill(Color.GRAY); stage.setScene(scene); stage.sizeToScene(); stage.setResizable(false); stage.show(); System.out.println("You should expect to see 3 overlapping squares in" + " the order of Blue is on top of Green and Green is on top Red.");; } public static void main(String[] args) { Application.launch(args); } }