⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicscene.java

📁 JAVA3D 的基本应用。关于BASIC SENCE 的运用。依据JAVA3D 的API可以很好的掌握。
💻 JAVA
字号:
import javax.swing.JFrame;
import javax.vecmath.Point3d;

import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;

public class BasicScene extends CustomFrame 
{
  public static void main(String args[])
  {
    new BasicScene();
  }
  
  public Canvas3D canvas;
  
  public BasicScene()
  {
    getContentPane().setLayout(new BorderLayout());

    GraphicsConfiguration config = 
      SimpleUniverse.getPreferredConfiguration();

    // Create a Canvas3D object and add it to the frame
     canvas = new Canvas3D(config);
     canvas.addMouseListener(this);
    getContentPane().add(canvas, BorderLayout.CENTER);

    // Create a SimpleUniverse object to mange the ``view" branch
    SimpleUniverse u = new SimpleUniverse(canvas);
    u.getViewingPlatform().setNominalViewingTransform();

    // Add the ``content" branch to the SimpleUniverse
    BranchGroup scene = createContentBranch();
    u.addBranchGraph(scene);
    
    setSize(256, 256);
    setVisible(true);
    }

  public BranchGroup createContentBranch() 
  {
    BranchGroup root = new BranchGroup();
  
    // Create the transform group
    TransformGroup transformGroup = new TransformGroup();
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    root.addChild(transformGroup);
    
    // Create the mouse rotate behaviour
    MouseRotate rotate = new MouseRotate();
    rotate.setTransformGroup(transformGroup);
    rotate.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    transformGroup.addChild(rotate);
    
    // The color cube geometry
    ColorCube colorCube = new ColorCube(0.3);
    transformGroup.addChild(colorCube);

    root.compile();

    return root;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -