List of usage examples for javax.media.j3d QuadArray setNormals
public void setNormals(int index, float normals[])
From source file:Drag.java
public Cube(Appearance appearance) { QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2); quadArray.setCoordinates(0, verts);/* w w w.j a v a 2 s.c om*/ quadArray.setNormals(0, normals); quadArray.setTextureCoordinates(0, textCoords); shape3D = new Shape3D(quadArray, appearance); }
From source file:EnvironmentExplorer.java
void setupGrid() { // create a Switch for the spheres, allow switch changes gridSwitch = new Switch(Switch.CHILD_NONE); gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the square3s with red ambient, // black emmissive, red diffuse and black specular coloring Material material = new Material(red, black, red, black, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);/* w w w . j a va 2s. c o m*/ // create a grid of quads int gridSize = 20; // grid is gridSize quads along each side int numQuads = gridSize * gridSize; int numVerts = numQuads * 4; // 4 verts per quad // there will be 3 floats per coord and 4 coords per quad float[] coords = new float[3 * numVerts]; // All the quads will use the same normal at each vertex, so // allocate an array to hold references to the same normal Vector3f[] normals = new Vector3f[numVerts]; Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f); float edgeLength = 5.0f; // length of each edge of the grid float gridGap = 0.03f; // the gap between each quad // length of each quad is (total length - sum of the gaps) / gridSize float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize; // create a grid of quads in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere float curX, curY; for (int y = 0; y < gridSize; y++) { curY = y * (quadLength + gridGap); // offset to lower left corner curY -= edgeLength / 2; // center on 0,0 for (int x = 0; x < gridSize; x++) { // this is the offset into the vertex array for the first // vertex of the quad int vertexOffset = (y * gridSize + x) * 4; // this is the offset into the coord array for the first // vertex of the quad, where there are 3 floats per vertex int coordOffset = vertexOffset * 3; curX = x * (quadLength + gridGap); // offset to ll corner curX -= edgeLength / 2; // center on 0,0 // lower left corner coords[coordOffset + 0] = curX; coords[coordOffset + 1] = curY; coords[coordOffset + 2] = 0.0f; // z // lower right corner coords[coordOffset + 3] = curX + quadLength; coords[coordOffset + 4] = curY; coords[coordOffset + 5] = 0.0f; // z // upper right corner coords[coordOffset + 6] = curX + quadLength; coords[coordOffset + 7] = curY + quadLength; coords[coordOffset + 8] = 0.0f; // z // upper left corner coords[coordOffset + 9] = curX; coords[coordOffset + 10] = curY + quadLength; coords[coordOffset + 11] = 0.0f; // z for (int i = 0; i < 4; i++) { normals[vertexOffset + i] = vertNormal; } } } // now that we have the data, create the QuadArray QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS); quads.setCoordinates(0, coords); quads.setNormals(0, normals); // create the shape Shape3D shape = new Shape3D(quads, appearance); // add it to the switch gridSwitch.addChild(shape); }
From source file:FourByFour.java
public BigCube(Appearance appearance) { QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS); quadArray.setCoordinates(0, verts);/* w w w. j a v a2 s . c o m*/ quadArray.setNormals(0, normals); shape3D = new Shape3D(quadArray, appearance); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); }
From source file:FourByFour.java
public Cube(Appearance appearance) { QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2); quadArray.setCoordinates(0, verts);/*from ww w.jav a 2s . c o m*/ quadArray.setNormals(0, normals); shape3D = new Shape3D(quadArray, appearance); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); }
From source file:FourByFour.java
public Cube(Appearance appearance, float size) { QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS); for (int i = 0; i < 72; i++) verts[i] *= size;/*from w w w .j av a 2s . c o m*/ quadArray.setCoordinates(0, verts); quadArray.setNormals(0, normals); shape3D = new Shape3D(quadArray, appearance); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); }
From source file:FourByFour.java
public BigCube(Appearance appearance, float size) { QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS); for (int i = 0; i < 72; i++) verts[i] *= size;//from w w w .ja v a2 s . c o m quadArray.setCoordinates(0, verts); quadArray.setNormals(0, normals); shape3D = new Shape3D(quadArray, appearance); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ); shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); }