2011-10-17 20 views
1

我有一個Java小程序,它應該顯示2個球體。它工作正常,直到我的球體的平移超出了-1.0到1.0的範圍,在這種情況下對象將消失。我有一個SimpleUniverse設置,我在幾個地方嘗試了幾個setBounds,但我無法弄清楚它是如何消失的。真正的奇怪,這是位置是不依賴於相機的位置,因爲我有一個OrbitBehavior在ViewPlatform變換在靠近不顯示對象。在Java3D中只在-1.0到+1.0範圍內可見的對象的翻譯位置

這是球體的設置: 公共類CelestialBody擴展的TransformGroup {

CelestialBody(float posX, float posY, float posZ) { 
     // This is set for the dynamic behaviour. 
     setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 

     Transform3D t3d = new Transform3D(); 
     t3d.setTranslation(new Vector3f(posX, posY, posZ)); 
     setTransform(t3d); 
     setBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 10000.0f)); 

     Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 100, createAppearance()); 

     addChild(sphere); 
    } 

    private Appearance createAppearance() { 
     Appearance appear = new Appearance(); 
     Material mat = new Material(); 
     mat.setShininess(100.0f); 
     appear.setMaterial(mat); 

     return appear; 
    } 
} 

這是主程序:

public class CelestialApp extends Frame { 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     new CelestialApp(); 
    } 

    private SimpleUniverse universe = null; 

    public CelestialApp() { 
    // ... 

     BranchGroup scene = constructContentBranch(); 
     scene.compile(); 

     universe = new SimpleUniverse(defaultCanvas); 
     setupView(); 
     universe.addBranchGraph(scene); 
    } 

    private void setupView() { 
     ViewingPlatform vp = universe.getViewingPlatform(); 
     OrbitBehavior orbit = new OrbitBehavior(); 
     orbit.setSchedulingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 10000.0f)); 
     vp.setNominalViewingTransform(); 
     vp.setViewPlatformBehavior(orbit); 
    } 

    private BranchGroup constructContentBranch() { 
     BranchGroup scene = new BranchGroup(); 

     CelestialBody body1 = new CelestialBody(-2.0f, 0.0f, 0.0f); 
     scene.addChild(body1); 

     CelestialBody body2 = new CelestialBody(2.0f, 0.0f, -1.1f); 
     scene.addChild(body2); 

     PhysicalBehavior physics1 = new PhysicalBehavior(body1); 
     scene.addChild(physics1); 

     PhysicalBehavior physics2 = new PhysicalBehavior(body2, new Vector3d(0.0f, 0.0f, 0.0f)); 
     scene.addChild(physics2); 

     setupLights(scene); 

     return scene; 
    } 

    private void setupLights(BranchGroup scene) { 
     AmbientLight lightA = new AmbientLight(); 
     lightA.setInfluencingBounds(new BoundingSphere()); 
     lightA.setColor(new Color3f(0.3f, 0.3f, 0.3f)); 
     scene.addChild(lightA); 

     DirectionalLight lightD1 = new DirectionalLight(); 
     lightD1.setInfluencingBounds(new BoundingSphere()); 
     Vector3f dir = new Vector3f(-0.3f, -1.0f, -0.5f); 
     dir.normalize(); 
     lightD1.setDirection(dir); 
     lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); 
     scene.addChild(lightD1); 

     Background bg = new Background(0.0f, 0.0f, 0.0f); 
     bg.setApplicationBounds(new BoundingSphere()); 
     scene.addChild(bg); 
    } 
} 
+0

在沒有任何代碼的情況下很難分辨出這裏發生了什麼。你能給至少相關的片段嗎? –

+0

主要課程:http://pastebin.com/FfL4BBgU 而對象課程:http://pastebin.com/TGZDD8Cd – progician

+0

請編輯它到問題中(理想情況下刪除任何不相關的東西),而不僅僅是給我們一個鏈接。 –

回答

0

呸,沒關係。光源只有一個半徑爲1.0f的邊界球體,並且該物體被渲染,但呈現黑色。