Java3D universe size is too small to fit object

心不动则不痛 提交于 2019-12-11 02:53:12

问题


The default universe bounds are x=[-1 meter,1 meter], y=[-1,1] and z=[-1,1]. When objects intersect these bounds they are rendered only partially. How can I set another universe size?


回答1:


Well actually, the Default Universe technically is unlimited, it is a virtual universe after all.

This is how the Java3D universe works:

Source:

  • http://java.sun.com/developer/onlineTraining/java3d/j3d_tutorial_ch1.pdf (Page 1-11)

So the universe is not too small, your object is just simply too big for the view you are trying to get. Image standing right next to a massive building, theres no way you can see the whole thing at once, but if you step back you can all of it from a distance and it appears smaller. So, you either need to move the object or move your view. Here is how you would move your object:

TransformGroup moveGroup = new TransformGroup();
Transform3D move = new Transform3D();
move.setTranslation(new Vector3f(0.0f, 0.0f, -10.0f));
//^^ set the Vector3f to where you want the object to be
moveGroup.setTransform(move);
moveGroup.addChild(YOUR_OBJECT);

You can also change where your viewing platform is viewing from. Here is how you would do that:

public class MoveEye extends Applet
{
    public MoveEye()
    {
        setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas = new Canvas3D(config);
        add("Center", canvas);

        BranchGroup content = getScene();
        content.compile();

        SimpleUniverse universe = new SimpleUniverse(canvas);
        Transform3D move = lookTowardsOriginFrom(new Point3d(0, 0, -3));
        universe.getViewingPlatform().getViewPlatformTransform().setTransform(move);
        universe.addBranchGraph(content);
    }

    public BranchGroup getScene()
    {
        BranchGroup group = new BranchGroup();

        group.addChild(new ColorCube(.5));

        return group;
    }

    public Transform3D lookTowardsOriginFrom(Point3d point)
    {
        Transform3D move = new Transform3D();
        Vector3d up = new Vector3d(point.x, point.y + 1, point.z);
        move.lookAt(point, new Point3d(0.0d, 0.0d, 0.0d), up);

        return move;
    }

    public static void main(String args[])
    {
        Frame frame = new MainFrame(new MoveEye(), 256, 256);
    }
}

It's probably good practice to just move the View instead of moving the object but in this case you can do either i suppose, i hope this helped!



来源:https://stackoverflow.com/questions/9020783/java3d-universe-size-is-too-small-to-fit-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!