00000008.htm
来自「水木清华BBS」· HTM 代码 · 共 553 行 · 第 1/3 页
HTM
553 行
<BR> 在上一节里我们介绍了利用IndexedPoint生成点 <BR>的程序,和IndexedPoint相类似,我们可以利用 <BR>IndexedLineArray生成直线段。 <BR> 下面的lineShape4.java利用了IndexedLineArray <BR>从六个点中挑选了3个点,生成了2条直线。 <BR> 从程序中我们可以看到,下标为0的点使用了两次, <BR>但生成的是两条线,因而参数VertexCount应为4,即 <BR>此处的VertexCount的数值应为直线条数的两倍。 <BR>//lineShape4.java <BR> <BR>import javax.media.j3d.*; <BR> <BR>public class lineShape4 extends Shape3D { <BR> int[] index={ 1, 0, 0 , 3, }; <BR> int VertexCount=4; <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 lineShape4() { <BR> <BR> IndexedLineArray line = new IndexedLineArray(6, <BR> IndexedLineArray.COORDINATES| <BR> IndexedLineArray.COLOR_3,VertexCount); <BR> line.setCoordinates(0,vert); <BR> line.setColors(0,color); <BR> line.setCoordinateIndices(0,index); <BR> line.setColorIndices(0,index); <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 lineShape4.java <BR> <BR> 将lineShape4.java翻译成VRML的相应程序为: <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 [1 0 -1 0 3] <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> <BR> <BR>四. 利用IndexedLineStripArray生成直线 <BR> IndexedLineStripArray对象的定义如下: <BR> IndexedLineStripArray( int vertexCount, int vertexFormat, <BR> int indexCount, int stripIndexCounts[]) <BR> 这里: <BR> vertexCount表示顶点数组里顶点的个数 <BR> vertexFormat表示顶点的格式(第七讲有介绍) <BR> indexCount表示选用的顶点的个数 <BR> stripIndexCounts为一数组,数组里的每一个数值表示 <BR> 每条折线段所拥有的顶点数目。 <BR> 下面的程序里,我们给出10个顶点, <BR> <BR> --0-- --1-- <BR> <BR> --2-- --3-- <BR> <BR> --4-- --5-- <BR> <BR> --6-- --7-- <BR> <BR> --8-- --9-- <BR> <BR> 然后我们用IndexedLineStripArray生成三个折线段,第一个 <BR>折线段为:0 1 3 2,第二个折线段为3、5、4,第三个折线段为 <BR>6、7、8、6,最后一个点没有用到。所有的直线宽度为30像数。 <BR>这时我们只用了10个点中的9个点,但有2个点用了两次,因而程序 <BR>中的vertexCount为11, <BR>程序如下: <BR>//lineShape5.java <BR> <BR>import javax.media.j3d.*; <BR> <BR>public class lineShape5 extends Shape3D { <BR> int StripCount[] = new int[3]; <BR> int[] index={ 0 , 1 , 3 , 2 , 3 , 5 , <BR> 4 , 6 , 7 , 8 , 6 } ; <BR> int vertexCount = 11; <BR> private float vert[] = { <BR> -.3f , .8f , .0f, <BR> .3f , .8f , .0f, <BR> -.3f , .4f , .0f, <BR> .3f , .4f , .0f, <BR> -.3f , .0f , .0f, <BR> .3f , .0f , .0f, <BR> -.3f , -.4f , .0f, <BR> .3f , -.4f , .0f, <BR> -.3f , -.8f , .0f, <BR> .3f , -.8f , .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> 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> }; <BR> <BR> public lineShape5() { <BR> StripCount[0] = 4; <BR> StripCount[1] = 3; <BR> StripCount[2] = 4; <BR> IndexedLineStripArray line = new IndexedLineStripArray(10 , <BR> IndexedLineStripArray.COORDINATES| <BR> IndexedLineStripArray.COLOR_3, vertexCount , StripCount); <BR> line.setCoordinates(0,vert); <BR> line.setColors(0,color); <BR> line.setCoordinateIndices(0,index); <BR> line.setColorIndices(0,index); <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 lineShape5.java <BR> <BR>-- <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.192.158.112] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?