根据此代码,stl文件的内容例如月亮形状的图像将不在框架的中心,并且其大小太大。如何将内容移动到框架的中心并减小其大小?感谢您的关注。
public class HelloUniverse2 extends JFrame implements WindowListener, MouseWheelListener
{
BranchGroup groupe;
BranchGroup objRoot;
Canvas3D canvas;
TransformGroup tg ;
public HelloUniverse2(String frameName)
{
super(frameName);
this.addWindowListener(this);
setLayout(new BorderLayout());
canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add(canvas);
try{
File file = new File("Moon.stl");
final STLFileReader reader = new STLFileReader(file);
Scene scene = STLLoader.createScene(reader);
groupe = scene.getSceneGroup();
}catch (IOException ex){
System.out.println(ex);
}
SimpleUniverse simpleU = new SimpleUniverse(canvas);
canvas.addMouseWheelListener(this);
simpleU.getViewingPlatform().setNominalViewingTransform();
objRoot =new BranchGroup();
tg = new TransformGroup();
tg.addChild(groupe);
objRoot.addChild(tg);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
MouseZoom myMouseZoom = new MouseZoom();
myMouseZoom.setTransformGroup(tg);
myMouseZoom.setSchedulingBounds(new BoundingSphere());
MouseRotate rotate = new MouseRotate(tg);
rotate.setSchedulingBounds(new BoundingSphere());
MouseTranslate translate = new MouseTranslate(tg);
translate.setSchedulingBounds(new BoundingSphere());
objRoot.addChild(myMouseZoom);
objRoot.addChild(rotate);
objRoot.addChild(translate);
simpleU.addBranchGraph(objRoot);
View view = simpleU.getViewer().getView();
view.setBackClipDistance(1000);
canvas.repaint();
}