围绕Java3D中的特定点旋转 [英] Rotate around a specific point in Java3D

查看:239
本文介绍了围绕Java3D中的特定点旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java3D中导入2个模型,缩小它们,然后使用 RotationInterpolator



<旋转其中一个模型p>但是,这会使对象围绕原点旋转。我想围绕ITS中心旋转对象,而不是场景。简而言之,我希望它能够旋转到位。



如何围绕特定点旋转?

  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(theBlades);

这是我执行当前轮换的代码。

解决方案

DR回答将对象转换为原点,执行旋转,然后将对象转换回其位置。哪个有效。



我的实际解决方案是简单地将模型置于.obj文件中的原点,我将其加载到Java3D中,执行旋转,然后翻译对象到了正确的位置。


I'm importing 2 models in Java3D, scaling them down and then rotating one of them using a RotationInterpolator

However, this rotates the object around the origin. I want to rotate the object around ITS centre, not the scene's. Put simply, I want it to spin in place.

How do I rotate around a specific point?

    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(theBlades);

This is my code for doing my current rotation.

解决方案

DR answered with translating the object to the origin, performing the rotation, then translating the object back to its position. Which worked.

My actual solution was to simply centre the model at the origin in the .obj file I was loading into Java3D, perform my rotation, and then translate the objects to their proper position.

这篇关于围绕Java3D中的特定点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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