旋转3D对象的3轴的JavaFX正确 [英] Rotate a 3D object on 3 axis in JavaFX properly

查看:530
本文介绍了旋转3D对象的3轴的JavaFX正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经使用,到目前为止,在JavaFX的旋转物体的方法是,我在3组,每组都带着旋转连接并锁定到一个轴,像这样层次的:

So the method that I've used so far to rotate objects in JavaFX was that I layered it in 3 groups, each of them with a Rotate attached and locked to a single axis like so:

    Rotate heading, roll, pitch;
    Group normalrotate, rollrotate, verticalrotate;

    heading.setAxis(new Point3D(0,1,0));
    normalrotate.getTransforms().add(heading);

    roll.setAxis(new Point3D(0,0,1));
    rollrotate.getTransforms().add(roll);

    pitch.setAxis(new Point3D(1,0,0));
    verticalrotate.getTransforms().add(pitch);

和做了setAngle()我需要旋转对象每次。这个工作非常出色仅供航向和滚动,直到我决定,我需要球场了。现在很多教程OpenGL和一致好评说,旋转matixes或四元是最适合这些类型的旋转,但javadoc的缺乏任何有用的数据regaring这一点。

and did a setAngle() for each time I needed to rotate the object. This worked very well for only heading and roll until i decided that I need pitch too. Now a lot of tutorials for OpenGL and alike say that rotational matixes or quaternions are best for these type of rotations, but the javadoc lacks any usefull data regaring this.

例如:当我通过在y轴180度旋转的对象会发生什么(什么应实际发生在透明的蓝色) 我失去了一些东西? 所有的帮助将是AP preciated。

Example: What happens when I rotate an object by 180 degrees on the y axis (and what should actually have happened in transparent blue) Am I missing something? All help would be appreciated.

推荐答案

还有一个原因,为什么所有这些教程指向旋转矩阵:在3D,你不能一个一个进行同步旋转,则需要执行一次他们。由于JavaFX的只使用一个角度和一个轴,你必须提供超过三个轴只在一个角度和一个轴转换三个旋转的方式。

There's a reason why all those tutorials point to rotational matrices: in 3D you can't perform simultaneous rotations one by one, you need to perform them at once. Since JavaFX only uses one angle and one axis, you have to provide the way to convert three rotations over three axes in just one angle and one axis.

前一段时间我去这些操作背后的数学在我的博客的有关使用大跃进运动让你的手(俯仰,偏航,滚动)的三个旋转旋转的3D模型后

A while ago I went to all the math behind these operations in my blog post about using Leap Motion to get the three rotations of your hand (pitch, yaw, roll) to rotate a 3D model.

因此​​,基本上,从三个旋转:螺距(围绕其X轴),横摆(绕Y轴)和滚动(绕Z轴),您有这些矩阵

So basically, from three rotations: pitch (around its X axis), yaw (around its Y axis) and roll (around its Z axis), you have these matrices:

如果你把他们,你有一个单一的矩阵:

and if you combine them you have one single matrix:

无需进一步解释,角度和旋转酉轴组件可以从计算:

Without further explanations, the angle and the rotation unitary axis components can be computed from:

哪些可以写为:

private void matrixRotateNode(Node n, double alf, double bet, double gam){
    double A11=Math.cos(alf)*Math.cos(gam);
    double A12=Math.cos(bet)*Math.sin(alf)+Math.cos(alf)*Math.sin(bet)*Math.sin(gam);
    double A13=Math.sin(alf)*Math.sin(bet)-Math.cos(alf)*Math.cos(bet)*Math.sin(gam);
    double A21=-Math.cos(gam)*Math.sin(alf);
    double A22=Math.cos(alf)*Math.cos(bet)-Math.sin(alf)*Math.sin(bet)*Math.sin(gam);
    double A23=Math.cos(alf)*Math.sin(bet)+Math.cos(bet)*Math.sin(alf)*Math.sin(gam);
    double A31=Math.sin(gam);
    double A32=-Math.cos(gam)*Math.sin(bet);
    double A33=Math.cos(bet)*Math.cos(gam);

    double d = Math.acos((A11+A22+A33-1d)/2d);
    if(d!=0d){
        double den=2d*Math.sin(d);
        Point3D p= new Point3D((A32-A23)/den,(A13-A31)/den,(A21-A12)/den);
        n.setRotationAxis(p);
        n.setRotate(Math.toDegrees(d));                    
    }
}

其中, ALF 是卷,下注是俯仰和 GAM 是偏航。

where alf is roll, bet is pitch and gam is yaw.

您可以找到完整的项目这里

You can find the full project here.

这篇关于旋转3D对象的3轴的JavaFX正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆