多个Canvas3D的OrbitBehavior

问题描述 投票:-1回答:1

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

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

事情是,无论我在上面的构造函数上使用canvas1还是canvas2,两个画布都会一起旋转。所以不太清楚参考是什么?我想要的是能够根据鼠标所在的画布独立旋转每个视图。我究竟做错了什么?

java-3d
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.