java3d_API_java3d_programming

合集下载

Java3D类简单说明

Java3D类简单说明

Java3D类简单说明很长时间没有听到关于Java3D的消息了,好像Sun已经放弃了Java3D一样,不过Java3D 作为一门纯正的面向对象的3D技术,还是很值得我们学习和使用的。

不过话说回来Java3D 开发的真是比较粗糙。

下面介绍些Java3D常用的类吧。

Canvas3D 类Canvas3D 类继承自Abstract Windowing Toolkit (AWT)类的Canvas类.在场景图的视图分支图中,至少要引用一个 Canvas3D对象(注:有可能存在多个Canvas3D对象,为了使演示简单,在使用SimpleUniverse类时,在程序中仅有 Canvas3D类的一个实例)。

关于Canvas 类更多的信息,请参考AWT。

附录B中提供了一系列参考。

Canvas3D 类的构造函数Canvas3D(GraphicsConfiguration graphicsconfiguration) 构造并初始化一个新的Canvas3D对象,Java 3D可以在给定的GraphicsConfiguration对象条件下渲染这个对象。

这是 AWT Canvas类的扩展的类。

关于GraphicsConfiguration 对象的更多信息请参考Java 2D规范。

这也是JDK 1.2 AWT的一部分。

Transform3D 类Transform3D 对象用于进行3D几何形变比于平移和旋转。

这些对象一般仅仅用于创建一个TransformGroup对象。

首先, Transform3D对象可能基于一些Transform3D对象的组合而创建,然後就用这个Transform3D来构建一个] TransformGroup对象。

Transform3D默认的构造函数一个通常的变换对象就表示为一个4x4双精度浮点矩阵。

这种数学表示是以行为主的。

一个Transform3D对象不是在场景图中用到的,而是用于指定TransformGroup对象的图形变换的。

Java3D总结

Java3D总结

Java3D介绍Java3d是适应与internet 环境下开发的三维图形开发包,它针对底层库openGL 和DirectX 的封装。

这样使得他们摆脱了单机三维束缚,面向与网络方向。

OpenGL :图形编程库。

(如坐标的变化,基本形体,关照效果等)DirectX :微软公司三维库传统下的Internet 图形处理,数据不是从本地硬盘中读取,运行环境也不是事先安装好的,如果用OpenGL 等传统的可视手段,只能在Web服务器端生成图像,在发到客户端显示。

但是当前的网络传输能力是不可能满足的。

(但是java3的是传输的不是图像本生,而是三维图像生成的程序和数据)当前下的Java3d是这样的:java3d是基于OpenGL或DirectX底层的API。

他和java 一样需要安装,jre(java虚拟机)一次编程,跨平台运行。

所以说他很好的运用了pc机的硬件加速器。

(当前我们现在用的是WebStart来下载java3d程序,他保证了如果服务器端没有升级变化时,只需要下载一次,以后就可以直接运行)。

Java3d 本质是一个交互式三维图形应用编程接口(api),他可以和java2d,swing,awt 结合。

其目标是:让用户在浏览器中观看或操作三维动画图形。

一次编程,到处运行。

适应不同的软件平台。

适应各种显示环境和输入设备。

Java3d的编程思想Java3d编程的空间采用场景图结构,是一种有向无环图。

如图:locale下有一到多个branchgroup节点,在他下有一个基准坐标系transformgroup,就可以相对此坐标系摆放所需的形体(shape3d)也可以给出形体的外观appearance及geometry。

所以:他就是将许多对象安放在这个虚拟空间的过程,在设置各个方面的属性,如:形状,位置,外观,贴图,透明效果等;再在三维环境下设置灯光,雾,背景,声音等。

最后定义我们自己的观察角度,最终达到效果。

编写Java3D程序的一般步骤

编写Java3D程序的一般步骤

编写Java3D程序的一般步骤SceneGraphObject类的子类就是集成构建场景图的模块,一个Java3D程序的开发大略可以分为七步(把它们聚在一起,在Java 3D API 规范中和这里称之为步骤(recipe)),具体如下列表所示,这些方法可用于装配许多的Java3D程序。

1. 创建一个Canvas3D对象。

2. 创建一个VirtualUniverse对象。

3. 创建一个Locale 对象,并使之与VirtualUniverse相关联。

4. 构建一个视图子图。

a. 创建一个View 对象。

b. 创建一个ViewPlatform对象。

c. 创建一个PhysicalBody对象。

d. 创建一个PhysicalEnvironment对象。

e. 把 ViewPlatform, PhysicalBody, PhysicalEnvironment, 和Canvas3D对象与View 对象相关联。

5. 构建一个或多个内容子图。

6. 编译所有子图。

7. 把子图加到Locale对象中。

表 1-1 编写Java3D程序的一般步骤这些步骤忽略了细节但是解释了Java 3D编程中的基本概念。

创建场景图中的子图是编程的主要部分。

但我们并没有展开这些步骤详细讨论,本教程的下一部分解释了一种用更少的代码更容易的手段来构建一个非常简单的场景图的方法。

1.4.1 编写Java 3D程序的一个简单方法用基本方法编写具有视图分支图的Java 3D programs程序的结构有其唯一性,构建视图分支子图结构的规则可以通过SimpleUniverse工具类来实现. SimpleUniverse 的实例承担了构建场景图的基本步骤中的第2, 3以及第4步。

利用SimpleUniverse类来进行Java3D编程,可以大大减少创建视图分支图的时间和精力,从而,程序员可以有更多的时间来构建内容分支子图,这才是真正与Java3D程序事关重大的。

java3D

java3D

Java3d整理Java3d基础环境配置1.1安装JDK1.2安装官网下载最新版本简单实例2.1新建java项目2.2导入基本jar包,jar包下载2.3编写代码package measoft.java3d.base;import java.applet.Applet;import java.awt.BorderLayout;import java.awt.GraphicsConfiguration;import javax.media.j3d.Appearance;import javax.media.j3d.Background;import javax.media.j3d.BoundingSphere;import javax.media.j3d.BranchGroup;import javax.media.j3d.Canvas3D;import javax.media.j3d.DirectionalLight;import javax.media.j3d.Material;import javax.media.j3d.TransformGroup;import javax.vecmath.Color3f;import javax.vecmath.Point3d;import javax.vecmath.Vector3f;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.geometry.Cone;import com.sun.j3d.utils.universe.SimpleUniverse; /*** 使用了SimpleUniverse对象,使得基本步骤比较简单:* 1.创建一个Canvas3D对象。

* 2.创建并定制一个SimpleUniverse对象,该对象引用前一步创建的Canvas3D对象* 3.构建内容子图* 4.编译内容子图* 5.将内容子图插入SimpleUniverse的Locale中*** @author J_nan**/publicclass MyCone extends Applet {public BranchGroupcreateSceneGroup(){/*** 一、 1.创建一个包含对象的数据结构2.生成坐标系3.将坐标系添加到跟节点上4.设置场景的有效范围*/BranchGroupobjRoot = new BranchGroup();TransformGroupobjTrans = new TransformGroup();objRoot.addChild(objTrans);BoundingSphere bounds = new BoundingSphere(newPoint3d(0.0,0.0,0.0),100.0);/*** 二、1. 创建背景颜色 2.设置背景边界 3.添加背景到场景中*/Color3f bgColor = new Color3f(0.0f,0.0f,0.0f);Background bg = new Background(bgColor);bg.setApplicationBounds(bounds);objRoot.addChild(bg);/*** 三、1. 添加平行光 2.给指定的bounds设定光的范围界限*/Color3f directionalLightColor = new Color3f(1.f,1.f,1.f);Vector3f vec = new Vector3f(0.f,0.f,-1.0f);DirectionalLightdirectionalLight =new DirectionalLight(directionalLightColor,vec);directionalLight.setInfluencingBounds(bounds);objRoot.addChild(directionalLight);/*** 四、1.设置外观 2.设置材料 3.生成基本圆锥*/Appearance app = new Appearance();Material material = new Material();material.setDiffuseColor(new Color3f(10.f,1.0f,0.0f));app.setMaterial(material);Cone cone = new Cone(.5f,1.0f,1,app);objRoot.addChild(cone);/*** 五、返回objRoot*/return objRoot;}public MyCone(){setLayout(new BorderLayout());GraphicsConfigurationconfig =SimpleUniverse.getPreferredConfiguration();/*** 第一步:Canvas3D类提供了一个3D渲染绘图画布,构造并初始化一个新的Canvas3D对象*/Canvas3D c = new Canvas3D(config);/*** 第二步:创建虚拟空间*/SimpleUniverse u = new SimpleUniverse(c);/*** 第三步:构建内容子图*/BranchGroup scene = createSceneGroup();/*** 第四步:编译内容子图*/pile();/*** 第五步:将内容子图插入SimpleUniverse的Locale中*/u.addBranchGraph(scene);add("Center",c);//安放观察点u.getViewingPlatform().setNominalViewingTransform();}publicstaticvoid main(String[] args) {new MainFrame(new MyCone(),400,300);}}运行效果如图:编写JAVA3D程序的一般步骤:A.SceneGraphObject的子类是构建场景图的基石。

Java 3D编程

Java 3D编程
Java 3D 编程之圆柱体
疑问:Java 3D之 物体的构建问题

1.骨架构建:如何构建要仿真的物体骨架? 2.贴图(蒙皮):当物体的骨架搭建完成后,如 何是物体外形接近真实的物体呢?
Java 3D 之 骨架


1.使用Java 3D中的现有的形体,构建出物体 的骨架 2.可以借用第三方工具(Maya、3D Max)形成 物体的骨架
Java 3D 编程之圆柱体

import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.DirectionalLight; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.Cylinder; import com.sun.j3d.utils.universe.SimpleUniverse; public class MyCylinder { public MyCylinder (){ //构建空间 和物体 // 创建一个虚拟空间 SimpleUniverse universe = new SimpleUniverse(); // 创建一个用来包含对象的数据结构 BranchGroup group = new BranchGroup(); // 创建一个圆柱形状并把它加入到group中 Cylinder cylinder=new Cylinder(.5f,1.0f); //圆柱型 group.addChild(cylinder); //灯光构造 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); // 设置光线的方向 DirectionalLight light1= new DirectionalLight(light1Color, light1Direction); // 指定颜色和方向,产生单向光源 light1.setInfluencingBounds(bounds); // 把光线的作用范围加入光源中 group.addChild(light1); // 将光源加入group组 // 安放观察点 universe.getViewingPlatform().setNominalViewingTransform(); // 把group加入到虚拟空间中 universe.addBranchGraph(group); } public static void main(String[] args) {

Java3D基本图形功能介绍

Java3D基本图形功能介绍

1.1Java3D的虚拟场景空间设计Java3D是一种面向对象的API。

通过场景图来管理场景中的各种图形元素。

场景图是一个树状结构,在该树状结构的各级节点表示该场景中的各种图形元素。

将由各种图形元素形成的一个场景的整体称为一个虚拟空间。

在这个虚拟空间中的图形元素包括:几何体的定义数据,几何显示时的颜色、材质、透明度等属性,背景颜色,光线类型,场景的作用范围,视点、投影面及投影类型,对几何体的坐标变换等。

Java3D与Java一样对各种功能的组织同样采用父类、子类、对象实例的方式。

Java3D中规定了在一个虚拟场景空间中各种图形元素的表示符号及虚拟场景空间的组织结构。

在一个虚拟空间中可以包含多个Local节点。

一个Local节点表示一个子场景的根节点。

多个Local节点表示在该虚拟场景中有多个场景的根节点。

但是在实际应用中最常使用的是在一个虚拟空间中只包含一个子场景,也就是只包含一个Local节点。

在一个Local节点之下,可以包含一个到多个BranchGroup节点。

每个BranchGroup 节点表示一种图形元素的集合。

这种图形元素的集合主要有两种:(1)定义几何体的数据与定义该几何体的颜色、材质、透明度等外观的属性;(2)定义该几何体在显示的时候在该场景中的其他元素,如背景颜色、光源类型、视点位置与观察方向、投影平面的位置、坐标变换等。

在实际应用中,最常用的是一个Local 节点下只含有一个BranchGroup节点。

在一个Local节点下只含有一个BranchGroup节点情况下,必须定义一个Shape3D对象,在该对象中定义几何体的数据与几何体的颜色、材质、透明度等外观显示特性,该Shape3D对象一般加入在一个TransformGroup类的节点中。

在一个BranchGroup 节点之下,可以包含多个TransformGroup节点。

每个TransformGroup节点可以包含以各种或多种几何体的定义。

Java3DAPI官方教程

Java3DAPI官方教程

Java3DAPI官方教程Java 3D API官方教程开始学习Java3D API第一章、入门本章目标:学习了本章之后,你能:能用一些基本术语解释什么是Java3D能描述出Java3D程序的基本结构。

能识别出Java3D API中的许多类。

能编写出简单的Java3D动画程序。

Java 3D API是一个用于编写显示和交互操作三维图形对象的程序的接口。

Java 3D也是在Java2 Java开发包(JDK)上的标准扩展。

这个API提供了用于创建和操纵3D图形的高端构成方法以及渲染该图形的一些数据结构。

Java3D 提供了创建图片、可视化、动画以及3D 交互图形应用程序的函数。

1.1 什么是Java 3D API?Javae 3D API是作为复杂三维图形和声音渲染系统的接口的一系列层次的JAVA类的统称。

程序员可以用Java3D开发创建和操纵3D图形对象的高端应用。

这个图形对象处于一个被渲染了的虚拟世界(Virtual Universe)中。

这个API就是用设计来用于灵活方便地创建精确的各种大小的虚拟环境,可以大到大空物体,小到比原子还小。

除了这些功能之外,API的使用也很直接,API能自动处理渲染的细节,由于利用了Java线程机制的优势,所以Java3D的渲染器的工作是并行进行的。

并且渲染器也能自动地优化并提高渲染性能。

一个Java3D程序创建了Java3D对象的实际,并将其置之于场景图数据结构中。

在这个场景图中,所有3D对象用完全指定了虚拟世界内容和其如何被渲染的树形结构存储,Java3D程序能写成能独立运行的应用程序,或者写成能嵌入在浏览器中运行的Applets,或者二者兼备。

1.2 Java 3D API每一个Java3D程序至少部分地集成了来自Java类层次中的对象,这些对象的集合称做虚拟世界(virtual universe),这就是将要被渲染的对象。

此API在javax.media.j3d包中定义了超过100多个类,这些类我们平常称做Java3D核心类。

JAVA教程

JAVA教程

Java3D探奇2007年12月07日星期五00:02本教程是为没有任何3D编程经验的Java程序员而编写的。

我们将从一些基本的3D概念入手,探索如何构建一副场景图—用于描述我们想要渲染的场景的基本对象。

然后,我们将接触Java3D的一些更强大的功能。

我们的重点将放在使用一些Java3D实用类来开始您的编程。

预备知识对3D编程没有任何经验的程序员都可以是本教程的读者。

系统需求浏览器:Netscape4.x或更高版本,或者Internet Explorer4.x或更高版本,支持Javas cript。

思想Java3D API的设计是对以前流行的诸如OpenGL和Direct3D的3D图形API的重大革新(以前的API是同3D硬件设计紧密结合的低级过程性API)。

Java3D是一种功能强大的、面向对象的API,它提供了许多超出我们认为作为“3D图形API”所能有的功能。

Java程序员可能会发现Java3D编程环境非常熟悉而且易用。

Java3D做了许多事情来为您管理图形数据,这样就使得您可以把精力集中在其它编程工作上。

使用Java3D,首先要在场景图中设置所有的图形对象(也称为几何对象),场景图是一个层次模型,它包含有关场景中的对象以及如何渲染它们的全部信息。

然后,将该场景图交由Java3D渲染。

您无须为显示数据而编写任何代码―Java3D为您完成了这项工作。

通过使用内置的强大工具,您可以在一个更高的级别上进行编程。

对速度的需要3D程序员十分在意性能,这是有其原因的―他们的应用程序往往对性能非常敏感。

如果旋转的CAD模型没有平滑地旋转,或者3D应用程序用户不能够交互地抓取一个对象并移动它,用户将会立即注意到这一点。

令人欣慰的是,Java3D能够利用图形适配器所提供的任何3D加速性能。

Java 3D最终会在JNI层生成可以由图形卡加速的OpenGL调用。

新工作站通常装有OpenGL加速适配器,因此您的Java3D程序应该可以由硬件加速。

java3D安装教程

java3D安装教程

在Eclipse中运行Java3D的程序此页解释了如何在Eclipse中使用Java3D的库运行程序。

1.下载Java3D的。

访问此网页下载为您的系统Java3D的库。

2.下载用于Windows包含一个安装程序。

我发现最简单的安装在我的Java文件夹,包含在我的情况同一个标准的Java,jdk1.6.0_18下载Java3D的文件和目录。

在运行安装程序:3.启动Eclipse。

你可以创建一个Java3D的代码为您的新项目,或使用一个已经存在的项目。

我将创建一个新的名为3DExamples 项目4.下载HelloUniverse.java和添加项目,从第3步。

HelloUniverse.java有很多语法错误,因为它是指一些Java3D的非标准类。

我们需要告诉到哪里寻找这些类的项目。

5.在Eclipse菜单,选择“项目” - >“属性”6.在弹出窗口中选择 Java Build Path,然后单击 Add Library ...“按钮。

7.在下一个窗口中,选择用户库,点击“下一步”按钮。

8.在下一个窗口中单击“用户库”...“按钮9.在未来的点击新建...“按钮。

10.在窗口,弹出新的库名称。

使用名称Java3DLib。

然后单击“确定”按钮。

11.选择您刚才创建的库,然后单击“添加JAR文件...”按钮。

12.在弹出浏览文件夹,你在第2步安装Java3D的文件选择。

(Java3D的jar文件的路径在我的机器是用Java3D - > 1.5.2 - >库- >分机- >)选择所有三个jar文件(j3dcore.jar,j3dutils.jar,和vecmath.jar的)。

所有三个jar文件,选择后单击“打开”按钮13.后加入的罐子在首选项窗口点击的好吧按钮。

14.在弹出的窗口中单击 Finish按钮。

15.在构建路径“窗口中选择回到您刚才添加的Java3DLib,展开它,并选择本机库的位置属性。

第13章 VRML(虚拟现实建模语音)其他虚拟现实开发技术和软件介绍

第13章 VRML(虚拟现实建模语音)其他虚拟现实开发技术和软件介绍

三 与其他虚拟现实开发语言的比较
Java 3D
Java 3D是在OpenGL三维图形库的基础上发展而来的,Java3D API (Java Three-Dimension Application Programming Interface)是用于实现基于 Web的三维图形显示和应用程序开发的Java编程接口,它具备了从网络设备 编程到三维几何图形编程等各方面的功能。 Java3D继承了OpenGL的层次结构,并兼有Java语言结构的较完美形式, 使其具有以下一些的特点:(1)Java 3D结合了高层次的场景图(Scene Graph)模型,使得程序员不必花费时间和精力来设计具体的几何形体和编写 描绘代码,只需集中精力于场景图中各个对象和组成元素。(2)Java3D继 承了Java的平台无关性,采用了几何形体的压缩技术,加快了三维模型的网 络传输速度,适合于开发基于Intranet/Internet的应用。(3)它支持多 种文件输入格式,能实现对3D图示数据的高性能处理,实现对于挑选、删除 等操作的优化处理。(4)Java3D把OpenGL和DirectX这些底层技术包装在 Java接口中,这种全新的设计使3D技术变得不再繁琐并且可以加入到J2SE、 J2EE的整套架构,这些特性保证了Java3D技术强大的扩展性。
最适合应 用领域 网上三维 显示 三维设计 软件 三维游戏 网上虚拟 现实
三 与其他虚拟现实开发语言的比较
DIRECT3D DIRECT3D是Microsoft公司推出的三维图形编程API,是DirectX的成 员之一。顾名思义,他是DirectX中负责实现3D图形绘制的部分,它主 要应用于三维游戏的编程。众多优秀的三维游戏都是由这个接口实现 。与OpenGL一样,Direct3D的实现主要使用C++语言。

Java 3d 教程

Java 3d 教程
At time of writing, the newest version of Java (6.3) is at /javase/downloads/index.jsp. The current version of the Java 3D extension (1.5.1) is at https:///#Downloads Netscape and Internet Explorer both require you to download plug-ins if you want to use up-to-date versions of Java and Java3D in applets, the plug-in can be found at /products/plugin/.
The Java 3D class library provides a simpler interface than most other graphics libraries, but has enough capabilities to produce good games and animation. Java 3D builds on existing technology such as DirectX and OpenGL so the programs do not run as slowly as you might expect. Also, Java 3D can incorporate objects created by 3D modeling packages like TrueSpace and VRML models.
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1

一个简单的Java 3D源代码

一个简单的Java 3D源代码

这段源代码实现了在一个窗体中显示一个场景;以一个棋盘格做的地面,在地面上浮着一个蓝色的球体,在场景中有一个环境光和一个直射光,实现了用鼠标全角度的观察场景的功能。

从某种意义上来说这的确实现了一部3D游戏最原始的框架。

代码是照着《Killer Game Programming in Java》一书中关于3D游戏制作的那部分写的,由于此书是英文版的据说在国内也买不到中文翻译版的,看得很费力,本人英文不好。

只能慢慢的研究书中的源代码。

下面说明下源代码的文件功能GameMain.java - 程序的入口。

ScreenManager.Java - 实现一个很简单的窗体类从JFrame派生,目前只返回一个窗体,以后可能实现最复杂的功能。

WrapCheckers3D.Java - 实现一个简单的3D场景类,能实现一个简单的鼠标操作。

CheckerFloor.Java - 实现一个国际象棋般的棋盘格做来场景中的地面。

ColouredTile.Java - 派生自Shape3D类,能实现一个正方体平面,用来为CheckerFl oor类实现棋盘格GameMain.Java1.import java.awt.event.WindowAdapter;2.import java.awt.event.WindowEvent;3.4.import javax.swing.JFrame;5.import javax.swing.JOptionPane;6.7.8.public class GameMain {9. private static int scrWidth = 800;ScreenManager.Javaview plaincopy to clipboardprint?.........10........20........30........40........50........60........70........80.. (9)0........100.......110.......120.......130.......140. (150)1.import java.awt.Dimension;2.import java.awt.DisplayMode;3.import java.awt.GraphicsDevice;4.import java.awt.GraphicsEnvironment;5.import java.awt.Insets;6.import java.awt.Toolkit;7.import java.awt.event.WindowAdapter;8.import java.awt.event.WindowEvent;9.10.import javax.swing.JFrame;11.import javax.swing.JOptionPane;12.13.14.public class ScreenManager {15.16. private GraphicsDevice device;17. private JFrame frame;18. private String title;19. private boolean isResizable;20. private boolean isWindowMode;21. private int scrWidth;22. private int scrHeight;23. private int scrBitdepth;24.25. public ScreenManager(int scrWidth,int scrHeight,int scrBitdepth,String title)26. {27. this.scrWidth = scrWidth;28. this.scrHeight = scrHeight;29. this.scrBitdepth = scrBitdepth;30. this.title = title;31. }32.33. public void setWindowMode()34. {35. frame = new JFrame();36. frame.setResizable(false);//禁止窗体改变大小37. frame.setPreferredSize(new Dimension(scrWidth,scrHeight));38. frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//响应窗体的关闭事件,但不关闭窗体39. frame.setVisible(true);40.// 侦听窗体事件并捕获窗体关闭中的事件,在用户确认后退出程序41. frame.addWindowListener(new WindowAdapter(){42. public void windowClosing(WindowEvent e)43. {44. int res = JOptionPane.showConfirmDialog(null, "是否退出!","退出",JOptionPane.YES_NO_OPTION);45. if(res == JOptionPane.YES_OPTION)46. closeFrame();47. }48. });49. this.setFrametoCenter();50. }51.52. public void setFullWindowMode()53. {54. if(frame != null)55. {56. device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();57. DisplayMode displayMode = device.getDisplayMode();58. frame.setPreferredSize(new Dimension(displayMode.getWidth(),displayMode.getHeight()));59. }60. }61.62. public int getWidth()63. {64. return scrWidth;65. }66.67. public int getHeight()68. {69. return scrHeight;70. }71.72. public JFrame getFrame()73. {74. return frame;75. }76.77.// 将窗体在显示屏幕内居中显示78. public void setFrametoCenter()79. {80. if(device!=null)81. return;82. Insets inset = frame.getInsets();83. int scrx=0;84. int scry=0;85. Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();86. if(scrSize.width > scrWidth)87. scrx = (scrSize.width-scrWidth)/2;88. if(scrSize.height > scrHeight)89. scry = (scrSize.height-scrHeight)/2;90. frame.setBounds(scrx-inset.left, scry-inset.top, scrWidth+inset.right+inset.left, scrHeight+inset.bottom+inset.top);91. }92.93.// 关闭窗体事件94. public void closeFrame()95. {96. frame.dispose();97. System.exit(0);98. }99.}1.import java.awt.BorderLayout;2.import java.awt.Color;3.import java.awt.GraphicsConfiguration;4.5.import javax.media.j3d.AmbientLight;6.import javax.media.j3d.Appearance;7.import javax.media.j3d.Background;8.import javax.media.j3d.BoundingSphere;9.import javax.media.j3d.BranchGroup;10.import javax.media.j3d.Canvas3D;11.import javax.media.j3d.DirectionalLight;12.import javax.media.j3d.Material;13.import javax.media.j3d.Transform3D;14.import javax.media.j3d.TransformGroup;15.import javax.swing.JPanel;16.import javax.vecmath.Color3f;17.import javax.vecmath.Point3d;18.import javax.vecmath.Vector3d;19.import javax.vecmath.Vector3f;20.21.import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;22.import com.sun.j3d.utils.geometry.Sphere;23.import com.sun.j3d.utils.universe.SimpleUniverse;24.import com.sun.j3d.utils.universe.ViewingPlatform;25.26.27.public class WrapCheckers3D extends JPanel {28.29. private BranchGroup sceneBg;30. private SimpleUniverse su;31. private BoundingSphere bounds;32. private static final float BOUNDSIZE=100.0f;33.34. public WrapCheckers3D(int width,int height)35. {36. this.setLayout(new BorderLayout());37. GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();38. Canvas3D canvas = new Canvas3D(config);39. this.add("Center",canvas);40. canvas.setBounds(0, 0, width, height);41.42. su = new SimpleUniverse(canvas);43. createSceneGroup();44. initUserPosition();45. orbitControls(canvas);46. su.addBranchGraph(sceneBg);47. }48.49. public void createSceneGroup()50. {51. sceneBg = new BranchGroup();52. bounds = new BoundingSphere(new Point3d(0,0,0),BOUNDSIZE);53. lightScene();54. addBackground();55. sceneBg.addChild(new CheckerFloor().getBG());56. floatingSphere();57. pile();58. }59.60. private void lightScene()61. {62. Color3f white = new Color3f(1.0f,1.0f,1.0f);63. AmbientLight ambientLightNode = new AmbientLight(white);64. ambientLightNode.setInfluencingBounds(bounds);65. sceneBg.addChild(ambientLightNode);66.67. Vector3f lightDirection = new Vector3f(-1.0f,-1.0f,-1.0f);68. DirectionalLight light = new DirectionalLight(white,lightDirection);69. light.setInfluencingBounds(bounds);70. sceneBg.addChild(light);71. }72.73. private void addBackground()74. {75. Background back = new Background();76. back.setApplicationBounds(bounds);77. back.setColor(0.17f, 0.62f, 0.92f);78. sceneBg.addChild(back);79. }80.81. private void floatingSphere()82. {83. Color3f black = new Color3f(0.0f,0.0f,0.0f);84. Color3f blue = new Color3f(0.3f,0.3f,0.8f);85. Color3f specular = new Color3f(0.9f,0.9f,0.9f);86.87. Material blueMat = new Material(blue,black,blue,specular,25.0f);88. blueMat.setLightingEnable(true);89.90. Appearance blueApp = new Appearance();91. blueApp.setMaterial(blueMat);92.93. Transform3D t3d = new Transform3D();94. t3d.set(new Vector3f(0,4,0));95. TransformGroup tg = new TransformGroup(t3d);96. tg.addChild(new Sphere(2.0f,blueApp));97. sceneBg.addChild(tg);98. }99.100. private void initUserPosition()101. {102. ViewingPlatform vp = su.getViewingPlatform();103. TransformGroup steerTG = vp.getViewPlatformTransform(); 104.105. Transform3D t3d = new Transform3D();106. steerTG.getTransform(t3d);107.108. t3d.lookAt(new Point3d(0,5,20), new Point3d(0,0,0), new Vecto r3d(0,1,0));109. t3d.invert();110.111. steerTG.setTransform(t3d);112.113. }114.115. private void orbitControls(Canvas3D canvas)116. {117. OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);118. orbit.setSchedulingBounds(bounds);119. ViewingPlatform vp = su.getViewingPlatform( );120. vp.setViewPlatformBehavior(orbit);121. }122.}1.import java.awt.Font;2.import java.util.ArrayList;3.4.import javax.media.j3d.BranchGroup;5.import javax.media.j3d.Transform3D;6.import javax.media.j3d.TransformGroup;7.import javax.vecmath.Color3f;8.import javax.vecmath.Point3d;9.import javax.vecmath.Vector3f;10.11.import com.sun.j3d.utils.geometry.Text2D;12.13.public class CheckerFloor {14.15. private BranchGroup floor;16.17. public CheckerFloor() {18. floor = new BranchGroup();19. }20.21. public BranchGroup getBG() {22. Color3f blue = new Color3f(0, 0, 1);23. Color3f green = new Color3f(0, 1, 0);24.25. boolean isBlue = true;26. for (int j = -10; j < 9; j++) {27. for (int i = -10; i < 9; i++) {28. Point3d t1 = new Point3d(i, 0, j);29. Point3d t2 = new Point3d(i + 1, 0, j);30. Point3d t3 = new Point3d(i + 1, 0, j + 1);31. Point3d t4 = new Point3d(i, 0, j + 1);32. ArrayList<Point3d> tileCoord = new ArrayList<Point3d>();33. tileCoord.add(t1);34. tileCoord.add(t2);35. tileCoord.add(t3);36. tileCoord.add(t4);37. if (isBlue)38. floor.addChild(new ColouredTile(tileCoord, blue));39. else40. floor.addChild(new ColouredTile(tileCoord, green));41. isBlue = !isBlue;42. floor.addChild(makeText(new Vector3f(i,0,j),"("+i+","+j+")"));43. }44. }45. return floor;46. }1.import java.util.ArrayList;2.3.import javax.media.j3d.Appearance;4.import javax.media.j3d.BranchGroup;5.import javax.media.j3d.GeometryArray;6.import javax.media.j3d.PolygonAttributes;7.import javax.media.j3d.QuadArray;8.import javax.media.j3d.Shape3D;9.import javax.vecmath.Color3f;10.import javax.vecmath.Point3d;11.import javax.vecmath.Point3f;12.13.14.public class ColouredTile extends Shape3D {15.16. private ArrayList<Point3d> coord;17. private Color3f color;18. private QuadArray plane;19.20. public ColouredTile(ArrayList<Point3d> coord,Color3f color)21. {22. this.coord = coord;23. this.color = color;24. plane = new QuadArray(coord.size(),GeometryArray.COORDINATES | GeometryArray.COLOR_3);25. createGeometry();26. createAppearance();27. }28.29. public void createGeometry()30. {31. int numPoints = coord.size();32. Point3d[] points = new Point3d[numPoints];。

Java3D

Java3D
二. 如何编写 JAVA3D 源程序 用文本编辑工具编辑源程序,和其它 JAVA 程序一样,程序后缀为 JAVA。
三. 如何运行 JAVA3D 源程序 用 JAVAC 编译源程序,生成 class 文件。根据文件的类型,选择用 JAVA 或 APPLETVIEWER 运行程序。JAVA3D 程序可以为 APPLICATION 程序,也可以为 APPLET 程序,因而 JAVA3D 程序也可以摆放在网页上,当然这时候我们必须在浏览器上 做一些设置工作(以后再介绍)。
在运行 applet 程序时,我们需要编写一个 HTML 文件: 先用 javac 将 JAVA3D 源程序编译成 class 文件,再用 appletviewer 运行 HTML 文件。虽然程序是 applet 程序,但我们也可以将其变成 application 程序,这 时我们只需将程序头尾的四个注释行的注释符号去掉即可,这时我们可以用 java 来运行它: java SimpleCone
二。OPENGL、VRML、DIRECT3D、JAVA3D 的比较 由于 OPENGL 的跨平台特性,许多人利用 OPENGL 编写三维应用程序,不过对于一 个非计算专业的人员来说,利用 OPENGL 编写出复杂的三维应用程序是比较困难 的,且不说 C(C++)语言的掌握需要花费大量时间精力,当我们需要处理复杂 问题的时候,我们不得不自己完成大量非常繁琐的工作。当然,对于编程高手来 说,OPENGL 是他们发挥才能的非常好的工具。
PDF 文件使用 "pdfFactory Pro" 试用版本创建
Virtual Universe | |----------------------------------| || Locale Locale | | ----------------+----------------|||| |||| BG BG BG BG (BG--BranchGroup) |||| | | | | (S---Shape) S TG TG TG (TG--| ||||| A G S S View Platform || | | (A---Appearance) ----+---- ----+---- (G---Geometry) |||| |||| AGAG

Java实现的3D计算机图形类库与引擎

Java实现的3D计算机图形类库与引擎

跨平台三维图形开发工具包Java 3D官方主页:https:///Java 3D严格遵循“建模-绘制”泛型。

场景图(scene graph)的抽象模型被用来组织和维护虚拟场景中的可是对象及其行为。

场景图包含了虚拟图形世界的全部信息,Jav a 3D绘制引擎会对场景图进行自动绘制。

Java 3D is a scene graph-based 3D application programming interface (API) for the Java platform. It runs on top of either OpenGL or Direct3D. Since version 1.2, Java 3D is developed under the Java Community Proces s. JSR 926 specifies Java 3D 1.4; as of 2007, the current version is 1.5.1 (released in June 2007).Compared to other solutions, Java 3D is not only a wrapper around th ese graphics APIs, but an interface that encapsulates the graphics program ming using a real, object-oriented concept. Here a scene is constructed usi ng a scene graph that is a representation of the objects that have to be s hown. This scene graph is structured as a tree containing several elements that are necessary to display the objects. Additionally, Java 3D offers ext ensive spatialized sound support.Java 3D and its documentation are available for download separately. They are not part of the JDK 6. However,future versions of the JDK are e xpected to include an API package for Java 3D.Java 3D开源项目包含一组3D图形API,它提供的一组面向对象接口支持简单、高级编程模型,你可以用于构建、展示和控制3D对象的行为与可视化环境。

如何搭建java3d环境 (图)

如何搭建java3d环境 (图)

Netbeans下如何搭建java3D环境(图)摘要在Netbeans IDE 工具下搭建java3D的开发环境主要有三步:一是安装java3d需要的包,二是在netbeans导入java3d需要的包,三是运行java3d的测试程序;最终Netbeans能够运行显示出“Java ”的3D效果图像,如下图1所示:图1 Java 的3D效果图像1.搭建步骤:1.1下载java3d-1_5_1-windows-i586.exe安装包并安装到电脑;1)、下载地址:/file/c2k157vw#java3d-1-5-1-windows-i586.exe。

2)、安装java3d-1_5_1-windows-i586.exe,默认路径为:C:\ProgramFiles\Java\Java3D\1.5.1。

图2 java3d-1_5_1-windows-i586.exe默认安装路径1.2 新建工程,导入java3d的3个包j3dcore.jar、j3dutils.jar、vecmath.jar 1)、选择文件>新建项目>Java>Java 应用程序,如下图3填写项目名称“Java3D”,点击完成。

图3 新建Java 3 工程2)、导入java3d 的3个文件操作:如图4鼠标右击库>添加JAR/文件夹,如图5添加3个jar文件包图4图53)、如图6、图7,鼠标右击“java3d>新建>Java类”填写“Java3dTest”新建java 测试类Java3dTest.java,并将Java3dTest类中的源码全部替换为以下源码:图 6图7package java3d;/**** @author Administrator*/import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.media.j3d.*;import javax.vecmath.*;import com.sun.j3d.utils.universe.*;public class Java3dTest {public static void main(String[] args) {Java3dTest t = new Java3dTest();t.setUp();}public void setUp() {JFrame jf = new JFrame("Welcome");// kill the window on closejf.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent winEvent) { System.exit(0);}});JPanel panel = new JPanel();panel.setLayout(new GridLayout(1, 1, 2, 2));GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();Canvas3D canvas3D = new Canvas3D(config);canvas3D.setSize(360, 160);SimpleUniverse universe = new SimpleUniverse(canvas3D);BranchGroup group = new BranchGroup();addObjects(group);addLights(group);universe.getViewingPlatform().setNominalViewingTransform();universe.addBranchGraph(group);panel.add(canvas3D);jf.getContentPane().add(panel, BorderLayout.CENTER);jf.pack();jf.setVisible(true);}public void addLights(BranchGroup group) {BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),1000.0);Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f);Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);light1.setInfluencingBounds(bounds);group.addChild(light1);// Set up the ambient lightColor3f ambientColor = new Color3f(.1f, .1f, .1f);AmbientLight ambientLightNode = newAmbientLight(ambientColor);ambientLightNode.setInfluencingBounds(bounds);group.addChild(ambientLightNode);}private void addObjects(BranchGroup group) {Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 2), new FontExtrusion());Text3D text = new Text3D(f3d, new String(""), new Point3f(-3.5f, -.5f, -4.5f));text.setString("");Color3f white = new Color3f(1.0f, 1.0f, 1.0f);Color3f blue = new Color3f(.2f, 0.2f, 0.6f);Appearance a = new Appearance();Material m = new Material(blue, blue, blue, white, 80.0f);m.setLightingEnable(true);a.setMaterial(m);Shape3D sh = new Shape3D();sh.setGeometry(text);sh.setAppearance(a);TransformGroup tg = new TransformGroup();Transform3D t3d = new Transform3D();Transform3D tDown = new Transform3D();Transform3D rot = new Transform3D();Vector3f v3f = new Vector3f(-1.6f, -1.35f, -6.5f);t3d.setTranslation(v3f);rot.rotX(Math.PI / 5);t3d.mul(rot);v3f = new Vector3f(0, -1.4f, 0f);tDown.setTranslation(v3f);t3d.mul(tDown);tg.setTransform(t3d);tg.addChild(sh);group.addChild(tg);}}4)运行Java3dTest.java 文件,将会显示如下错误(注意以下黄色背景的文字,说在java的library路径中缺少了j3dcore-d3d 文件):2012-6-10 21:42:31 javax.media.j3d.NativePipeline getSupportedOglVendor严重: ng.UnsatisfiedLinkError: no j3dcore-ogl-chk in java.library.path Exception in thread "main" ng.UnsatisfiedLinkError: no j3dcore-d3d in java.library.pathat ng.ClassLoader.loadLibrary(ClassLoader.java:1734)at ng.Runtime.loadLibrary0(Runtime.java:823)at ng.System.loadLibrary(System.java:1028)at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:189)at java.security.AccessController.doPrivileged(Native Method)at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:180)at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:137)at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:948)at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:280)at java3d.Java3dTest.setUp(Java3dTest.java:36)at java3d.Java3dTest.main(Java3dTest.java:22)Java Result: 1成功生成(总时间:1 秒)解决方案:复制java3d-1_5_1-windows-i586.exe安装路径下的4个文件j3dcore-d3d.dll、j3dcore-ogl.dll、j3dcore-ogl-cg.dll和j3dcore-ogl-chk.dll到Netbeans默认的安装路径下,再运行程序即可,如图8图9、图10、图11红色圈的1,2,3,4步骤:图8图9 Netbeans默认的JDK路径图10 复制4个dll文件图11 把4个文件粘贴到Netbeans默认JDK路径下1.3 运行例子,测试java3D环境图12 运行文件解决方案参考:/blog/1153584小结:在Netbeans搭建java3D的前提是:可以在Netbeans运行一般的程序,此配置关键在于在Netbeans中添加3个包j3dcore.jar、j3dutils.jar、vecmath.jar 和在Netbeans下使用的默认JDK路径下添加4个库文件j3dcore-d3d.dll、j3dcore-ogl.dll、j3dcore-ogl-cg.dll和j3dcore-ogl-chk.dll,而这一共7个文件包在安装java3d-1_5_1-windows-i586.exe即可获得。

Java实现的3D计算机图形类库与引擎

Java实现的3D计算机图形类库与引擎

跨平台三维图形开发工具包Java 3D官方主页:https:///Java 3D严格遵循“建模-绘制”泛型。

场景图(scene graph)的抽象模型被用来组织和维护虚拟场景中的可是对象及其行为。

场景图包含了虚拟图形世界的全部信息,Jav a 3D绘制引擎会对场景图进行自动绘制。

Java 3D is a scene graph-based 3D application programming interface (API) for the Java platform. It runs on top of either OpenGL or Direct3D. Since version 1.2, Java 3D is developed under the Java Community Proces s. JSR 926 specifies Java 3D 1.4; as of 2007, the current version is 1.5.1 (released in June 2007).Compared to other solutions, Java 3D is not only a wrapper around th ese graphics APIs, but an interface that encapsulates the graphics program ming using a real, object-oriented concept. Here a scene is constructed usi ng a scene graph that is a representation of the objects that have to be s hown. This scene graph is structured as a tree containing several elements that are necessary to display the objects. Additionally, Java 3D offers ext ensive spatialized sound support.Java 3D and its documentation are available for download separately. They are not part of the JDK 6. However,future versions of the JDK are e xpected to include an API package for Java 3D.Java 3D开源项目包含一组3D图形API,它提供的一组面向对象接口支持简单、高级编程模型,你可以用于构建、展示和控制3D对象的行为与可视化环境。

JAVA 3D 官方教程_CH_5

JAVA 3D 官方教程_CH_5

Getting Started with the Java 3D™ APIChapter 5AnimationDennis J BouvierK ComputingModule2: Interaction and Animation Chapter 5. Animation © 1999 Sun Microsystems, Inc.2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.AAll Rights Reserved.The information contained in this document is subject to change without notice.SUN MICROSYSTEMS PROVIDES THIS MATERIAL "AS IS" AND MAKES NO WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SUN MICROSYSTEMS SHALL NOT BE LIABLE FOR ERRORS CONTAINED HEREIN OR FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS IN CONNECTION WITH THE FURNISHING, PERFORMANCE OR USE OFTHIS MATERIAL, WHETHER BASED ON WARRANTY, CONTRACT, OR OTHER LEGAL THEORY).THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY MADE TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.Some states do not allow the exclusion of implied warranties or the limitations or exclusion of liability for incidental or consequential damages, so the above limitations and exclusion may not apply to you. This warranty gives you specific legal rights, and you also may have other rights which vary from state to state.Permission to use, copy, modify, and distribute this documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies.This documentation was prepared for Sun Microsystems by K Computing (530 Showers Drive, Suite 7-225, Mountain View, CA 94040, 770-982-7881, ). For further information about course development or course delivery, please contact either Sun Microsystems or K Computing.Java, JavaScript, Java 3D, HotJava, Sun, Sun Microsystems, and the Sun logo are trademarks or registered trademarks of Sun Microsystems, Inc. All other product names mentioned herein are the trademarks of their respective owners.Module 2: Interaction and AnimationTable of ContentsChapter 5 Animation.............................................................................................................................................5-1 5.1Animations................................................................................................................................5-1 5.2Interpolators and Alpha Object Provide Time-based Animations.................................................5-25.2.1Alpha.................................................................................................................................5-25.2.2Using Interpolator and Alpha Objects.................................................................................5-45.2.3Example Using Alpha and RotationInterpolator..................................................................5-45.2.4Alpha API.........................................................................................................................5-85.2.5Interpolator Behavior Classes...........................................................................................5-105.2.6Core Interpolator API......................................................................................................5-125.2.7Path Interpolator Classes..................................................................................................5-20 5.3Billboard Class........................................................................................................................5-245.3.1Using a Billboard Object..................................................................................................5-245.3.2Example Billboard Program.............................................................................................5-255.3.3Billboard API..................................................................................................................5-26 5.4Level of Detail (LOD) Animations...........................................................................................5-285.4.1Using a DistanceLOD Object...........................................................................................5-295.4.2Example Usage of DistanceLOD......................................................................................5-295.4.3DistanceLOD API............................................................................................................5-315.4.4LOD (Level of Detail) API...............................................................................................5-32 5.5Morph.....................................................................................................................................5-335.5.1Using a Morph Object......................................................................................................5-345.5.2Example Morph Application: Walking..............................................................................5-345.5.3Morph API......................................................................................................................5-37 5.6Chapter Summary....................................................................................................................5-38 5.7Self Test..................................................................................................................................5-38List of FiguresFigure 5-1 Some Classes used in Java 3D Animations............................................................................5-2 Figure 5-2 Phases of the Alpha Waveform.............................................................................................5-3 Figure 5-3 Some Basic Waveforms Easily Made with an Alpha Object..................................................5-4 Figure 5-4 Recipe for Using an Interpolator and Alpha Objects for Animation........................................5-4 Figure 5-5 Scene Rendered at 4:30 by the ClockApp Example Program.................................................5-6 Figure 5-6 Smoothing of the Waveform Produced by Alpha...................................................................5-7 Figure 5-7 Four Scenes Rendered by AlphaApp Showing the Effect of IncreasingAlphaRampDuration..5-7 Figure 5-8 Java 3D Core and Utility (shaded boxes) Interpolator Classes Hierarchy.............................5-10 Figure 5-9 Two Scenes from InterpolatorApp Showing Various Interpolators.......................................5-11 Figure 5-10 Partial Scene Graph Diagram of a ColorInterpolator Object and its Target Material NodeComponent Object...............................................................................................................5-13 Figure 5-11The Relationship Between Knots and Alpha Value for a 2D Position Example...................5-20 Figure 5-12 Recipe for Using a Path Interpolator Object......................................................................5-21 Figure 5-13A Scene Rendered by RotPosPathApp Showing the Interpolation of the Rotation and Position of the Color Cube. The Red Dots Show the Knots Positions of the Example Application..............5-22 Figure 5-14 Recipe for Using a Billboard Object to Provide Animation................................................5-24 Figure 5-15 Diagram of Scene Graph Using a Billboard Object as Created in Code Fragment 5-3........5-26 Figure 5-16 Image of BillboardApp with all 2D 'Trees' Facing the Viewer............................................5-26 Figure 5-17 Recipe for Using a DistanceLOD Object to Provide Animation.........................................5-29 Figure 5-18 Partial Scene Graph Diagram for DistanceLODApp Example Program.............................5-30 Figure 5-19 Two Scenes Rendered from DistanceLODApp..................................................................5-31 Figure 5-20 Recipe for Using a Morph Object.....................................................................................5-34 Figure 5-21 Key Frame Images from MorphApp with the Trace of One Vertex....................................5-36 Figure 5-22 A Scene Rendered from Morph3App Showing the Animations of Three Alternative Behavior Classes (not all are good).............................................................................................................5-37 List of Code FragmentsCode Fragment 5-1 Using a RotationInterpolator and Alpha to Spin a Clock (from ClockApp)...............5-5 Code Fragment 5-2 An Excerpt from the CreateSceneGraph Method of RotPosPathApp.java...............5-21 Code Fragment 5-3 Except From the createSceneGraph Method of BillboardApp.java.........................5-26 Code Fragment 5-4 Excerpt from createSceneGraph Method in DistanceLODApp...............................5-30 Code Fragment 5-5 MorphBehavior Class from MorphApp.................................................................5-35 Code Fragment 5-6 An Excerpt from the createSceneGraph Method of MorphApp..............................5-36 List of TablesTable 5-1 Summary of Core Interpolator Classes.................................................................................5-11List of Reference BlocksAlpha Constructor Summary.................................................................................................................5-8 Alpha Method Summary (partial list)....................................................................................................5-9 Interpolator Method Summary (partial list)..........................................................................................5-12 ColorInterpolator Constructor Summary..............................................................................................5-13 ColorInterpolator Method Summary (partial list).................................................................................5-14 PositionInterpolator Constructor Summary..........................................................................................5-14 PositionInterpolator Method Summary (partial list)..............................................................................5-15 RotationInterpolator Constructor Summary.........................................................................................5-15 RotationInterpolator Method Summary (partial list).............................................................................5-16 ScaleInterpolator Constructor Summary..............................................................................................5-16 ScaleInterpolator Method Summary.....................................................................................................5-17 SwitchValueInterpolator Constructor Summary...................................................................................5-17 SwitchValueInterpolator Method Summary (partial list)......................................................................5-18 Switch Constructor Summary..............................................................................................................5-18 Switch Method Summary (partial list).................................................................................................5-19 Switch Capability Summary................................................................................................................5-19 TransparencyInterpolator Constructor Summary..................................................................................5-19 TransparencyInterpolator Method Summary........................................................................................5-20 PathInterpolator..................................................................................................................................5-23 PathInterpolator Method Summary (partial list)...................................................................................5-23 RotPosPathInterpolator Constructor Summary....................................................................................5-23 RotPosPathInterpolator Method Summary...........................................................................................5-24 Billboard Constructor Summary..........................................................................................................5-27 Billboard Method Summary (partial list).............................................................................................5-28 DistanceLOD Constructor Summary...................................................................................................5-32 DistanceLOD Method Summary..........................................................................................................5-32 LOD Constructor Summary................................................................................................................5-32 LOD Method Summary.......................................................................................................................5-33 Morph Constructor Summary..............................................................................................................5-37 Morph Method Summary (partial list).................................................................................................5-38 Morph Capabilities Summary..............................................................................................................5-38 Preface to Chapter 5This document is one part of a tutorial on using the Java 3D API. You should be familiar with Java 3D API basics to fully appreciate the material presented in this Chapter. Additional chapters and the full preface to this material are presented in the Module 0 document available at:/products/javamedia/3d/collateralCover ImageThe cover image represents the key frame animation possible using a Morph object and the appropriate behavior. Section 5.5 presents an example program utilizing a Morph object, an Alpha object, and a Behavior object to animate a stick man.Module 2: Interaction and Animation5AnimationChapter ObjectivesAfter reading this chapter, you’ll be able to:• use Alpha and Interpolator classes to add simple animations• use LOD and Billboard to provide computation saving animations• use Morph objects with custom behaviors to provide key frame animationsC ertain visual objects change independent of user actions. For example, a clock in the virtual worldshould keep on ticking without user interaction. The clock is an example of animation. For the purposes of this tutorial, animation is defined as changes in the virtual universe that occur without direct user action 1.By contrast, changes in the virtual universe as a direct result of user actions are defined as interactions.Chapter 4 presents interaction classes and programs. This chapter is about animations.5.1 AnimationsAs with interaction, animations in Java 3D are implemented using Behavior objects 2. As you might imagine,any custom animation can be created using behavior objects. However, the Java 3D API provides a number of classes useful in creating animations without having to create a new class. It should come as no surprise that these classes are based on the Behavior class.One set of animation classes are known as interpolators. An Interpolator object, together with an Alpha object, manipulates some parameter of a scene graph object to create a time-based animation. The Alpha object provides the timing. Interpolators and Alpha objects are explained in Section 5.2.1 The distinction between animation and interaction made in this tutorial is fairly fine (direct is the key word here).Chapter 4 provides an example to help clarify this distinction (see "Animation versus Interaction" on page 4-3).2 Chapter 4 presents the Behavior class in detail and the application of Behaviors, in general. The material presented in Section 4.2 is a prerequisite for this chapter.C H A P T E RAnother set of animation classes animates visual objects in response to view changes. This set of classes includes the billboard and Level of Detail (LOD) behaviors which are driven not by the passage of time, but on the position or orientation of the view. Classes for both of these behaviors are provided in the Java 3D core and presented in Sections 5.3 and 5.4, respectively. Figure 5-1 shows the high level class hierarchy for animation classes.Figure 5-1 Some Classes used in Java 3D AnimationsSection 5.5 presents the Morph class. The Morph class is used in both animation or interpolator applications.5.2Interpolators and Alpha Object Provide Time-based Animations3An Alpha object produces a value between zero and one, inclusive, depending on the time and the parameters of the Alpha object. Interpolators are customized behavior objects that use an Alpha object to provide animations of visual objects. Interpolator actions include changing the location, orientation, size, color, or transparency of a visual object. All interpolator behaviors could be implemented by creating a custom behavior class; however, using an interpolator makes creating these animations much easier. Interpolator classes exist for other actions, including some combinations of these actions. The RotationInterpolator class is used in an example program in Section 5.2.3.5.2.1AlphaAn alpha object produces a value, called the alpha value, between 0.0 and 1.0, inclusive. The alpha value changes over time as specified by the parameters of the alpha object. For specific parameter values at any particular time, there is only one alpha value the alpha object will produce. Plotting the alpha value over time shows the waveform that the alpha object produces.The alpha object waveform has four phases: increasing alpha, alpha at one, decreasing alpha, and alpha at zero. The collection of all four phases is one cycle of the alpha waveform. These four phases correspond with four parameters of the Alpha object. The duration of the four phases is specified by an integer value expressing the duration in milliseconds of time. Figure 5-2 shows the four phases of the alpha waveform. All alpha timings are relative to the start time for the Alpha object. The start time for all Alpha object is taken from the system start time. Consequently, Alpha objects created at different times will have the same 3 Section 1.9 introduced the RotationInterpolator and Alpha classes. You may want to read that section first. Also, the Java 3D API Specification covers Alpha in detail.start time. As a result, all interpolator objects, even those based on different Alpha objects, are synchronized.Alpha objects can have their waveforms begin at different times. The beginning of an alpha object's first waveform cycle may be delayed by either or both of two other parameters: TriggerTime and PhaseDelayDuration. The TriggerTime parameter specifies a time after the StartTime to begin operation of the Alpha object. For a time specified by the PhaseDelayDuration parameter after the TriggerTime, the first cycle of the waveform begins4. Figure 5-2 shows the StartTime, TriggerTime and PhaseDelayDuration.An alpha waveform may cycle once, repeat a specific number of times, or cycle continuously. The number of cycles is specified by the loopCount parameter. When the loopCount is positive, it specifies the number of cycles. A loopCount of –1 specifies continuous looping. When the alpha waveform cycles more than once, only the four cycles repeat. The phase delay is not repeated.An alpha waveform does not always use all four phases. An alpha waveform can be formed from one, two, three, or four phases of the Alpha waveform. Figure 5-3 shows waveforms created using one, two, or three phases of the Alpha waveform. Six of the 15 possible phase combinations are shown in the figure.4 Either startTime or phaseDelayDuration can be used for the same purpose. It is a rare application that requires the use of both parameters.basic waveforms of INCREASING_ENABLEmode basic waveforms of DECREASING_ENABLE mode some other waveformsThe alpha object has two modes which specify a subset of phases are used. The INCREASING_ENABLE mode indicates the increasing alpha and alpha at one phases are used. The DECREASING_ENABLE mode indicates the decreasing alpha and alpha at zero phases are used. A third mode is the combination of these two modes indicating that all four phases are used.The mode specification overrides the duration parameter settings. For example, when the mode is INCREASING_ENABLE, the DecreasingAlphaDuration, DecreasingAlphaRampDuration 5, and AlphaAtZeroDuration parameters are ignored. While any waveform may be specified by setting the duration of unwanted phases to zero, the proper specification of the mode increases the efficiency of the Alpha object.5.2.2 Using Interpolator and Alpha ObjectsThe recipe for using Interpolator and Alpha objects is very similar to using any behavior object. The major difference from the behavior usage recipe (given in Section 4.2.2) is to include the Alpha object. Figure 5-4gives the basic interpolator and alpha object usage recipe 6.1. create the target object with the appropriate capability2. create the Alpha object3. create the Interpolator object referencing the Alpha object and target object4. add scheduling bounds to the Interpolator object5. add Interpolator object to the scene graphFigure 5-4 Recipe for Using an Interpolator and Alpha Objects for Animation.5.2.3 Example Using Alpha and RotationInterpolatorClockApp.java is an example use of the RotationInterpolator class. The scene is of a clock face. The clock is rotated by a RotationInterpolator and Alpha objects once per minute. The complete code for this example is included in the examples/Animation subdirectory of the examples jar 7.5The ramp parameters are discussed in the 'Smoothing of the Alpha Waveform' Section on page 5-66This is the same recipe as given in Section 1.9.4.7 The examples jar contains all of the source code for the examples in The Java 3D Tutorial; available for download from The Java 3D website.In this application, the target object is a TransformGroup object. The ALLOW_TRANSFORM_WRITE capability is required for the TransformGroup target object. Some other interpolators act upon different target objects. For example, the target of a ColorInterpolator object is a Material object. An interpolator object sets the value of its target object based on the alpha value and values that the interpolator object holds.The interpolator defines the end points of the animation. In the case of the RotationInterpolator, the object specifies the start and end angles of rotation. The alpha controls the animation with respect to the timing and how the interpolator will move from one defined point to the other by the specification of the phases of the alpha waveform.This application uses the default RotationInterpolator settings of a start angle of zero and an end angle of 2Π (one complete rotation). The default axis of rotation is the y-axis. The alpha object is set to continuously rotate (loopCount = -1) with a period of one minute (60,000 milliseconds). The combination of these two objects will cause the visual object to rotate one full rotation every minute. The cycle continuously and immediately repeats. The result looks like the clock is continuously spinning, not that the clock spins once and starts over.Code Fragment 5-1 shows the createSceneGraph method from ClockApp.java. This code fragment is annotated with the steps from the recipe of Figure 5-4.1.public BranchGroup createSceneGraph() {2. // Create the root of the branch graph3. BranchGroup objRoot = new BranchGroup();4.5. // create target TransformGroup with Capabilities6.Œ TransformGroup objSpin = new TransformGroup();7. objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);8.9. // create Alpha that continuously rotates with a period of 1 minute10.• Alpha alpha = new Alpha (-1, 60000);11.12. // create interpolator object; by default: full rotation about y-axis13.Ž RotationInterpolator rotInt = new RotationInterpolator(alpha, objSpin);14.• rotInt.setSchedulingBounds(new BoundingSphere());15.16. //assemble scene graph17.• objRoot.addChild(objSpin);18. objSpin.addChild(new Clock());19. objRoot.addChild(rotInt);20.21. // Let Java 3D perform optimizations on this scene graph.22. pile();23.24. return objRoot;25.} // end of CreateSceneGraph method of ClockAppCode Fragment 5-1 Using a RotationInterpolator and Alpha to Spin a Clock (from ClockApp). Figure 5-5 is of a scene rendered by ClockApp at 4:30. The clock face is oblique to the viewer since the entire clock face is rotating.Figure 5-5 Scene Rendered at 4:30 by the ClockApp Example Program.The ClockApp program shows a simple application of the RotationInterpolator. The Clock object, defined in Clock.java available in the examples/Animation subdirectory, shows a more advanced application of the RotationInterpolator object. The clock object in the program uses one RotationInterpolator object to animate each hand of the clock8. However, only one alpha object is used in the clock. It is not necessary to use one Alpha object to coordinate the hands; as noted above, all Alpha objects are synchronized on the program start time. However, sharing one Alpha object saves system memory.Some of the potentially interesting features of the Clock Class are:•the setting of the start and end angles for the hands,•the setting of the axes of rotation, and•the setting of the polygonal culling for the various components of the clock.The source code for the clock is in Clock.java, also available in the examples/Animation subdirectory. The study of the Clock class is left to the reader.Smoothing of the Alpha WaveformIn addition to the duration of the four phases, the programmer can specify a ramp duration for the increasing alpha and decreasing alpha phases. During the ramp duration, the alpha value changes gradually. In the case of motion interpolators, it will appear as though the visual object is accelerating and decelerating in a more natural, real world, manner.The ramp duration value is used for both the beginning and ending portions of the phase and therefore the ramp duration is limited to half of the duration of the phase. Figure 5-6 shows an Alpha waveform with both IncreasingAlphaRampDuration and a DecreasingAlphaRampDuration. Note that the alpha value changes linearly between the two ramp periods.8 Since the clock has front and back facing hands, there are four hands and four RotationInterpolator objects.IncreasingAlphaRampDuration DecreasingAlphaRampDurationIncreasingAlphaDuration DecreasingAlphaDurationFigure 5-6 Smoothing of the Waveform Produced by Alpha9An example program, AlphaApp.java, demonstrates the effect of an IncreasingAlphaRampDuration on an Alpha waveform. In this program there are three car visual objects. The three cars start at the same time from the same x coordinate and travel parallel. The upper car has no ramp (ramp duration = 0), the bottom car has maximum ramp duration (half of the duration of the increasing or decreasing alpha duration), and the middle car has half the maximum ramp duration (one quarter of the duration of the increasing or decreasing alpha duration). Each car takes two seconds to cross the view. In Figure 5-7 shows four scenes rendered from this application.ramptime ~ 0.4s time ~ 0.8s time ~ 1.2s time ~ 1.6s durationnone½fullFigure 5-7 Four Scenes Rendered by AlphaApp Showing the Effect of IncreasingAlphaRampDuration. At about 0.4 seconds after the cars start, the first (left) image of Figure 5-7 was captured showing the positions of the cars. The top car, which will proceed at a constant rate in the absence of a ramp, has traveled the most distance in the first frame. The other two cars begin more slowly and accelerate. At one second (not shown), all the cars have traveled the same distance. The relative positions reverse during the second half of the phase. At the end of the two second phase, each of the cars have traveled the same distance.The source for AlphaApp is available in the examples/Animation subdirectory.9 Justin Couch provided the inspiration and most of the artwork for this figure.。

Java3D API与Java3D编程技术

Java3D API与Java3D编程技术

Java3D API与Java3D编程技术
李志均;傅秀芬
【期刊名称】《现代计算机:下半月版》
【年(卷),期】1999(000)004
【摘要】Java3DAPI是应用于3D图形编程的Java类包,本文具体介绍Java3DAPI中主要类的使用,Java3D编程模式和显示模式,阐明了Java3D编程的思路和方法。

【总页数】5页(P28-31,33)
【作者】李志均;傅秀芬
【作者单位】广东工业大学计算机系;广东工业大学计算机系
【正文语种】中文
【中图分类】TP311
【相关文献】
1.Java3D虚拟现实技术在水下发射模拟中的应用 [J], 洪华军;许统华;吴建波
2.基于Java3D和VRML技术的采摘机械手运动仿真研究 [J], 李珑
3.基于Java3D网络大数据多分辨率采集方法仿真 [J], 李晓明; 应毅; 曾岳
4.利用Java3D技术处理岩心图像 [J],
5.Java3D二次开发在物流设备三维造型中的应用 [J], 韩冰;程国全
因版权原因,仅展示原文概要,查看原文内容请购买。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Getting Started with the Java 3D™ APIChapter 1前言:如对译文中有不同理解的地方请参考原著,水平有限,请见谅,谢谢1.3构造一个场景图一个java 3d虚拟宇宙是由一个由JA V A 3D类的实例构成的场景图构造出来的,场景图由许多对象聚集在一起去定义几何体,声音,光线,位置,方向,虚拟的外观和音频对象对于图的一般定义可以说是包含结点和弧线的数据结构,一个结点就是一个数据元素,弧线代表的就是数据元素之间的关系。

在场景图的一个结点代表JA V A 3D的一个类的实例,弧线代表JA V A 3D实例之间的两种关系。

最普遍的一种关系就是父子关系,一个(group node)组结点可以有很无限多个子类但只能有一个父类,一个(leaf node)叶子结点可以有一个父类但不能有子类,另外一种关系就是引用关系,一个引用关系把一个(NodeComponent)结点组件对象和一个(scene graph Node)场景图结点连系起来,NodeComponent objects定义用来渲染视觉对象的几何体和外观属性一个 java 3D场景图由父子关系的Node对象构成,最后形成一个树形结构。

在一个树结构中,有一个称为根结点的结点,其它结点从根结点一直往下延伸。

一个树的弧线不能形成回路,一个场景图起源于(Local objects)的根结点,(NodeComponents)和(reference arcs)不是场景场的部分。

从一个树的根结点到叶子结点只存在一个路径,因而,从场景图的根到每一个子叶结点只有一条路径。

从场景图的根到指定的叶子结点称为叶子结点的场景图路径。

由于一条场景图路径只通向一个确定的结点,所以在场景图中对于每个结点都只有一条场景图路径。

在一个javad3D场景图中每一个场景图路径都完全载明了它的叶子的状况信息。

状况信息包括位置,方向和视觉对像的大小。

因此,每一个视觉对象的视觉属性都依附于场景图路径。

java3d渲染器充分利用了这个事实而从被认为是最有效的顺序去渲染叶子结点。

java3d程序员不必操心去支配对象的渲染顺序。

一个场景图的图表的表示可以作为JA V A3D的设计工具和文档说明。

我们可以用标准的图形符号来画场景图,如图1.1.java3d程序可以有比这场景图更多的对象。

我们可以用标准的符号来设计一个JA V A3D虚拟宇宙的场景图。

在设计完成之后,场景图的制图可以作为这程序的文档说明。

在程序完成之后,对应的场景图就是程序的一个简明的表示。

图 1.1左手边的每个符号代表在场景图中使用的单一的对象,最前面的两个符号代表确定的类:VirtualUniverse and Locale.接着下来的左边的三个符号代表类Group, Leaf, and NodeComponent的对象。

这三个符号通常也被注释代表这三个类的子类的对象。

在左边的最后一个符号是用来代表其它类的对象。

实线箭头符号代表两个对象之间的父子关系,点箭头是对其它对象的引用。

被引用的对象可以在一个场景图中的不能分支共享。

图1.2表示了一个简单的场景图创建一个不合法的场景图是有可能的。

图1.3表示了一个不合法的场景图例子。

因为它违反了DAG特性。

问题只出在于两个TransformGroup objects同时拥有同一个Shape3D leaf object 作为孩子。

记住一个Leaf object只能有一个老爸。

换句话说,从Locale object到a leaf只能有一条路径(或者说从a leaf到a Locale只有一条路径)你可能想,图1.3表现出来的结构中定义了一个虚拟宇宙的三个视觉对象。

在图1.3右边可以看出,它看起来好像是这个场景图通过重用了visual object(Shape3D)定义了两个视觉对象。

概念上,共享的Shape3D实例的两个父类TransformGroup objects都可以把视觉对象的画面投影到不同的位置。

但是,由于父-子弧线不能形成一棵树,所以它是一个不合法的场景图。

在这个例子中,结果是Shape3D object拥有多个父亲。

树和DAG结构的讨论是符合一般准则的。

然而由于子-父之间的关系,JA V A3D运行时系统会报错。

树结构限制了每一个Shape3D object只限于一个父亲。

图1.3中,‘多父类’的错误会在程序运时时被报告出来。

图1.4中,每一个Shape3D object都只有一个父亲,为这场景图显示了一种修改过的结构。

一个定义了不合法的场景图的java3d程序虽然能编译,但不能被渲染。

当一个定义了不合法的场景图的JA V A3D程序运行时,JA V A3D系统就会检测到这个错误。

当错误被检测到,JA V A3D 系统就会报告出这个异常。

这个程序仍然会运行,结果必然是需要被停止的,然而,没有图画被渲染。

每一个场景图都只有一个VirtualUniverse,这个VirtualUniverse对象拥有多个Locale objects.一个Locale objects在虚拟宇宙在提供了一个引用结点。

我们可以把一个Locale object看作用来确定visual objects在虚拟宇宙中位置的一个地标。

从技术上来说,一个JA V A3D程序拥有多个VirtualUniverse object是可能的,这样就定义了多个虚拟宇宙。

但是在多个虚拟宇宙之间没有内在的方法可以沟通。

进一步地说,一个场景图对象不可能在多个虚拟宇宙中同时存在。

我们强烈建议在一个JA V A3D程序中只定义一个VirtualUniverse的实例。

一个VirtualUniverse对象可以引用多个Locale对象。

大多数JA V A3D程序只有一个Locale 对象。

每一个Locale对象可以作为场景图中多个子图的根结点。

参考图1.2表示的场景图,注意,一个Locale对象产生了两个子图分支。

一个BranchGroup对象是一个子图或分支图的根结点。

有两种不同种类的场景子图:view branch graph 和the content branch graph.内容子图载明了虚拟宇宙中内容:几何体,外观,行为,位置,声音和光线。

观察子图指明了观察的参数例如观察的位置和方向。

两者一起定义了很多渲染器需要去渲染的工作.1.3.1高级JA V A3D API类层次图1.5显示了JA V A3D API前三层的类结构。

VirtualUniverse, Locale, Group和Leaf类出现在这个部分中。

除了VirtualUniverse和Locale对象,一个场景图的其它部分是由SceneGraphObject组成的。

SceneGraphObject差不多是每一个JA V A3D的核心类和实用类的父类。

SceneGraphObject有两个子类:Node和NodeComponent.Node子类提供了场景图的大部分对象。

一个Node对象是一个Group node对象或者是一个Leaf node对象。

Group和Leaf是若干子类的父类。

下面简要看一下Node类和它的两个子类,NodeComponent类,在介绍了这些背景知识之后,然后我们就会解析一下JA V A3D程序的构造Node类Node类是Group和Leaf类的抽象父类。

Node类为它的子类提供了一些重要的通用方法。

在我们讲述了更多的背景知识之后我们就会介绍这些方法的具体用法。

Node类的子类构成了场景图。

Group类Group类是在虚拟宇宙中定义视觉对象的位置和方向的父类。

BranchGroup和TransformGroup是Group类的两个子类。

在场景图的图形表示中。

Group类所代表的符号(圆圈)通常都是用BG来代表BranchGroups,TG代表TransformGroups,例如图1.2Leaf类Leaf类是在虚拟宇宙中定义视觉对象的形状,声音和行为的父类。

其中它的一些子类是Shape3D,Light,Behavior和Sound,这些对象没有孩子,但可以引用NodeComponentsNodeComponent类NodeComponent类是用来定义Shape3D (Leaf)的几何体,外观,贴图和物质属性的父类。

NodeComponents并不是场景图的一部分,但会被场景图引用。

一个NodeComponent可以被多个Shape3D引用。

1.4编写JA V A3D程序的步骤SceneGraphObject类的子类是构建场景图的基础材料。

开发JA V A3D程序的基础轮廓包含七步,这些步骤可以把许多JA V A3D程序聚合起来1.创建一个Canvas3D对象2.创建一个VirtualUniverse对象3.创建一个Locale对象,把它附加于VirtualUniverse对象4.构造一个观察分支图a.创建一个View对象b.创建一个ViewPlatform对象c.创建一个PhysicalBody对象d.创建一个PhysicalEnvironment对象e.把ViewPlatform,PhysicalBody,PhysicalEnvironment,Canvas3D附加于View对象5.构造一个内容分支图graph(s)6.编译graph(s)7.把子图插入到Locale中上述方法忽略了一些细节,但是详细说明了JA V A3D编程的基本思想:创建场景图的每一个分支图是编程的大部分工作,除了详述这些方法,下一节我们将介绍一种用更少的编程的简单方法去构建一个非常类似的场景图1.4.1编写JA V A3D程序的一种简单方法我们会用基本的方法构建相同结构的观察分支图来编写JA V A3D程序。

SimpleUniverse实用类包含了观察分支图结构的一致性,SimpleUniverse实例把基本方法中的2,3和4步骤都包含了。

在JA V A3D编程中用SimpleUniverse类来创建观察分支图可以有效地减少时间和工作量,于是程序员可以有更多的时间来关注内容分支图的开发,这就是JA V A3D编程所关注的。

SimpleUniverse对于JA V A3D编程来说是一个好的起点,因为它允许程序员忽略观察分支图。

然而,利用SimpleUniverse却不允许在虚拟宇宙中存在多个观察点。

在这教程中所有的编程实例都用到SimpleUniverse类.如果程序员需要了解View, ViewPlatform, PhysicalBody和PhysicalEnvironment类的更多的信息请参考其它文档。

SimpleUniverse类SimpleUniverse对象创建了一个包含VirtualUniverse,Locale对象,和一个完整的观察分支图的场景图。

相关文档
最新文档