Java 如何设置ViewingPlatform和更新TransformGroup?
我在TransformGroup中有一个场景,允许鼠标缩放/旋转/平移 我需要将摄影机位置设置回足够远的位置,以便可以看到整个场景,我使用以下代码执行此操作:Java 如何设置ViewingPlatform和更新TransformGroup?,java,opengl,graphics,3d,java-3d,Java,Opengl,Graphics,3d,Java 3d,我在TransformGroup中有一个场景,允许鼠标缩放/旋转/平移 我需要将摄影机位置设置回足够远的位置,以便可以看到整个场景,我使用以下代码执行此操作: // Position the position from which the user is viewing the scene ViewingPlatform viewPlatform = universe.getViewingPlatform(); TransformGroup viewTransform =
// 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));
与:
我失去了用鼠标操纵屏幕的能力
我如何保持在将相机进一步向后推的同时使用鼠标进行变换的能力,以便查看整个屏幕
非常感谢 .setActivationRadius使对象显示在范围内,但.setBackClipDistance有什么作用?后剪辑距离确定场景对象的后(后)距离保持可见的距离。
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);