How to display live coordinates of a PerspectiveCamera in JavaFX relative to an object

Here’s the relevant code I have:

public class OpenViewController implements Initializable {

@FXML
private SubScene mySubScene;

@FXML
private VBox mainVBox;

@FXML
private Text coordinateDisplay;

private final Translate translate = new Translate(0, 0, 0);
private final Translate translateZ = new Translate(0, 0, -1070);
private final Rotate rotateX = new Rotate(-120, 0, 0, 0, Rotate.X_AXIS);
private final Rotate rotateY = new Rotate(180, 0, 0, 0, Rotate.Y_AXIS);
private final Translate translateY = new Translate(0, 0, 0);

@Override
public void initialize(URL location, ResourceBundle resources) {
    setupRiggedHands();
}

private void setupRiggedHands() {
    // Some irrelevant code...
    
    PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
    perspectiveCamera.setTranslateZ(-400);
    perspectiveCamera.setNearClip(0.001);
    perspectiveCamera.setFarClip(10000);
    mySubScene.setCamera(perspectiveCamera);

    mySubScene.widthProperty().bind(mainVBox.widthProperty());
    mySubScene.heightProperty().bind(mainVBox.heightProperty().subtract(50));

    Translate centerTranslate = new Translate();
    centerTranslate.xProperty().bind(mySubScene.widthProperty().divide(2));
    centerTranslate.yProperty().bind(mySubScene.heightProperty().divide(2));

    mySubScene.getRoot().getTransforms().addAll(centerTranslate, translate, translateZ, rotateX, rotateY, translateY);
    mySubScene.setPickOnBounds(true);

    new DragSupport(mySubScene, null, MouseButton.SECONDARY, Orientation.VERTICAL, translateZ.zProperty(), -3);
    new DragSupport(mySubScene, null, Orientation.HORIZONTAL, rotateY.angleProperty());
    new DragSupport(mySubScene, null, Orientation.VERTICAL, rotateX.angleProperty());
    new DragSupport(mySubScene, null, MouseButton.MIDDLE, Orientation.HORIZONTAL, translate.xProperty());
    new DragSupport(mySubScene, null, MouseButton.MIDDLE, Orientation.VERTICAL, translate.yProperty());
    
    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            // Get the bounds of the SubScene
            Bounds bounds = mySubScene.getBoundsInParent();

            double distanceX = Math.abs(translate.getX());
            double distanceY = Math.abs(translateY.getY());
            double distanceZ = Math.abs(translateZ.getZ() - perspectiveCamera.getTranslateZ());

            // Update the coordinate display with the calculated distances
            coordinateDisplay.setText(String.format("X: %.2f, Y: %.2f, Z: %.2f", distanceX, distanceY, distanceZ));
        }
     };

    // Start the timer
    timer.start();
    }
}

I am developing a JavaFX application that displays two sets of hands, where the user can change the perspective by dragging the mouse and zoom in or out by right-clicking and dragging. However, I’m encountering an issue when trying to display the live coordinates (X, Y, Z) of the center of the hands relative to the PerspectiveCamera.

Here are the problems I’m facing:

  1. The X and Y coordinates are always zero and do not update as I move the scene. Only the Z coordinate works as expected.
  2. When I resize the window, the distance from the camera to the object (hands) changes unexpectedly, but the Z coordinate remains constant.
  3. I want to display the coordinates of the object’s center (i.e., the center between the two hands) in a way that adjusts correctly when resizing the scene or changing the camera’s perspective.

Here is an example of what it looks like in normal view

And here is what its like in full screen

As you can see the coordinate stays the same, and I have to zoom in to a completely different z coord to get a good view on full screen.

Also here is my DragSupport constructer I am not sure if the code here is relevant

public DragSupport(SubScene target, final KeyCode modifier, final MouseButton mouseButton, final Orientation orientation, final Property<Number> property, final double factor) {
// Code used for handling movement
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật