2016-12-15 71 views
2

我想模擬盒子和矩形的透視失真。我的目標是扭曲盒子和圖像,就好像相機正在傾斜和移動一樣。但我並不真正遵循如何使用PerspectiveCamera。JavaFx PerspectiveCamera - fixedEyeAtCameraZero標誌 - 當爲true時,所有對象消失

當我將fixedEyeAtCameraZero設置爲false時,我可以在屏幕上看到框和圖像。但改變窗口大小會導致奇怪的正交透視變化,這是不現實的。

另一方面,當我設置fixedEyeAtCameraZerotrue,我看到的只是一個空白窗口。

假: false

真: true

下面的代碼,用違規旗行51

package sample; 
import javafx.application.Application; 
import javafx.geometry.Point3D; 
import javafx.scene.Group; 
import javafx.scene.PerspectiveCamera; 
import javafx.scene.Scene; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.scene.shape.Box; 
import javafx.scene.shape.DrawMode; 
import javafx.scene.shape.Rectangle; 
import javafx.scene.transform.Rotate; 
import javafx.stage.Stage; 

public class Example_Box extends Application { 
    @Override 
    public void start(Stage stage) { 

     //Drawing a Box 
     Box box2 = new Box(); 

     //Setting the properties of the Box 
     box2.setWidth(100.0); 
     box2.setHeight(100.0); 
     box2.setDepth(100.0); 

     //Setting the position of the box 
     box2.setTranslateX(30); //450 
     box2.setTranslateY(90);//150 
     box2.setTranslateZ(300); 

     //Setting the drawing mode of the box 
     box2.setDrawMode(DrawMode.LINE); 

     //Drawing an Image 
     Image image = new Image("Lenna.png"); 
     ImageView imageView = new ImageView(image); 
     imageView.setTranslateX(200); 
     imageView.setTranslateY(150); 
     imageView.setTranslateZ(200); 

     //imageView.getTransforms().add(new Rotate(30, 50, 30)); 

     //Creating a Group object 
     Group root = new Group(box2, imageView); 

     //Creating a scene object 
     Scene scene = new Scene(root, 600, 300); 

     //Setting camera 
     PerspectiveCamera camera = new PerspectiveCamera(true); 
     camera.setTranslateX(30); 
     camera.setTranslateY(0); 
     camera.setTranslateZ(-100); 

     camera.setRotationAxis(new Point3D(1,0,0)); 
     scene.setCamera(camera); 

     //Setting title to the Stage 
     stage.setTitle("Drawing a Box"); 

     //Adding scene to the stage 
     stage.setScene(scene); 

     //Displaying the contents of the stage 
     stage.show(); 
    } 
    public static void main(String args[]){ 
     launch(args); 
    } 
} 

回答

相關問題