java - 如何设置ViewingPlatform和更新TransformGroup?

标签 java opengl graphics 3d java-3d

我在 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));

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

如何在将相机向后推得更远的同时保持用鼠标变换的能力,以便我可以查看整个屏幕?

非常感谢!

最佳答案

    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);

关于java - 如何设置ViewingPlatform和更新TransformGroup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1300447/

相关文章:

java - Tomcat websockets 与独立java进程通信

java - 选择具有给定注释的类

java - "if"语句有什么问题?

opengl - OpenGL-为什么要删除矩阵堆栈,现在人们在使用什么?

OpenGL/Gtkmm 游戏 - 键盘移动

c++ - Qt 5.1.1 和 OpenGL - 渲染速度

java - 尝试创建随机的 "solar system"

java - 如何在同一个查询中同时将两个Arraylist值插入到数据库表中

java - 渲染针对调色板有限的设备的 2D 图像

c++ - 在 openGL 纹理中加载图像(使用它们的 RGB(A) 像素数据)