我希望下面的代码翻译 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();
}
}
嗯......它似乎确实翻译了一瞬间,然后旋转开始并撤消翻译。