Setting up PerspectiveTransform

The PerspectiveTransform effect is another effect which tries to simulate 3D. It changes the node's dimensions so it appears to be viewed not from the top to the bottom but at an angle.

The API is slightly awkward—you need to set all four corners of the new image by setting eight coordinates by different method calls:

// chapter8/geometry/PerspectiveDemo.java
PerspectiveTransform pt = new PerspectiveTransform();
pt.setUlx(20); // upper-left
pt.setUly(20);
pt.setUrx(100); // upper-right
pt.setUry(20);

pt.setLlx(0); // lower-left
pt.setLly(120);
pt.setLrx(120); // lower-right
pt.setLry(120);

Or use a very long constructor:

 PerspectiveTransform pt = new PerspectiveTransform(20, 20, 100, 20, 0, 120, 120, 120);

I've marked each corner on the following screenshot for convenience:

Don't forget that all effects are purely cosmetic. So all bounds, containment, and mouse hit methods will use original, untransformed coordinates. If you need to transform something more functional—for example, buttons—it is better to opt for the Transformations API we talked about in Chapter 2, Building Blocks – Shapes, Text, and Controls.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.163.13