List of usage examples for javax.media.j3d IndexedQuadArray IndexedQuadArray
public IndexedQuadArray(int vertexCount, int vertexFormat, int indexCount)
From source file:SpotLightApp.java
public SpotLightApp() { BoundingSphere bound1 = new BoundingSphere(new Point3d(0.0, 0.9, 0.0), 0.5); BoundingSphere bound2 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.5); BoundingSphere bound3 = new BoundingSphere(new Point3d(0.0, -0.9, 0.0), 0.5); Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f green = new Color3f(0.0f, 1.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); final int X = 101, Y = 102; final float dx = 0.01f, dy = -0.01f; final float epx = dx / 2.0f, epy = dy / 2.0f; final float top = 0.5f, left = -0.5f; final float right = left + dx * (X - 1); final float bottom = top + dy * (Y - 1); IndexedQuadArray qa = new IndexedQuadArray(X * Y, QuadArray.COORDINATES | QuadArray.NORMALS, (X - 1) * (Y - 1) * 4);/*from w w w . j a v a 2s . c o m*/ float x, y; int i = 0; System.out.print("set " + X * Y + " coordiantes..... "); for (y = top; y >= bottom - epx; y += dy) for (x = left; x <= right + epx; x += dx) qa.setCoordinate(i++, new Point3f(x, y, 0.0f)); System.out.println(i + " coordiantes done"); int row, col; i = 0; Vector3f n = new Vector3f(0.0f, 0.0f, 1.0f); System.out.print("set " + (X - 1) * (Y - 1) * 4 + " coordinate indices..... "); for (row = 0; row < (Y - 1); row++) { for (col = 0; col < (X - 1); col++) { qa.setNormal(row * X + col, n); qa.setCoordinateIndex(i++, row * X + col); qa.setCoordinateIndex(i++, (row + 1) * X + col); qa.setCoordinateIndex(i++, (row + 1) * X + col + 1); qa.setCoordinateIndex(i++, row * X + col + 1); } qa.setNormal(row * X + col + 1, n); } System.out.println(i + " coordinate indices done"); for (col = 0; col < (X - 1); col++) { qa.setNormal(X * (Y - 1) + 1 + col, n); } System.out.println("coordinate normals done"); Appearance qAppear = createMatAppear(blue, white, 5.0f); Shape3D plane = new Shape3D(qa, qAppear); Transform3D translate = new Transform3D(); translate.set(new Vector3f(-0.5f, 0.5f, 0.0f)); TransformGroup tg1 = new TransformGroup(translate); scene.addChild(tg1); Shape3D plane1 = new Shape3D(qa, qAppear); plane1.setBounds(bound1); tg1.addChild(plane1); translate.set(new Vector3f(0.5f, 0.5f, 0.0f)); TransformGroup tg2 = new TransformGroup(translate); scene.addChild(tg2); Shape3D plane2 = new Shape3D(qa, qAppear); plane2.setBounds(bound1); tg2.addChild(plane2); translate.set(new Vector3f(-0.5f, -0.5f, 0.0f)); TransformGroup tg3 = new TransformGroup(translate); scene.addChild(tg3); Shape3D plane3 = new Shape3D(qa, qAppear); plane3.setBounds(bound3); tg3.addChild(plane3); translate.set(new Vector3f(0.5f, -0.5f, 0.0f)); TransformGroup tg4 = new TransformGroup(translate); scene.addChild(tg4); Shape3D plane4 = new Shape3D(qa, qAppear); plane4.setBounds(bound3); tg4.addChild(plane4); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); scene.addChild(newSpotLight(bound1, new Point3f(-0.7f, 0.7f, 0.5f), 0.1f, 5.0f)); scene.addChild(newSpotLight(bound1, new Point3f(0.0f, 0.7f, 0.5f), 0.1f, 50.0f)); scene.addChild(newSpotLight(bound1, new Point3f(0.7f, 0.7f, 0.5f), 0.1f, 100.0f)); scene.addChild(newSpotLight(bound2, new Point3f(-0.7f, 0.0f, 0.5f), 0.3f, 5.0f)); scene.addChild(newSpotLight(bound2, new Point3f(0.0f, 0.0f, 0.5f), 0.3f, 50.0f)); scene.addChild(newSpotLight(bound2, new Point3f(0.7f, 0.0f, 0.5f), 0.3f, 100.0f)); scene.addChild(newSpotLight(bound3, new Point3f(-0.7f, -0.7f, 0.5f), 0.5f, 5.0f)); scene.addChild(newSpotLight(bound3, new Point3f(0.0f, -0.7f, 0.5f), 0.5f, 50.0f)); scene.addChild(newSpotLight(bound3, new Point3f(0.7f, -0.7f, 0.5f), 0.5f, 100.0f)); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); scene.compile(); setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:LightsNPlanesApp.java
public LightsNPlanesApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BoundingSphere bounds = new BoundingSphere(new Point3d(), 0.1); Vector3f direction = new Vector3f(0.0f, -1.0f, 0.0f); Point3f position = new Point3f(0.0f, 0.5f, -0.3f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f green = new Color3f(0.0f, 1.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); IndexedQuadArray qa = new IndexedQuadArray(9, QuadArray.COORDINATES | QuadArray.NORMALS, 16); qa.setCoordinate(0, new Point3f(-0.3f, 0.3f, -0.3f)); qa.setCoordinate(1, new Point3f(0.0f, 0.3f, -0.3f)); qa.setCoordinate(2, new Point3f(0.3f, 0.3f, -0.3f)); qa.setCoordinate(3, new Point3f(-0.3f, 0.0f, 0.0f)); qa.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.0f)); qa.setCoordinate(5, new Point3f(0.3f, 0.0f, 0.0f)); qa.setCoordinate(6, new Point3f(-0.3f, -0.3f, 0.3f)); qa.setCoordinate(7, new Point3f(0.0f, -0.3f, 0.3f)); qa.setCoordinate(8, new Point3f(0.3f, -0.3f, 0.3f)); Vector3f n = new Vector3f(0.0f, 0.6f, 0.8f); n.normalize();/* www . j a v a 2 s .com*/ qa.setNormal(0, n); qa.setNormal(1, n); qa.setNormal(2, n); qa.setNormal(3, n); qa.setNormal(4, n); qa.setNormal(5, n); qa.setNormal(6, n); qa.setNormal(7, n); qa.setNormal(8, n); qa.setCoordinateIndex(0, 0); qa.setCoordinateIndex(1, 3); qa.setCoordinateIndex(2, 4); qa.setCoordinateIndex(3, 1); qa.setCoordinateIndex(4, 1); qa.setCoordinateIndex(5, 4); qa.setCoordinateIndex(6, 5); qa.setCoordinateIndex(7, 2); qa.setCoordinateIndex(8, 3); qa.setCoordinateIndex(9, 6); qa.setCoordinateIndex(10, 7); qa.setCoordinateIndex(11, 4); qa.setCoordinateIndex(12, 4); qa.setCoordinateIndex(13, 7); qa.setCoordinateIndex(14, 8); qa.setCoordinateIndex(15, 5); TransformGroup trans1 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans1); TransformGroup trans2 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans2); TransformGroup trans3 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans3); Appearance qAppear = createMatAppear(white, white, 5.0f); Shape3D p1 = new Shape3D(qa, qAppear); // p1.setBoundsAutoCompute(false); p1.setBounds(bounds); p1.setCapability(Node.ALLOW_BOUNDS_READ); trans1.addChild(p1); Shape3D p2 = new Shape3D(qa, qAppear); p2.setBounds(bounds); p2.setCapability(Node.ALLOW_BOUNDS_READ); trans2.addChild(p2); Shape3D p3 = new Shape3D(qa, qAppear); p3.setBounds(bounds); p3.setCapability(Node.ALLOW_BOUNDS_READ); trans3.addChild(p3); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); lightA.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); scene.addChild(lightA); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setBoundsAutoCompute(false); lightD.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightD.setDirection(direction); lightD.setColor(red); trans1.addChild(lightD); PointLight lightP = new PointLight(); lightP.setInfluencingBounds(bounds); lightP.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightP.setPosition(position); lightP.setColor(green); trans2.addChild(lightP); SpotLight lightS = new SpotLight(); lightS.setInfluencingBounds(bounds); lightS.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightS.setPosition(position); lightS.setDirection(direction); lightS.setSpreadAngle(0.3f); lightS.setConcentration(1.0f); lightS.setColor(blue); trans3.addChild(lightS); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); scene.compile(); System.out.print("bounds object: "); System.out.println(bounds); System.out.print("influencing bounds for lightA: "); System.out.println(lightA.getInfluencingBounds()); System.out.print("influencing bounds for lightD: "); System.out.println(lightD.getInfluencingBounds()); System.out.print("influencing bounds for lightP: "); System.out.println(lightP.getInfluencingBounds()); System.out.print("influencing bounds for lightS: "); System.out.println(lightS.getInfluencingBounds()); System.out.print("bounds for plane1: "); System.out.println(p1.getBounds()); System.out.print("bounds for plane2: "); System.out.println(p2.getBounds()); System.out.print("bounds for plane3: "); System.out.println(p3.getBounds()); BoundingSphere bs0 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.2); BoundingSphere bs1 = new BoundingSphere(new Point3d(-0.1, 0.0, 0.0), 0.2); BoundingSphere bs2 = new BoundingSphere(new Point3d(-0.2, 0.0, 0.0), 0.2); BoundingSphere bs3 = new BoundingSphere(new Point3d(-0.3, 0.0, 0.0), 0.2); BoundingSphere bs4 = new BoundingSphere(new Point3d(-0.4, 0.0, 0.0), 0.2); BoundingSphere bs5 = new BoundingSphere(new Point3d(-0.5, 0.0, 0.0), 0.2); BoundingSphere bs6 = new BoundingSphere(new Point3d(-0.6, 0.0, 0.0), 0.2); BoundingSphere bs7 = new BoundingSphere(new Point3d(-0.7, 0.0, 0.0), 0.2); BoundingSphere bs8 = new BoundingSphere(new Point3d(-0.8, 0.0, 0.0), 0.2); BoundingBox bb1 = new BoundingBox(bs1); BoundingBox bb2 = new BoundingBox(bs2); BoundingBox bb3 = new BoundingBox(bs3); BoundingBox bb4 = new BoundingBox(bs4); BoundingBox bb5 = new BoundingBox(bs5); BoundingBox bb6 = new BoundingBox(bs6); BoundingBox bb7 = new BoundingBox(bs7); BoundingBox bb8 = new BoundingBox(bs8); if (bs0.intersect(bs1)) System.out.println("bs0 intersects bs1"); if (bs0.intersect(bs2)) System.out.println("bs0 intersects bs2"); if (bs0.intersect(bs3)) System.out.println("bs0 intersects bs3"); if (bs0.intersect(bs4)) System.out.println("bs0 intersects bs4"); if (bs0.intersect(bs5)) System.out.println("bs0 intersects bs5"); if (bs0.intersect(bs6)) System.out.println("bs0 intersects bs6"); if (bs0.intersect(bs7)) System.out.println("bs0 intersects bs7"); if (bs0.intersect(bs8)) System.out.println("bs0 intersects bs8"); if (bs0.intersect(bb1)) System.out.println("bs0 intersects bb1"); if (bs0.intersect(bb2)) System.out.println("bs0 intersects bb2"); if (bs0.intersect(bb3)) System.out.println("bs0 intersects bb3"); if (bs0.intersect(bb4)) System.out.println("bs0 intersects bb4"); if (bs0.intersect(bb5)) System.out.println("bs0 intersects bb5"); if (bs0.intersect(bb6)) System.out.println("bs0 intersects bb6"); if (bs0.intersect(bb7)) System.out.println("bs0 intersects bb7"); if (bs0.intersect(bb8)) System.out.println("bs0 intersects bb8"); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:SimpleMorph.java
/** * Build the content branch for the scene graph * /* w ww . j a v a2s. c om*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance object Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the cube key shape IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Make the pyramid key shape. Although this needs //only five vertices to create the desired shape, we //need to use six vertices so that it has the same //number as the cube. IndexedQuadArray indexedPyramid = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] pyramidCoordinates = { new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] pyramidNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int pyramidCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int pyramidNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedPyramid.setCoordinates(0, pyramidCoordinates); indexedPyramid.setNormals(0, pyramidNormals); indexedPyramid.setCoordinateIndices(0, pyramidCoordIndices); indexedPyramid.setNormalIndices(0, pyramidNormalIndices); //Set the contents of the array to the two shapes GeometryArray[] theShapes = new GeometryArray[2]; theShapes[0] = indexedCube; theShapes[1] = indexedPyramid; BranchGroup contentBranch = new BranchGroup(); //Create a transform to rotate the shape slightly Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); addLights(contentBranch); //Call the function to build the morph rotationGroup.addChild(createMorph(theShapes, app)); return contentBranch; }
From source file:SimpleIndexedQuad.java
/** * Build a cube from an IndexedQuadArray. This method creates the vertices * as a set of eight points and the normals as a set of six vectors (one for * each face). The data is then defined such that each vertex has a * different normal associated with it when it is being used for a different * face.// w w w . j av a 2 s .co m * * @return Node that is the shape. */ protected Node buildShape() { //The shape. The constructor specifies 8 vertices, that both //vertices and normals are to be defined and that there are //24 normals to be specified (4 for each of the 6 faces). IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); //The vertex coordinates defined as an array of points. Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; //The vertex normals defined as an array of vectors Vector3f[] normals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; //Define the indices used to reference vertex array int coordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; //Define the indices used to reference normal array int normalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; //Set the data indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, normals); indexedCube.setCoordinateIndices(0, coordIndices); indexedCube.setNormalIndices(0, normalIndices); //Define an appearance for the shape Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and return the shape return new Shape3D(indexedCube, app); }
From source file:SimpleMorph2.java
/** * Build the content branch for the scene graph * /* ww w.j ava2 s . c o m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the cube key shape IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Make the pyramid key shape. Although this needs //only five vertices to create the desired shape, we //need to use six vertices so that it has the same //number as the cube. IndexedQuadArray indexedPyramid = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] pyramidCoordinates = { new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] pyramidNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int pyramidCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int pyramidNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedPyramid.setCoordinates(0, pyramidCoordinates); indexedPyramid.setNormals(0, pyramidNormals); indexedPyramid.setCoordinateIndices(0, pyramidCoordIndices); indexedPyramid.setNormalIndices(0, pyramidNormalIndices); //Set the contents of the array to the two shapes GeometryArray[] theShapes = new GeometryArray[2]; theShapes[0] = indexedCube; theShapes[1] = indexedPyramid; BranchGroup contentBranch = new BranchGroup(); //Create a transform to rotate the shape slightly Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); addLights(contentBranch); //Call the function to build the morph rotationGroup.addChild(createMorph(theShapes, app)); //Add the behaviour to the scene graph to activate it rotationGroup.addChild(myBehave); return contentBranch; }
From source file:SimpleIndexedQuadSmooth.java
/** * Build a cube from an IndexedQuadArray. This method creates the vertices * as a set of eight points and the normals as a set of six vectors (one for * each face). The data is then defined such that each vertex has a * different normal associated with it when it is being used for a different * face.//from ww w. j ava 2 s . co m * * @return Node that is the shape. */ protected Node buildShape() { //The shape. The constructor specifies 8 vertices, that both //vertices and normals are to be defined and that there are //24 normals to be specified (4 for each of the 6 faces). IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); //The vertex coordinates defined as an array of points. Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; //The vertex normals defined as an array of vectors Vector3f[] normals = { new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, 1.0f), new Vector3f(1.0f, -1.0f, 1.0f), new Vector3f(1.0f, 1.0f, -1.0f), new Vector3f(-1.0f, 1.0f, -1.0f), new Vector3f(-1.0f, -1.0f, -1.0f), new Vector3f(1.0f, -1.0f, -1.0f) }; //Define the indices used to reference vertex array int coordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; //Define the indices used to reference normal array int normalIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; //Set the data indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, normals); indexedCube.setCoordinateIndices(0, coordIndices); indexedCube.setNormalIndices(0, normalIndices); //Define an appearance for the shape Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and return the shape return new Shape3D(indexedCube, app); }
From source file:SimpleCollision2.java
/** * Creates the content branch of the scene graph. * //ww w . j a v a2 s .c om * @return BranchGroup with content attached. */ protected BranchGroup buildContentBranch() { //First create a different appearance for each cube Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Appearance app3 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f ambientColour3 = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f diffuseColour3 = new Color3f(1.0f, 1.0f, 1.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); app3.setMaterial(new Material(ambientColour3, emissiveColour, diffuseColour3, specularColour, shininess)); //Build the vertex array for the cubes. We can use the same //data for each cube so we just define one set of data IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Create the three cubes leftCube = new Shape3D(indexedCube, app1); rightCube = new Shape3D(indexedCube, app2); moveCube = new Shape3D(indexedCube, app3); //Define some user data so that we can print meaningful messages leftCube.setUserData(new String("left cube")); rightCube.setUserData(new String("right cube")); //Create the content branch and add the lights BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Set up the transform to position the left cube Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); leftGroup = new TransformGroup(leftGroupXfm); //Set up the transform to position the right cube Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); rightGroup = new TransformGroup(rightGroupXfm); //Create the movable cube's transform with a scale and //a translation. Set up the //capabilities so it can be moved by the behaviour Transform3D moveXfm = new Transform3D(); moveXfm.set(0.7, new Vector3d(0.0, 2.0, 1.0)); moveGroup = new TransformGroup(moveXfm); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); //Create the behaviour to move the movable cube PickTranslateBehavior pickTranslate = new PickTranslateBehavior(contentBranch, myCanvas3D, bounds); contentBranch.addChild(pickTranslate); //Create and add the two colision detectors CollisionDetector2 myColDetLeft = new CollisionDetector2(leftCube, bounds); contentBranch.addChild(myColDetLeft); CollisionDetector2 myColDetRight = new CollisionDetector2(rightCube, bounds); contentBranch.addChild(myColDetRight); //Set up the scene graph contentBranch.addChild(moveGroup); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); moveGroup.addChild(moveCube); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); return contentBranch; }
From source file:SimpleCollision.java
/** * Creates the content branch of the scene graph. * //from w w w .j a va 2 s. c o m * @return BranchGroup with content attached. */ protected BranchGroup buildContentBranch() { //First create a different appearance for each cube Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Appearance app3 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f ambientColour3 = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f diffuseColour3 = new Color3f(1.0f, 1.0f, 1.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); app3.setMaterial(new Material(ambientColour3, emissiveColour, diffuseColour3, specularColour, shininess)); //Create the vertex data for the cube. Since each shape is //a cube we can use the same vertex data for each cube IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Create the three cubes leftCube = new Shape3D(indexedCube, app1); rightCube = new Shape3D(indexedCube, app2); moveCube = new Shape3D(indexedCube, app3); //Define the user data so that we can print out the //name of the colliding cube. leftCube.setUserData(new String("left cube")); rightCube.setUserData(new String("right cube")); //Create the content branch and add the lights BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Create and set up the movable cube's TransformGroup. //This scales and translates the cube and then sets the // read, write and pick reporting capabilities. Transform3D moveXfm = new Transform3D(); moveXfm.set(0.7, new Vector3d(0.0, 2.0, 1.0)); moveGroup = new TransformGroup(moveXfm); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); //Create the left cube's TransformGroup Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); leftGroup = new TransformGroup(leftGroupXfm); //Create the right cube's TransformGroup Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); rightGroup = new TransformGroup(rightGroupXfm); //Add the behaviour to allow us to move the cube PickTranslateBehavior pickTranslate = new PickTranslateBehavior(contentBranch, myCanvas3D, bounds); contentBranch.addChild(pickTranslate); //Add our CollisionDetector class to detect collisions with //the movable cube. CollisionDetector myColDet = new CollisionDetector(moveCube, bounds); contentBranch.addChild(myColDet); //Create the content branch hierarchy. contentBranch.addChild(moveGroup); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); moveGroup.addChild(moveCube); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); return contentBranch; }
From source file:SimpleTexture.java
/** * Build a cube from an IndexedQuadArray. This method creates the vertices * as a set of eight points and the normals as a set of six vectors (one for * each face). The data is then defined such that each vertex has a * different normal associated with it when it is being used for a different * face. The shape is created with texture coordinates so that when the * appearance is set it will use the appearance texture on the surface. * //from w ww .ja v a 2s .co m * @return Node that is the shape. */ protected Node buildShape() { IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS | IndexedQuadArray.TEXTURE_COORDINATE_2, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] normals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; //Define the texture coordinates. These are defined //as floating point pairs of values that are used to //map the corners of the texture image onto the vertices //of the face. We then define the indices into this //array of values in a similar way to that used for //the vertices and normals. TexCoord2f[] textCoord = { new TexCoord2f(1.0f, 1.0f), new TexCoord2f(0.0f, 1.0f), new TexCoord2f(0.0f, 0.0f), new TexCoord2f(1.0f, 0.0f) }; int coordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int normalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; int textIndices[] = { 0, 1, 2, 3, 3, 0, 1, 2, 1, 2, 3, 0, 1, 2, 3, 0, 3, 0, 1, 2, 1, 2, 3, 0 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setCoordinateIndices(0, coordIndices); indexedCube.setNormals(0, normals); indexedCube.setNormalIndices(0, normalIndices); indexedCube.setTextureCoordinates(0, 0, textCoord); indexedCube.setTextureCoordinateIndices(0, 0, textIndices); return new Shape3D(indexedCube, DefineAppearance()); }
From source file:SimpleTextureGen.java
/** * Build a cube from an IndexedQuadArray. This method creates the vertices * as a set of eight points and the normals as a set of six vectors (one for * each face). The data is then defined such that each vertex has a * different normal associated with it when it is being used for a different * face. The shape doesn't have texture coordinates or nornmals defined * since the texture coordinate generator will define the necessary data. * /*from w w w . j ava 2 s. com*/ * @return Node that is the shape. */ protected Node buildShape() { IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; int coordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int normalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; int textIndices[] = { 0, 1, 2, 3, 3, 0, 1, 2, 1, 2, 3, 0, 1, 2, 3, 0, 3, 0, 1, 2, 1, 2, 3, 0 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setCoordinateIndices(0, coordIndices); return new Shape3D(indexedCube, DefineAppearance()); }