00000008.htm
来自「水木清华BBS」· HTM 代码 · 共 553 行 · 第 1/3 页
HTM
553 行
0.0f,0.5f,1.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,0.8f,2.0f, <BR> 1.0f,0.0f,0.3f, <BR> 0.0f,1.0f,0.3f, <BR> 0.3f,0.8f,0.0f, <BR> }; <BR> <BR> public lineShape2() { <BR> StripCount[0] = 6; <BR> <BR> LineStripArray line = new LineStripArray(6, <BR> LineStripArray.COORDINATES| <BR> LineStripArray.COLOR_3,StripCount); <BR> line.setCoordinates(0,vert); <BR> line.setColors(0,color); <BR> LineAttributes la = new LineAttributes(); <BR> la.setLineWidth(30.0f); <BR> la.setLineAntialiasingEnable(true); <BR> la.setLinePattern(LineAttributes.PATTERN_DASH); <BR> Appearance ap = new Appearance(); <BR> ap.setLineAttributes(la); <BR> this.setGeometry(line); <BR> this.setAppearance(ap); <BR> } <BR>} <BR> <BR>//end of lineShape2.java <BR>----------------------------------------- <BR>//Line2.java <BR> <BR>import java.applet.Applet; <BR>import java.awt.BorderLayout; <BR>import com.sun.j3d.utils.applet.MainFrame; <BR>import com.sun.j3d.utils.universe.*; <BR>import javax.media.j3d.*; <BR>import javax.vecmath.*; <BR> <BR>public class Line2 extends Applet { <BR> <BR> private BranchGroup createSceneGraph() { <BR> BranchGroup objRoot = new BranchGroup(); <BR> objRoot.addChild(createObject()); <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> Shape3D shape = new lineShape2(); <BR> objTrans.addChild(shape); <BR> <BR> Transform3D yAxis = new Transform3D(); <BR> Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, <BR> 0, 0, <BR> 4000, 0, 0, <BR> 0, 0, 0); <BR> RotationInterpolator rotator = <BR> new RotationInterpolator(rotationAlpha, objTrans, yAxis, <BR> 0.0f, (float) Math.PI*2.0f); <BR> BoundingSphere bounds = <BR> new BoundingSphere(new Point3d(0.0,0.0,0.0), 50.0); <BR> rotator.setSchedulingBounds(bounds); <BR> objTrans.addChild(rotator); <BR> <BR> return objTrans; <BR> } <BR> <BR> public Line2() { <BR> setLayout(new BorderLayout()); <BR> Canvas3D c = new Canvas3D(null); <BR> add("Center", c); <BR> BranchGroup scene = createSceneGraph(); <BR> SimpleUniverse u = new SimpleUniverse(c); <BR> u.getViewingPlatform().setNominalViewingTransform(); <BR> u.addBranchGraph(scene); <BR> } <BR> <BR> public static void main(String[] args) { <BR> new MainFrame(new Line2(), 400,400); <BR> } <BR>} <BR> <BR>//end of Line2.java <BR> <BR> 由上可知,Line2.java这个程序和Point5.java几乎没有 <BR>什么差别,除了类的名字于调用的外部程序名不同之外,其余 <BR>完全相同。 <BR> lineShape1.java和lineShape2.java相差不大, <BR>lineShape2.java多了一个StripCount数组,它可以用来生成 <BR>多个折线段,下面的lineShape3.java程序就将Line2.java生成 <BR>的一条折线段分成了两条折线段:0、1、2三个点构成了一个折 <BR>线段,3、4、5构成了另一条折线段,每个折线段的顶点数目就 <BR>构成了数组StripCount,StripCount数组的大小等于折线段的 <BR>数目。 <BR>//lineShape3.java <BR> <BR>import javax.media.j3d.*; <BR> <BR>public class lineShape3 extends Shape3D { <BR> int StripCount[] = new int[2]; <BR> <BR> private float vert[] = { <BR> .8f, 0.8f,0.0f, <BR> -0.8f, 0.8f,0.0f, <BR> 0.5f, 0.0f,0.0f, <BR> -0.5f, 0.0f,0.0f, <BR> -0.8f,-0.8f,0.0f, <BR> 0.8f,-0.8f,0.0f, <BR> }; <BR> <BR> private float color[] = { <BR> 0.0f,0.5f,1.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,0.8f,2.0f, <BR> 1.0f,0.0f,0.3f, <BR> 0.0f,1.0f,0.3f, <BR> 0.3f,0.8f,0.0f, <BR> }; <BR> <BR> public lineShape3() { <BR> StripCount[0] = 3; <BR> StripCount[1] = 3; <BR> <BR> LineStripArray line = new LineStripArray(6, <BR> LineStripArray.COORDINATES| <BR> LineStripArray.COLOR_3,StripCount); <BR> line.setCoordinates(0,vert); <BR> line.setColors(0,color); <BR> LineAttributes la = new LineAttributes(); <BR> la.setLineWidth(30.0f); <BR> la.setLineAntialiasingEnable(true); <BR> la.setLinePattern(LineAttributes.PATTERN_DASH); <BR> Appearance ap = new Appearance(); <BR> ap.setLineAttributes(la); <BR> this.setGeometry(line); <BR> this.setAppearance(ap); <BR> } <BR>} <BR> <BR>//end of lineShape3.java <BR> <BR> 将lineShape3.java生成的绕Y轴旋转的形体用VRML <BR>程序表示的结果为: <BR> <BR>#VRML V2.0 utf8 <BR>DEF T Transform{ <BR> children Shape { <BR> geometry IndexedLineSet { <BR> coord Coordinate { <BR> point [.8 .8 .0, -.8, .8 0, .5 0 0, <BR> -.5 0 0, -.8 -.8 0, .8 -.8 0]} <BR> coordIndex [0 1 2 -1, 3 4 5 ] <BR> # 两个折线段 <BR> color Color{ <BR> color [ .0 .5 1., .5 .0 1, 0 .8 .2, <BR> 1 0 .3, 0 1 .3, .3 .8 0 ]} <BR> }}} <BR> <BR>DEF TS TimeSensor{ <BR> cycleInterval 4 <BR> loop TRUE} <BR> <BR>DEF OI OrientationInterpolator{ <BR> key [0 .25 .5 .75 1] <BR> keyValue [0 1 0 1, 0 1 0 1.57, 0 1 0 3.14 <BR> 0 1 0 4.71 0 1 0 6.28]} <BR> <BR>ROUTE TS.fraction TO OI.fraction <BR>ROUTE OI.value TO T.rotation <BR>#end of lineShape3.wrl <BR> <BR> <BR>三. 利用IndexedLineArray生成直线 <BR> IndexedLineArray对象的定义为: <BR> IndexedLineArray(int vertexCount, int vertexFormat, <BR> int indexCount ) <BR> 这里: <BR> vertexCount表示顶点数组里顶点的个数 <BR> vertexFormat表示顶点的格式(第七讲有介绍) <BR> indexCount表示选用的顶点个数,如果一个点用了 <BR> 几次,则要把几次加进去 <BR>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?