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

📄 cone3d.java

📁 Java 多媒体技术(附源码) Java 3D API JavaSound API 各种格式的多媒体数据文件 JBuilder开发环境
💻 JAVA
字号:
package cone3d;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.awt.BorderLayout;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.geometry.Cone;import com.sun.j3d.utils.universe.*;import javax.media.j3d.*;import javax.vecmath.*;/** * <p>Title: 红色圆锥体</p> * <p>Description: 应用Java 3D API生成一个三维红色圆锥体</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: 北京师范大学计算机系</p> * @author 王大伟 * @version 1.0 */public class Cone3D extends Applet{  boolean isStandalone = false; public BranchGroup createSceneGraph(){//生成三维场景图的方法  BranchGroup objRoot = new BranchGroup();  TransformGroup objTrans = new TransformGroup();  objRoot.addChild(objTrans);  BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);  Color3f bgColor = new Color3f(1.0f,1.0f,1.0f);  Background bg = new Background(bgColor);   bg.setApplicationBounds(bounds);  objRoot.addChild(bg);  Color3f directionalColor = new Color3f(1.0f,1.0f,1.0f);  Vector3f vec = new Vector3f(0.0f,0.0f,-1.0f);  DirectionalLight directionalLight = new DirectionalLight(directionalColor,vec);  directionalLight.setInfluencingBounds(bounds);  objRoot.addChild(directionalLight);  Appearance app = new Appearance();  Material material = new Material();   material.setEmissiveColor(new Color3f(1.0f,0.0f,0.0f));  app.setMaterial(material);  Cone cone = new Cone(0.5f,1.0f,1,app);  objTrans.addChild(cone);  objRoot.compile();  return objRoot; } public Cone3D(){//程序的构造方法  setLayout(new BorderLayout());  GraphicsConfiguration config =           SimpleUniverse.getPreferredConfiguration();  Canvas3D c = new Canvas3D(config);  add("Center",c);  BranchGroup scene = createSceneGraph();  SimpleUniverse u = new SimpleUniverse(c);  u.getViewingPlatform().setNominalViewingTransform();  u.addBranchGraph(scene); }  public static void main(String[] args) {    Cone3D applet = new Cone3D();    applet.isStandalone = true;    Frame frame;    frame = new Frame() {      protected void processWindowEvent(WindowEvent e) {        super.processWindowEvent(e);        if (e.getID() == WindowEvent.WINDOW_CLOSING) {          System.exit(0);        }      }      public synchronized void setTitle(String title) {        super.setTitle(title);        enableEvents(AWTEvent.WINDOW_EVENT_MASK);      }    };    frame.setTitle("演示生成三维红色圆锥体");    frame.add(applet, BorderLayout.CENTER);    applet.init();    applet.start();    frame.setSize(400,320);    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);    frame.setVisible(true);  }}

⌨️ 快捷键说明

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