How far is the eye of the plan z = 0, when you use the PerspectiveCamera?

I use the PerspectiveCamera in a 3D scene. I need to calculate the angle between the position of the eye and an object when the object has been translated. Simple trigonometry would indicate that I need to know the distance from the position of the eye of the plan z = 0, in addition to the fieldOfView parameter.

Does anyone know this distance (unpublished)?
If not, how I can work on the corner?
Thank you.
d = -1 * 1 / tan(fov / 2) * sh / 2
c = 0.8 * d

Where d represents the coordinate z from the eye, fov is the field of vision of the camera from the point of view and sh is up to the scene.
Look at a volume is a right truncated pyramid, where anything with a coordinate z< 0.8="" *="" d="" will="" be="" truncated="" to="" give="" the="" clip="" distance="">

Distance of the eye is not published, but can be determined in mathematics. Point of truncation of the pyramid for the cutoff distance is not documented, but can be determined by trial and error, taking into account two different fovs for verification.

For example, for the field of view of 45 degrees and a height of stage of 200.

d = -1 * 1 / tan(45 degrees /2) * 200 / 2 = -241.42
c = 0.8 * -241.42 = -193.13

So anything with a translateZ< -193.13="" will="" not="" be="" seen.="" you="" can="" try="" this="" out="" by="" setting="" translatez="" to="" -194="" in="" the="" following="" program="" and="" the="" rectangle="" will="" no="" longer="" be="">

If you set the field of view to 30s, the same formula will give a value of d =-373.20 and c = 298.5, so anything with a translateZ<= -299="" will="" be="">

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 PerspectiveFov extends Application {
  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage stage) throws Exception {
    Rectangle rectangle = new Rectangle(95, 95, 10, 10); rectangle.setFill(Color.FORESTGREEN);

    rectangle.setTranslateZ(-193);

    // define the scene.
    final Scene scene = new Scene(new Group(rectangle), 200, 200, true);
    final PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
    System.out.println(perspectiveCamera.getFieldOfView());
//    perspectiveCamera.setFieldOfView(30); // max translateZ => 298
    perspectiveCamera.setFieldOfView(45); // max translateZ => 193
    scene.setCamera(perspectiveCamera);

    stage.setScene(scene);
    stage.show();
  }
}

Tags: Java

Similar Questions

Maybe you are looking for