如何在JavaFX中获取Node的绝对旋转 [英] How to get the absolute rotation of a Node in JavaFX
本文介绍了如何在JavaFX中获取Node的绝对旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在JavaFX中,Node的rotateProperty为我提供了相对于其父级的旋转度。有没有办法获得相对于场景或屏幕的度数绝对旋转?
In JavaFX the rotateProperty of a Node provides me with its rotation in degree relative to its parent. Is there a way to get the absolute rotation in degree, either relative to the Scene or the Screen?
例如,有没有办法从我可以从getLocalToSceneTransform()获得的Node的Transform对象计算角度?
For example, is there a way to calculate the angle from the Transform object of a Node i can get from getLocalToSceneTransform()?
推荐答案
所以,我自己做了数学计算,对于我的情况,我要么通过以下方式获得Radians的轮换:
So, i did the math myself, and for my case i either get the rotation in Radians via:
double xx = myNode.getLocalToSceneTransform().getMxx();
double xy = myNode.getLocalToSceneTransform().getMxy();
double angle = Math.atan2(-xy, xx);
或
double yx = myNode.getLocalToSceneTransform().getMyx();
double yy = myNode.getLocalToSceneTransform().getMyy();
double angle = Math.atan2(yx, yy);
在这两种情况下都可以转换为360度:
In both cases this can be converted to 360-degrees:
angle = Math.toDegrees(angle);
angle = angle < 0 ? angle + 360 : angle;
这篇关于如何在JavaFX中获取Node的绝对旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文