2012-01-26 118 views

回答

1

實際上,默認的宇宙在技術上是無限的,畢竟它是一個虛擬的宇宙。

這是Java3D的宇宙是如何工作的:

enter image description here

來源:

所以宇宙不是太小,您的對象對於您想要獲得的視圖來說太大了。圖片站在一座巨大的建築旁邊,它們不可能一次看到整個事物,但如果你退後一步,你可以從遠處看到它,它看起來更小。所以,你需要移動物體或移動視圖。這裏是你如何移動你的對象:

TransformGroup moveGroup = new TransformGroup(); 
Transform3D move = new Transform3D(); 
move.setTranslation(new Vector3f(0.0f, 0.0f, -10.0f)); 
//^^ set the Vector3f to where you want the object to be 
moveGroup.setTransform(move); 
moveGroup.addChild(YOUR_OBJECT); 

你也可以改變你的觀看平臺正在查看的地方。這裏是你會怎麼做:

public class MoveEye extends Applet 
{ 
    public MoveEye() 
    { 
     setLayout(new BorderLayout()); 
     GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); 
     Canvas3D canvas = new Canvas3D(config); 
     add("Center", canvas); 

     BranchGroup content = getScene(); 
     content.compile(); 

     SimpleUniverse universe = new SimpleUniverse(canvas); 
     Transform3D move = lookTowardsOriginFrom(new Point3d(0, 0, -3)); 
     universe.getViewingPlatform().getViewPlatformTransform().setTransform(move); 
     universe.addBranchGraph(content); 
    } 

    public BranchGroup getScene() 
    { 
     BranchGroup group = new BranchGroup(); 

     group.addChild(new ColorCube(.5)); 

     return group; 
    } 

    public Transform3D lookTowardsOriginFrom(Point3d point) 
    { 
     Transform3D move = new Transform3D(); 
     Vector3d up = new Vector3d(point.x, point.y + 1, point.z); 
     move.lookAt(point, new Point3d(0.0d, 0.0d, 0.0d), up); 

     return move; 
    } 

    public static void main(String args[]) 
    { 
     Frame frame = new MainFrame(new MoveEye(), 256, 256); 
    } 
} 

這可能是很好的做法,只是移動視圖,而不是移動的對象,但在這種情況下,你可以做任何我想,我希望這有助於!