00000017.htm
来自「水木清华BBS」· HTM 代码 · 共 570 行 · 第 1/3 页
HTM
570 行
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: vrml (3d), 信区: Java <BR>标 题: JAV3D学习系列(17)--动画的生成(下) <BR>发信站: BBS 水木清华站 (Mon Apr 26 11:48:56 1999) <BR> <BR> JAVA3D学习系列(17)--动画的生成(下) <BR> <BR> <BR> 汕头大学机电系 张杰(<A HREF="mailto:jzhang@mailserv.stu.edu.cn)">jzhang@mailserv.stu.edu.cn)</A> <BR> <BR> <BR>一. TransparnecyInterpolator对象 <BR> TransparencyInterpolator对象的构造函数有两个: <BR> public TransparencyInterpolator(Alpha alpha, <BR> TransparencyAttributes target) <BR> public TransparencyInterpolator(Alpha alpha, <BR> TransparencyAttributes target, <BR> float minimumTransparency, <BR> float maximumTransparency) <BR> 它的方法有: <BR> public void setMinimumTransparency(float transparency) <BR> public float getMinimumTransparency() <BR> <BR> public void setMaximumTransparency(float transparency) <BR> public float getMaximumTransparency() <BR> <BR> public void setTarget(TransparencyAttributes target) <BR> public TransparencyAttributes getTarget() <BR> <BR> public void processStimulus(Enumeration criteria) <BR> <BR> 利用这个对象,我们可以在给定的时间内,使某一个形体的透明度 <BR>按照Alpha提供的方式在两个数值之间变化,VRML语言中我们可以用 <BR>ScalarInterpolator节点来实现同样的效果。 <BR> 如果我们使用的是第一个构造函数,则透明度的最大值为1.0f, <BR>最小值为0.0f。 <BR> 下面是一个应用此方法的JAVA3D程序和一个相对应的VRML程序。 <BR>为了看出透明的效果,我们设定背景为白色。 <BR>//Tra.java <BR>import java.applet.Applet; <BR>import java.awt.BorderLayout; <BR>import com.sun.j3d.utils.applet.MainFrame; <BR>import com.sun.j3d.utils.image.TextureLoader; <BR>import com.sun.j3d.utils.universe.*; <BR>import com.sun.j3d.utils.geometry.*; <BR>import javax.media.j3d.*; <BR>import javax.vecmath.*; <BR> <BR>public class Tra extends Applet { <BR> <BR> private BranchGroup createSceneGraph() { <BR> BranchGroup objRoot = new BranchGroup(); <BR> objRoot.addChild(createObject()); <BR> BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0); <BR> Background bg=new Background(new Color3f(1.0f,1.0f,1.0f)); <BR> bg.setApplicationBounds(bounds); <BR> objRoot.addChild(bg); <BR> objRoot.compile(); <BR> return objRoot; <BR> } <BR> <BR> private Group createObject() { <BR> Transform3D t = new Transform3D(); <BR> TransformGroup objTrans = new TransformGroup(t); <BR> objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); <BR> <BR> Appearance ap=new Appearance(); <BR> Color3f ambient=new Color3f(1.0f,0.0f,0.0f); <BR> Color3f emissive = new Color3f(0.8f,0.2f,0.2f); <BR> Color3f diffuse=new Color3f(1.f,1.f,0.f); <BR> Color3f specular = new Color3f(1.0f,1.0f,1.0f); <BR> ap.setMaterial(new Material(ambient,emissive,diffuse,specular,100.0f)); <BR> <BR> PolygonAttributes pa = new PolygonAttributes(); <BR> pa.setCullFace(PolygonAttributes.CULL_NONE); <BR> ap.setPolygonAttributes(pa); <BR> <BR> TransparencyAttributes ta=new TransparencyAttributes(); <BR> ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); <BR> ta.setTransparencyMode(ta.BLENDED); <BR> ta.setTransparency(.0f); <BR> ap.setTransparencyAttributes(ta); <BR> <BR> Alpha alpha = new Alpha(-1, <BR> Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, <BR> 0, 0, 8000, 0, 0, 8000, 0, 0); <BR> TransparencyInterpolator transparency= <BR> new TransparencyInterpolator(alpha,ta,.0f,1.f); <BR> BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0); <BR> transparency.setSchedulingBounds(bounds); <BR> Shape3D shape = new myShape(); <BR> shape.setAppearance(ap); <BR> objTrans.addChild(shape); <BR> objTrans.addChild(transparency); <BR> <BR> Transform3D yAxis = new Transform3D(); <BR> Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, <BR> 0, 0, 4000, 0, 0, 0, 0, 0); <BR> <BR> RotationInterpolator rotator = <BR> new RotationInterpolator(rotationAlpha, objTrans, yAxis, <BR> 0.0f, (float) Math.PI*2.0f); <BR> rotator.setSchedulingBounds(bounds); <BR> objTrans.addChild(rotator); <BR> <BR> return objTrans; <BR> } <BR> <BR> public Tra() { <BR> setLayout(new BorderLayout()); <BR> Canvas3D c = new Canvas3D(null); <BR> add("Center", c); <BR> <BR> BranchGroup scene = createSceneGraph(); <BR> SimpleUniverse u = new SimpleUniverse(c); <BR> u.getViewingPlatform().setNominalViewingTransform(); <BR> <BR> u.addBranchGraph(scene); <BR> } <BR> <BR> public static void main(String[] args) { <BR> new MainFrame(new Tra(), 540,361); <BR> } <BR>} <BR> <BR> <BR>//end of Tra.java <BR>--------- <BR>#VRML V2.0 utf8 <BR>DEF T Transform{ <BR> children Shape{ <BR> appearance Appearance{material DEF M Material{diffuseColor 0 1 0}} <BR> geometry IndexedFaceSet{ <BR> coord Coordinate{point [-0.3 -0.3 0,-0.3 0.3 0, <BR> -0.1 -0.3 0,-0.1 0.3 0, <BR> 0.1 -0.3 0, 0.1 0.3 0, <BR> 0.3 -0.3 0, 0.3 0.3 0, <BR> 0.4 0.4 0]} <BR> coordIndex[0 3 1 -1, 2 5 4 -1, 6 8 7] <BR> solid FALSE <BR> } <BR>} <BR>} <BR> <BR>DEF TS TimeSensor{ <BR> loop TRUE <BR> cycleInterval 8} <BR> <BR>DEF SI ScalarInterpolator{ <BR> key[0 .5 1] <BR> keyValue[ 1, 0, 1] <BR>} <BR> <BR>DEF OI OrientationInterpolator{ <BR> key[0 .5 1] <BR> keyValue[ 0 1 0 0 , 0 1 0 3.14, 0 1 0 6.28] <BR>} <BR> <BR>Viewpoint { <BR> position 0 .3 1 <BR> orientation 1 0 0 -.3} <BR> <BR>Background{skyColor 1 1 1} <BR> <BR>ROUTE TS.fraction TO SI.fraction <BR>ROUTE TS.fraction TO OI.fraction <BR>ROUTE SI.value TO M.transparency <BR>ROUTE OI.value TO T.rotation <BR>#end of tra.wrl <BR> <BR> <BR>二. PathInterpolator对象 <BR> 我们在后面将要介绍下面这些对象: <BR> PositionPathInterpolator <BR> RotPosPathInterpolator <BR> RotPosScalePathInterpolator <BR> RotationPathInterpolator <BR> 它们都是PathInterpolator的子类。为此,我们先介绍一下 <BR>PathInterpolator对象的作用。 <BR> PathInterpolator是Interpolator类的子类,就好象我们 <BR>上面介绍的所有的内插对象是Interpolator类的子类一样。 <BR>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?