Applying Transformations in JavaFX
1 Translation
The translation transformation shifts a node from one place to another along one of the axes relative to its initial position. The initial position of the xylophone bar is defined by x, y, and z coordinates. In Example 1-1, the initial position values are specified by the xStart
, yPos
, and zPos
variables. Some other variables are added to simplify the calculations when applying different transformations. Each bar of the xylophone is based on one of the base bars. The example then translates the base bars with different shifts along the three axes to correctly locate them in space.
Example 1-1 shows a code snippet from the sample application with the translation transformation.
Example 1-1 Translation
Group rectangleGroup = new Group(); rectangleGroup.setDepthTest(DepthTest.ENABLE); double xStart = 260.0; double xOffset = 30.0; double yPos = 300.0; double zPos = 0.0; double barWidth = 22.0; double barDepth = 7.0; // Base1 Cube base1Cube = new Cube(1.0, new Color(0.2, 0.12, 0.1, 1.0), 1.0); base1Cube.setTranslateX(xStart + 135); base1Cube.setTranslateZ(yPos+20.0); base1Cube.setTranslateY(11.0);