1 / 76

Java 3D 网络上的三维动画 刘鹏 pengliu@ieee

Java 3D 网络上的三维动画 刘鹏 pengliu@ieee.org. 第一回. 起. 初识 Java 3D. What is Java 3D?. Internet 的交互式三维图形应用编程接口( API )。 让用户能够像浏览网页一样观看并操作三维动态图形 一次编程,到处运行 适应各种不同的软硬件平台. Java 3D=Java + 3D. 提高了编写三维图形程序的层次 是 Java 的嫡系 高效的三维图形语言. 更大的优点. 它是网络语言,代码可以自由传输. 从产品设计、网上 购物到各种游戏, “三维”将改变人们 在屏幕上获取信息 的习惯。.

lea
Download Presentation

Java 3D 网络上的三维动画 刘鹏 pengliu@ieee

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java 3D网络上的三维动画刘鹏 pengliu@ieee.org

  2. 第一回

  3. 初识Java 3D

  4. What is Java 3D? • Internet的交互式三维图形应用编程接口(API)。 • 让用户能够像浏览网页一样观看并操作三维动态图形 • 一次编程,到处运行 • 适应各种不同的软硬件平台

  5. Java 3D=Java + 3D • 提高了编写三维图形程序的层次 • 是Java的嫡系 • 高效的三维图形语言

  6. 更大的优点 • 它是网络语言,代码可以自由传输

  7. 从产品设计、网上购物到各种游戏,“三维”将改变人们在屏幕上获取信息的习惯。从产品设计、网上购物到各种游戏,“三维”将改变人们在屏幕上获取信息的习惯。

  8. Examples: Scientific Visualization

  9. Examples: Scientific Visualization

  10. Examples: Scientific Visualization

  11. Examples: Education

  12. Examples: Abstract Data (Financial)

  13. Examples: Medical Education

  14. Geographical information systems (GIS)

  15. Examples: CAD

  16. Examples: Analysis

  17. Examples: 3D Logos

  18. Examples: Astronomy

  19. Examples: Animations

  20. 如何用Java 3D编程

  21. 安装Java 3D • Java 2 SDK/JRE http://java.sun.com • Java 3D SDK/RT http://java.sun.com/products/java-media/3D/download.html • OpenGL • Direct3D

  22. Java 3D的编程空间

  23. Java 3D的座标系

  24. 第一个Java 3D程序 • Hello.java

  25. Hello.java • Imports • public class Hello { • public Hello() • { • Contents • } • public static void main(String[] args) • { • new Hello(); • } • }

  26. Imports • import com.sun.j3d.utils.geometry.*; • import com.sun.j3d.utils.universe.*; • import javax.media.j3d.*; • import javax.vecmath.*;

  27. Contents:空间和小球 • // 创建一个虚拟空间 • SimpleUniverse universe = new • SimpleUniverse(); • // 创建一个用来包含对象的数据结构 • BranchGroup group = new BranchGroup(); • // 创建一个球并把它加入到group中 • Sphere sphere = new Sphere(0.5f); • // 小球的半径为0.5米 • group.addChild(sphere);

  28. Contents: 灯光构件 • Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f); • // 设置光线的颜色 • BoundingSphere bounds = new BoundingSphere( • new Point3d(0.0,0.0,0.0), 100.0); • // 设置光线的作用范围 • Vector3f light1Direction = new • Vector3f(4.0f, -7.0f, -12.0f); • // 设置光线的方向

  29. Contents:灯光形成 • DirectionalLight light1= new DirectionalLight • (light1Color, light1Direction); • // 指定颜色和方向,产生单向光源 • light1.setInfluencingBounds(bounds); • // 把光线的作用范围加入光源中 • group.addChild(light1); • // 将光源加入group组

  30. Contents:观察者 • // 安放观察点 • universe.getViewingPlatform(). • setNominalViewingTransform(); • // 把group加入到虚拟空间中 • universe.addBranchGraph(group);

  31. 程序的逻辑结构

  32. 编译 • javac Hello.java 运行 • java Hello

  33. 在网上发布Java 3D程序

  34. 第一步:编写Hello.html • <APPLET CODE = "Hello.class" WIDTH=800 HEIGHT=800 ALIGN = middle > • <blockquote> • <hr> • If you were using a Java-capable browser, • you would see Hello Universe! instead of this paragraph. • <hr> • </blockquote> • </APPLET>

  35. 第二步:转换HTML • 运行 HTMLConverter.BAT http://java.sun.com/products/plugin/1.2/converter.html

  36. <HTML> • <HEAD> • <TITLE>Hello</TITLE> • </HEAD> • <BODY BGCOLOR="#000000"> • <!--"CONVERTED_APPLET"--> • <!-- CONVERTER VERSION 1.0 --> • <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" • WIDTH = 800 HEIGHT = 800 ALIGN = middle • codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0"> • <PARAM NAME = CODE VALUE = "Hello.class" > • <PARAM NAME="type" • VALUE="application/x-java-applet;version=1.2"> • <COMMENT> • <EMBED type="application/x-java-applet;version=1.2" • java_CODE="Hello.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"> • <NOEMBED> • </COMMENT> • <blockquote> • <hr> • If you were using a Java-capable browser, • you would see Hello Universe! instead of this paragraph. • <hr> • </blockquote> • </NOEMBED> • </EMBED> • </OBJECT> • </BODY> • </HTML>

  37. 执行流程

  38. 里程碑 • 什么是Java 3D • 优点、用处 • 用Java 3D编程 • 安装、程序、逻辑结构、编译、运行 • 在网上发布Java 3D Applet • 编HTML、转换、自动安装运行环境

  39. 第二回

  40. 基本形体的生成

  41. 锥体 Cone cone=new Cone(.5f,1.0f,1,app)

  42. 球体 Sphere sphere=new Sphere(.5f,app);

  43. 圆柱体 Cylinder cylinder=new Cylinder(.5f,1.0f);

  44. 直线

  45. 直线的生成 (1) • public class lineShape extends Shape3D • { • // 直线的定点坐标 • private float vert[ ]={ • .5f,0.5f,0.0f, -0.5f,0.5f,0.0f, • 0.3f,0.0f,0.0f, -0.3f,0.0f,0.0f, • -0.5f,-0.5f,0.0f, 0.5f,-0.5f,0.0f}; • // 各定点的颜色 • private float color[ ]={ • 0.0f,0.5f,1.0f, 0.0f,0.5f,1.0f, • 0.0f,0.8f,2.0f, 1.0f,0.0f,0.3f, • 0.0f,1.0f,0.3f, 0.3f,0.8f,0.0f};

  46. 直线的生成 (2) public lineShape( ) { // 创建直线数组对象 LineArray line=new LineArray(6,LineArray.COORDINATES |LineArray.COLOR_3); // 设置直线对象的坐标数组 line.setCoordinates(0,vert); // 设置直线对象的颜色数组 line.setColors(0,color);

  47. 直线的生成 (3) // 创建直线属性对象 LineAttributes linea=new LineAttributes( ); // 设置线宽 linea.setLineWidth(10.0f); // 设置直线的渲染效果 linea.setLineAntialiasingEnable(true); Appearance app=new Appearance( ); app.setLineAttributes(linea); this.setGeometry(line); this.setAppearance(app); } }

  48. 直线的使用 • BranchGroup group=new BranchGroup(); • Shape3D shape=new lineShape(); • group.addChild(shape);

  49. 二维文字 Shape3D text2D=new Text2D("清华大学",new Color3f(1f,1f,0f),"宋体",100,Font.BOLD);

  50. 三维文字

More Related