JavaFX 3D Tutorial #5 – More fine mouse control – Zoom in and Zoom out

In this chapter, we will implement the mouse zoom control. Currently we have complete rotation freedom on the mouse. With Zoom in/out effect, we can control the Z-axis.

This zoom control will be based on mouse scrolling. JavaFX provides option to listen for mouse scroll event. We will make use of that.

//Attach a scroll listener
stage.addEventHandler(ScrollEvent.SCROLL, event -> {
        //Get how much scroll was done in Y axis.
	double delta = event.getDeltaY();
        //Add it to the Z-axis location.
	group.translateZProperty().set(group.getTranslateZ() + delta);
});

ScrollEvent.SCROLL allows to track the scrolling. JavaFX provides support for tracking horizontal scrolling (which can be obtained using event.getDeltaX()) as well as vertical scrolling (which can be obtained using event.getDeltaY()). Currently we are interested in vertical scrolling only.

When we scroll upward, the value will be positive. Then the Z axis value will increase and object will go away. When the scroll is downward, Z value will be decreased and the object will come closer.

Visit JavaFX 3D Course Index Page

Muhammed Afsal Villan

Muhammed Afsal Villan is an experienced full-stack developer, specialized in desktop and mobile application development. He also regularly publishes quality tutorials on his YouTube channel named 'Genuine Coder'. He likes to contribute to open-source projects and is always enthusiastic about new technologies.

More From Author

JavaFX Communication Between Controllers

JavaFX 3D Tutorial #6 – Textures with Diffuse Map

52 thoughts on “JavaFX 3D Tutorial #5 – More fine mouse control – Zoom in and Zoom out

  1. Pingback: make publicity
  2. Pingback: THEWIN888
  3. Pingback: Free Undress AI
  4. Pingback: pork spareribs
  5. Pingback: DEHN
  6. Pingback: akmens gaminiai
  7. Pingback: rich89bet
  8. Pingback: ks quik
  9. Pingback: ส่งsms
  10. Pingback: ไก่ตัน
  11. Pingback: arduino
  12. Pingback: dk7
  13. Pingback: แทงบอล
  14. Pingback: safe dayz hacks
  15. Pingback: JILISLOT
  16. Pingback: som777
  17. Pingback: ufa168
  18. Pingback: find out here now

Leave a Reply