0

次のコードがColorCubeを変換し、それ自体を中心に回転することを期待していました。代わりに、変換せず、原点を中心に回転するだけです。私はここで何が間違っているのですか?

import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class TestRotTrans {

    public TestRotTrans(){
        SimpleUniverse su = new SimpleUniverse();
        BranchGroup root = new BranchGroup();
        TransformGroup tg = new TransformGroup();
        tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        root.addChild(tg);

        // Move to center
        Transform3D translater = new Transform3D();
        translater.setTranslation(new Vector3f(-0.3f, -0.3f, -0.3f));
        tg.setTransform(translater);

        // Rotate around y
        TransformGroup tgRot = new TransformGroup();

        RotationInterpolator rotator = new RotationInterpolator(new Alpha(-1,5000), tg);
        BoundingSphere bounds = new BoundingSphere();
        rotator.setSchedulingBounds(bounds);
        tgRot.addChild(rotator);
        tg.addChild(tgRot);
        tg.addChild(new ColorCube(0.4f));

        su.addBranchGraph(root);
        su.getViewingPlatform().setNominalViewingTransform();
        su.getViewer().getView().setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
    }

    public static void main(String[] args) {
        new TestRotTrans();
    }
}

ええと...回転が始まり、翻訳を元に戻す前に、一瞬翻訳されているようです。

4

1 に答える 1

0

この問題の解決策は、tgRotをtgの親にし、rotatorにtgRotを見てもらうことでした。これにより、ツリーは次のようになります。

BranchGroup root
---- TransformGroup tgRot
     ---- RotationInterpolator rotator
     ---- TransformGroup tg
          ---- ColorCube cube
          ---- Transform3D translator
于 2013-02-21T18:26:59.390 に答える