00000010.htm
来自「水木清华BBS」· HTM 代码 · 共 355 行 · 第 1/2 页
HTM
355 行
IndexedTriangleStripArray对象的定义为: <BR> IndexedTriangleStripArray( int vertexCount, int vertexFormat, <BR> int indexCount, int stripIndexCounts[]) <BR> 利用IndexedTriangleStripArray对象,我们可以生成多组三角片面, <BR>对于每一组三角片面来说,它的头三个点生成一个面,从第四个点 <BR>开始,每一个点都和前两个点生成一个新的面。这些点可以通过一个数组index <BR>从一个顶点数组中任意选取,它和TriangleStripArray的差别在于 <BR>TriangleStripArray对顶点没有选择权,而IndexedTriangleStripArray <BR>对顶点具有选择权,其它的都一样。 <BR> 程序triShape6.java给出了一个16个数构成的顶点数组,从中挑选了 <BR>两组数,每一组都有6个顶点构成并生成了相连的四个三角片面。 <BR>//triShape6.java <BR> <BR>import javax.media.j3d.*; <BR> <BR>public class triShape6 extends Shape3D { <BR> int StripCount[] = new int[2]; <BR> private float vert[] = { <BR> -.6f , .6f , .1f , <BR> -.6f , .2f , .2f , <BR> -.6f , -.2f , .1f , <BR> -.6f , -.6f , .2f , <BR> -.0f , .6f , -.1f , <BR> -.0f , .2f , -.2f , <BR> -.0f , -.2f , -.1f , <BR> -.0f , -.6f , -.2f , <BR> .6f , .6f , .1f , <BR> .6f , .2f , .2f , <BR> .6f , -.2f , .1f , <BR> .6f , -.6f , .2f , <BR> }; <BR> <BR> private float color[] = { <BR> 1.0f,0.5f,0.0f, <BR> 1.0f,0.0f,0.5f, <BR> 1.0f,0.8f,0.0f, <BR> 5.0f,1.0f,0.0f, <BR> 0.0f,1.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,0.5f,1.0f, <BR> 1.0f,0.5f,0.0f, <BR> 1.0f,0.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> }; <BR> <BR> public triShape6() { <BR> int[] index={ 0 , 1 , 4 , 5 , 8 , 9 , 2 , 3 , 6 , 7 , 10 }; <BR> StripCount[0] = 6; <BR> StripCount[1] = 5; <BR> int indexCount=11; <BR> IndexedTriangleStripArray tri = new IndexedTriangleStripArray(12, <BR> IndexedTriangleStripArray.COORDINATES| <BR> IndexedTriangleStripArray.COLOR_3 , indexCount , StripCount); <BR> tri.setCoordinates(0,vert); <BR> tri.setColors(0,color); <BR> tri.setCoordinateIndices(0,index); <BR> tri.setColorIndices(0,index); <BR> PolygonAttributes pa = new PolygonAttributes(); <BR> pa.setCullFace(PolygonAttributes.CULL_NONE); <BR> Appearance ap = new Appearance(); <BR> ap.setPolygonAttributes(pa); <BR> this.setGeometry(tri); <BR> this.setAppearance(ap); <BR> this.setGeometry(tri); <BR> } <BR>} <BR>//end of Shape6.java <BR> <BR> <BR>四. IndexedTriangleFanArray生成的面 <BR> IndexedTriangleFanArray对象的定义为: <BR> IndexedTriangleFanArray ( int vertexCount, int vertexFormat, <BR> int indexCount, int stripIndexCounts[]) <BR> 利用这一对象,我们可以从一组顶点数组中挑选我们所需要的 <BR>顶点,生成多组三角片面,每组三角片面占用一定数量的顶点,每个组 <BR>在生成三角片面时,头三个顶点构成一个三角片面,其余的顶点和前面 <BR>的顶点及每组第一个顶点生成一个三角片面。下面的triShape7.java程 <BR>序中,我们生成了两组三角片面,头5个点生成了三个相连的三角片面, <BR>后6个点生成了四个相连的三角片面。形状就像两把扇子,一大一小。 <BR>程序中所用的数组为20个点的顶点数组。 <BR> IndexedTriangleFanArray对象和TriangleFanArray的应用方法很相似, <BR>它们之间的不同在于IndexedTriangleFanArray对象可以从顶点数组中挑选 <BR>自己所需要的顶点,而TriangleFanArray对象没有挑选权,只能被动地使用 <BR>顶点数组中的数据。 <BR>//triShape7.java <BR> <BR>import javax.media.j3d.*; <BR> <BR>public class triShape7 extends Shape3D { <BR> int StripCount[] = new int[2]; <BR> private float vert[] = { <BR> -.6f , .8f , -.1f , <BR> -.6f , .4f , -.0f , <BR> -.6f , .0f , .1f , <BR> -.6f , -.8f , -.1f , <BR> <BR> -.4f , .8f , .1f , <BR> -.4f , .4f , .1f , <BR> -.4f , .0f , -.1f , <BR> -.4f , -.8f , .1f , <BR> <BR> -.0f , .8f , -.1f , <BR> -.0f , .4f , -.0f , <BR> -.0f , .0f , .1f , <BR> -.0f , -.8f , -.1f , <BR> <BR> .4f , .8f , .1f , <BR> .4f , .4f , -.05f , <BR> .4f , .0f , -.1f , <BR> .4f , -.8f , .1f , <BR> <BR> .6f , .8f , -.1f , <BR> .6f , .4f , -.0f , <BR> .6f , .0f , .1f , <BR> .6f , -.8f , -.1f , <BR> <BR> }; <BR> <BR> private float color[] = { <BR> 1.0f,0.5f,0.0f, <BR> 1.0f,0.0f,0.5f, <BR> 1.0f,0.8f,0.0f, <BR> 0.5f,1.0f,0.0f, <BR> 0.0f,1.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,0.5f,1.0f, <BR> 1.0f,0.5f,0.0f, <BR> 1.0f,0.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,1.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> 0.0f,0.5f,1.0f, <BR> 1.0f,0.5f,0.0f, <BR> 1.0f,0.0f,0.5f, <BR> 0.9f,1.0f,0.0f, <BR> 0.5f,0.0f,1.0f, <BR> }; <BR> <BR> public triShape7() { <BR> int[] index={ 9 , 4 , 8 , 12 , 16 , 11 , 2 , 6 , 10 , 14 , 18}; <BR> StripCount[0] = 5; <BR> StripCount[1] = 6; <BR> int indexCount=11; <BR> IndexedTriangleFanArray tri = new IndexedTriangleFanArray(20, <BR> IndexedTriangleFanArray.COORDINATES| <BR> IndexedTriangleFanArray.COLOR_3 , indexCount , StripCount); <BR> tri.setCoordinates(0,vert); <BR> tri.setColors(0,color); <BR> tri.setCoordinateIndices(0,index); <BR> tri.setColorIndices(0,index); <BR> PolygonAttributes pa = new PolygonAttributes(); <BR> pa.setCullFace(PolygonAttributes.CULL_NONE); <BR> Appearance ap = new Appearance(); <BR> ap.setPolygonAttributes(pa); <BR> this.setGeometry(tri); <BR> this.setAppearance(ap); <BR> this.setGeometry(tri); <BR> } <BR>} <BR>/end of triShape7.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 + -
显示快捷键?