List of usage examples for javax.media.j3d TriangleArray setCoordinates
public void setCoordinates(int index, float coordinates[])
From source file:AppearanceTest.java
public Tetrahedron() { int i;//from w w w . j a va 2s. c om TriangleArray tetra = new TriangleArray(12, TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2); tetra.setCoordinates(0, verts); for (i = 0; i < 12; i++) { tetra.setTextureCoordinate(0, i, texCoord[i % 3]); } int face; Vector3f normal = new Vector3f(); Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); Point3f[] pts = new Point3f[3]; for (i = 0; i < 3; i++) pts[i] = new Point3f(); for (face = 0; face < 4; face++) { tetra.getCoordinates(face * 3, pts); v1.sub(pts[1], pts[0]); v2.sub(pts[2], pts[0]); normal.cross(v1, v2); normal.normalize(); for (i = 0; i < 3; i++) { tetra.setNormal((face * 3 + i), normal); } } this.setGeometry(tetra); this.setAppearance(new Appearance()); }
From source file:TickTockPicking.java
public Tetrahedron() { int i;//from ww w. j ava 2 s .c o m TriangleArray tetra = new TriangleArray(12, TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2); tetra.setCoordinates(0, verts); for (i = 0; i < 12; i++) { tetra.setTextureCoordinate(0, i, texCoord[i % 3]); } int face; Vector3f normal = new Vector3f(); Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); Point3f[] pts = new Point3f[3]; for (i = 0; i < 3; i++) pts[i] = new Point3f(); for (face = 0; face < 4; face++) { tetra.getCoordinates(face * 3, pts); v1.sub(pts[1], pts[0]); v2.sub(pts[2], pts[0]); normal.cross(v1, v2); normal.normalize(); for (i = 0; i < 3; i++) { tetra.setNormal((face * 3 + i), normal); } } tetra.setCapability(Geometry.ALLOW_INTERSECT); this.setGeometry(tetra); this.setAppearance(new Appearance()); }
From source file:AppearanceExplorer.java
Shape3D createTexTris() { Point3f pnt[] = new Point3f[9]; pnt[0] = new Point3f(-0.8f, -0.8f, 0.0f); pnt[1] = new Point3f(-0.5f, -0.7f, 0.0f); pnt[2] = new Point3f(-0.7f, 0.7f, 0.0f); pnt[3] = new Point3f(-0.4f, 0.7f, 0.0f); pnt[4] = new Point3f(0.0f, -0.7f, 0.0f); pnt[5] = new Point3f(0.4f, 0.7f, 0.0f); pnt[6] = new Point3f(0.5f, 0.7f, 0.0f); pnt[7] = new Point3f(0.5f, -0.7f, 0.0f); pnt[8] = new Point3f(0.9f, 0.0f, 0.0f); TexCoord2f texCoord[] = new TexCoord2f[9]; texCoord[0] = new TexCoord2f(0.05f, 0.90f); texCoord[1] = new TexCoord2f(0.25f, 0.10f); texCoord[2] = new TexCoord2f(1.00f, 0.60f); texCoord[3] = texCoord[0];//from w w w. j a v a2 s . co m texCoord[4] = texCoord[1]; texCoord[5] = texCoord[2]; texCoord[6] = texCoord[0]; texCoord[7] = texCoord[1]; texCoord[8] = texCoord[2]; TriangleArray ta = new TriangleArray(9, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); ta.setCoordinates(0, pnt); ta.setTextureCoordinates(0, 0, texCoord); return new Shape3D(ta, appearance); }
From source file:AppearanceExplorer.java
Shape3D createTriangleArray() { Point3f pnt[] = new Point3f[3]; pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f); pnt[1] = new Point3f(1.0f, -1.0f, 0.0f); pnt[2] = new Point3f(1.0f, 1.0f, 0.0f); Color3f colrs[] = new Color3f[3]; colrs[0] = red;//from w w w. j a v a 2 s .co m colrs[1] = green; colrs[2] = blue; Vector3f norms[] = new Vector3f[3]; Vector3f triNormal = new Vector3f(0.0f, 0.0f, 1.0f); norms[0] = triNormal; norms[1] = triNormal; norms[2] = triNormal; TriangleArray ta = new TriangleArray(3, GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.NORMALS); ta.setCoordinates(0, pnt); ta.setColors(0, colrs); ta.setNormals(0, norms); return new Shape3D(ta, appearance); }