如何设置ViewingPlatform和更新TransformGroup?

发布于 2024-08-02 11:41:36 字数 937 浏览 2 评论 0原文

我在 TransformGroup 中有一个场景,允许鼠标缩放/旋转/平移。

我需要将相机位置设置得足够远,以便可以看到整个场景,我使用以下代码执行此操作:

    // Position the position from which the user is viewing the scene
    ViewingPlatform viewPlatform = universe.getViewingPlatform();
    TransformGroup viewTransform = viewPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    viewTransform.getTransform(t3d);
    t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

执行上述代码可以使用鼠标操作场景。但是,如果我用:替换这一行:

t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));

// Change value from 50 to 90 to push the camera back further
t3d.lookAt(new Point3d(0,0,90), new Point3d(0,0,0), new Vector3d(0,1,0));

就失去了用鼠标操作屏幕的能力。

如何保持鼠标变换的能力,同时将相机进一步向后推,以便我可以查看整个屏幕?

非常感谢!

I have a scene inside of a TransformGroup that allows the mouse to zoom/rotate/pan.

I need to set the camera position back far enough that I can see the entire scene, which I do with the following code:

    // Position the position from which the user is viewing the scene
    ViewingPlatform viewPlatform = universe.getViewingPlatform();
    TransformGroup viewTransform = viewPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    viewTransform.getTransform(t3d);
    t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

Executing the above code works in that I can manipulate the scene with the mouse. However, if I swap out this line:

t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));

with:

// Change value from 50 to 90 to push the camera back further
t3d.lookAt(new Point3d(0,0,90), new Point3d(0,0,0), new Vector3d(0,1,0));

I lose the ability to manipulate the screen with the mouse.

How can I maintain the capability to transform with the mouse while pushing the camera back further so that I can view the entire screen?

Much thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-08-09 11:41:36
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3d = new Canvas3D(config);

    // Manually create the viewing platform so that we can customize it
    ViewingPlatform viewingPlatform = new ViewingPlatform();

    // **** This is the part I was missing: Activation radius
    viewingPlatform.getViewPlatform().setActivationRadius(300f);

    // Set the view position back far enough so that we can see things
    TransformGroup viewTransform = viewingPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    // Note: Now the large value works
    t3d.lookAt(new Point3d(0,0,150), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

    // Set back clip distance so things don't disappear 
    Viewer viewer = new Viewer(canvas3d);
    View view = viewer.getView();
    view.setBackClipDistance(300);

    SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3d = new Canvas3D(config);

    // Manually create the viewing platform so that we can customize it
    ViewingPlatform viewingPlatform = new ViewingPlatform();

    // **** This is the part I was missing: Activation radius
    viewingPlatform.getViewPlatform().setActivationRadius(300f);

    // Set the view position back far enough so that we can see things
    TransformGroup viewTransform = viewingPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    // Note: Now the large value works
    t3d.lookAt(new Point3d(0,0,150), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

    // Set back clip distance so things don't disappear 
    Viewer viewer = new Viewer(canvas3d);
    View view = viewer.getView();
    view.setBackClipDistance(300);

    SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文