简体   繁体   中英

Is it possible to implement perspective transform in JavaFX?

Affine class made as extending Transform class in JavaFX .

This makes an illusion, that there can be some types of transforms, other than affine.

UPDATE

In JavaFX 2.x Transform class contains only getters for specific matrix elements, which includes 12 elements of 3x4 matrix for 3D affine transform. Any class usage can rely only on these elements, so any represented transformation is affine.

This means that 2.x version has bad design, because basic class can represent only affine transforms, while Affine is made it's subclass. This is wrong, since Affine should be made basic class.

In JavaFX 8 Transform class has better design. Additionally to getters, it has indexed access to matrix elements and determination of matrix type . Also it has transform() methods, which do actual transformation.

This means, that usage can rely both on transform() methods, or on matrix element getters.

If it can be guaranteed, that all internal parts of JavaFX rely on transform() methods, then this class can be extended and perspective transformation can be implemented. May be it even can be implemented in release version of JavaFX8 .

The question is: can it be guaranteed, that JavaFX relies only on transform() methods?

Yes, there are non-affine transforms in Mathematics.

No, these non-affine transforms are not supported by the JavaFX 2.2 Transform class, nor are they supported by the JavaFX 8 Transform class. There is no way in the Transform class or any of it's subclasses to set the transform matrix elements required to perform a non-affine transform.

You can apply a PerspectiveTransform to 2D nodes. For a usage sample, see my answer to Stretching Polygon to other Polygon with Java .

To understand the math of non-affine transforms, see Petzold's explanation . You can use similar math for 2d transforms . Yes, I realize Petzold's examples are not JavaFX examples. However, the math still holds and you can apply it to JavaFX through either a PerspectiveTransform or by modifying the points in a TriangleMesh using a custom matrix definition.

Note, a limitation of PerspectiveTransform is picking (mouse selection) doesn't work. Picking will work for a transformed TriangleMesh, but the mesh itself is not a general JavaFX node, just a collection of shaded faces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM