2009-08-19 45 views
3

我有一個允許鼠標放大/旋轉/平移的TransformGroup內的場景。如何設置ViewingPlatform並更新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)); 

我失去通過屏幕來操作鼠標的能力。

如何進一步將相機向後推回以保持用鼠標進行轉換的能力,以便可以查看整個屏幕?

非常感謝提前!

回答

4
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); 
+0

.setActivationRadius使對象顯示範圍,但是.setBackClipDistance做什麼? – 2012-08-27 13:07:42

+0

後方剪輯距離決定了距離場景對象後方(後方)的距離保持可見的距離。 – Cuga 2012-08-27 15:21:39