尝试制造旋转螺旋桨。一直绕着原点旋转,而不是绕着它自己旋转
我正在尝试用 Java 3D 创建一个旋转的飞机螺旋桨。此刻,它正在绕原点旋转。但是,我需要它围绕自身旋转。我没有用 Java 做过太多 3D 图形,所以我很困惑。
TransformGroup rotateTheBlades = new TransformGroup();
rotateTheBlades.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Alpha rotationAlpha = new Alpha(-1,5000);
RotationInterpolator rotator = new RotationInterpolator(
rotationAlpha,rotateTheBlades);
Transform3D abc = new Transform3D();
abc.rotZ(Math.PI/2);
rotator.setTransformAxis(abc);
rotator.setSchedulingBounds(new BoundingSphere());
rotateTheBlades.addChild(rotator);
rotateTheBlades.addChild(propeller);
sceneBG.addChild(rotateTheBlades);
任何帮助将不胜感激。 PS:我尝试将其翻译为原点之前和之后,但它似乎没有做任何事情。
I'm trying to create a spinning airplane propeller in Java 3D. At the moment, it is rotating around the origin. However, I need it to rotate around itself. I haven't done much 3D graphics in Java, so I'm pretty much stumped.
TransformGroup rotateTheBlades = new TransformGroup();
rotateTheBlades.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Alpha rotationAlpha = new Alpha(-1,5000);
RotationInterpolator rotator = new RotationInterpolator(
rotationAlpha,rotateTheBlades);
Transform3D abc = new Transform3D();
abc.rotZ(Math.PI/2);
rotator.setTransformAxis(abc);
rotator.setSchedulingBounds(new BoundingSphere());
rotateTheBlades.addChild(rotator);
rotateTheBlades.addChild(propeller);
sceneBG.addChild(rotateTheBlades);
Any help would be greatly appreciated. PS: I tried to translate it to the origin before and after but it doesn't seem to do anything whatsoever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有足够的 Java 知识来给出完整的答案;数学术语中的正确解决方案正如您所怀疑的那样:将对象的中心平移到原点,旋转,然后将其平移回原始位置。
然而,很可能(即,我猜测)当您组合变换时,它们会被后乘以产生变换在模型空间中发生的效果。您可能想要的是预乘,以产生在世界空间中发生变换的效果。
考虑一下风车的帆。在代码中,您希望能够转换到风车的顶部,然后调用绘制帆的例程。该例程可能会应用旋转,然后绘制。但就变换而言,实际上您想要在原点旋转帆,使它们绕中心旋转,然后将它们移出。因此,转换的应用顺序与您请求的顺序相反。
这意味着,您希望将变换应用为:
例如,如果您使用 OpenGL(这也是后乘法器,并且在本示例中很容易遵循,即使你实际上并不知道)你可能会这样做:
Without knowing enough Java to give a complete answer; the correct solution in maths terms is as you suspect: translate centre of the object to origin, rotate, then translate it back to its original position.
However, it's likely (ie, I'm guessing) that when you combine transformations, they're post-multiplied to give the effect that transformations happen in model space. What you probably want is pre-multiplication, to give the effect that transformations occur in world space.
Consider the sails of a windmill. In code you'd want to be able to translate to the top of the windmill, then call the routine that draws the sails. That routine might apply a rotation and then draw. But in terms of transformations, you actually you want to rotate the sails while at the origin so that they rotate around their centre, then move them out. So the transformations are applied in the opposite order to the order in which you request them.
What that means is, you want to apply the transformations as:
For example, if you were in OpenGL (which is also a post-multiplier, and easy enough to follow in this example even if you don't actually know it) you might do:
@Tommy 建议的方法是正确的。与 GL 一样,Java 图形上下文的转换是
连接
“以最常用的方式”,我认为这是最后进入,< em>先出。下面和这个完整的示例中显示了典型的paintComponent()
方法。The approach suggested by @Tommy is correct. Like GL, transformations of the Java graphics context are
concatenated
"in the most commonly useful way," which I think of as last-in, first-out. A typicalpaintComponent()
method is shown below and in this complete example.