用于多个Canvas3D的OrbitBehavior

时间:2019-03-08 21:44:41

标签: java-3d

java3d新手在这里。我学习了基础知识。设法创建两个查看同一对象的画布。我还设法使用OrbitBehavior用鼠标旋转平台:

OrbitBehavior orbit = new OrbitBehavior(canvas1, 
OrbitBehavior.REVERSE_ALL);
orbit.setSchedulingBounds(bounds);
ViewingPlatform vp = universe.getViewingPlatform();
vp.setViewPlatformBehavior(orbit);

问题是,无论我在上面的构造函数上使用canvas1还是canvas2,两个画布都一起旋转。因此,不太确定参考的用途是什么?我想要的是能够根据鼠标悬停在哪个画布上来独立地旋转每个视图。 我在做什么错了?

1 个答案:

答案 0 :(得分:0)

好的,我自己找到了答案。我需要两个在SimpleUniverse中不可用的ViewingPlatform。如果有人发现它有用,下面是创建两个Canvas3D的代码,每个代码由鼠标独立控制。

        VirtualUniverse u = new VirtualUniverse();
    Locale locale = new Locale(u);
    BranchGroup scene = new Scene(); // this is my own BranchGroup derived class for the geometry 
    locale.addBranchGraph(scene);

    GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
    gc3D.setSceneAntialiasing( GraphicsConfigTemplate.PREFERRED );
    GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

    Canvas3D canvas = new Canvas3D(gd[0].getBestConfiguration( gc3D ));
    canvas.setPreferredSize(new Dimension(600,600));
    ViewPlatform vp = new ViewPlatform();
    vp.setViewAttachPolicy( View.RELATIVE_TO_FIELD_OF_VIEW );
    ViewingPlatform viewingp = new ViewingPlatform();
    viewingp.setViewPlatform(vp);
    locale.addBranchGraph(viewingp);
    View view = new View();
    PhysicalBody pb = new PhysicalBody();
    PhysicalEnvironment pe = new PhysicalEnvironment();
    view.setPhysicalEnvironment( pe );
    view.setPhysicalBody( pb );
    view.attachViewPlatform( vp );
    view.addCanvas3D( canvas);
    OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
    orbit.setSchedulingBounds(Scene.worldBounds);
    viewingp.setViewPlatformBehavior(orbit);

    Canvas3D canvas2 = new Canvas3D(gd[0].getBestConfiguration( gc3D ));
    canvas2.setPreferredSize(new Dimension(600,600));
    ViewPlatform vp2 = new ViewPlatform();
    vp2.setViewAttachPolicy( View.RELATIVE_TO_FIELD_OF_VIEW );
    ViewingPlatform viewingp2 = new ViewingPlatform();
    viewingp2.setViewPlatform(vp2);
    locale.addBranchGraph(viewingp2);
    View view2 = new View();
    PhysicalBody pb2 = new PhysicalBody();
    PhysicalEnvironment pe2 = new PhysicalEnvironment();
    view2.setPhysicalEnvironment( pe2 );
    view2.setPhysicalBody( pb2 );
    view2.attachViewPlatform( vp2 );
    view2.addCanvas3D( canvas2);
    OrbitBehavior orbit2 = new OrbitBehavior(canvas2, OrbitBehavior.REVERSE_ALL);
    orbit2.setSchedulingBounds(Scene.worldBounds);
    viewingp2.setViewPlatformBehavior(orbit2);