JavaFX 3D Graphics: Mouse click position on 3D obj

2020-03-31 06:19发布

问题:

I just played around with the Oracle JavaFX Sample 3D Graphics app I am wondering if it is possible to calculate the current mouse position relative to the 3d platform. I would like some info e.g. if the mouse hovers a 3d object. Is that possible in any way (Maybe with the given camera translations etc.)?

回答1:

You can use the PickResult class from any MouseEvent, this is just the basic usage ..

...{
    shape3D.setOnMouseEntered(e->{
        PickResult pr = e.getPickResult();
        System.out.println(pr.getIntersectedPoint());
    });
}