List of usage examples for javax.media.j3d IndexedQuadArray setNormals
public void setNormals(int index, float normals[])
From source file:SimpleMorph.java
/** * Build the content branch for the scene graph * // ww w . j a v a 2s.co m * @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:SimpleMorph2.java
/** * Build the content branch for the scene graph * //from w w w .j av a 2 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:SimpleCollision2.java
/** * Creates the content branch of the scene graph. * /*from w ww . j a va 2s .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)); //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. * //www . java2s .com * @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: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./*from w w w . j a va 2 s. com*/ * * @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: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 a v a2s . c o 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: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. * //w w w . j ava2s . c om * @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:AppearanceExplorer.java
Shape3D createColorCube() { // color cube int[] indices = { 0, 3, 4, 2, // left face x = -1 0, 1, 5, 3, // bottom face y = -1 0, 2, 6, 1, // back face z = -1 7, 5, 1, 6, // right face x = 1 7, 6, 2, 4, // top face y = 1 7, 4, 3, 5 // front face z = 1 };//w w w . j a va2s.c o m Point3f pts[] = new Point3f[8]; pts[0] = new Point3f(-1.0f, -1.0f, -1.0f); pts[1] = new Point3f(1.0f, -1.0f, -1.0f); pts[2] = new Point3f(-1.0f, 1.0f, -1.0f); pts[3] = new Point3f(-1.0f, -1.0f, 1.0f); pts[4] = new Point3f(-1.0f, 1.0f, 1.0f); pts[5] = new Point3f(1.0f, -1.0f, 1.0f); pts[6] = new Point3f(1.0f, 1.0f, -1.0f); pts[7] = new Point3f(1.0f, 1.0f, 1.0f); Color3f colr[] = new Color3f[8]; colr[0] = black; colr[1] = red; colr[2] = green; colr[3] = blue; colr[4] = cyan; colr[5] = magenta; colr[6] = yellow; colr[7] = white; // The normals point out from 0,0,0, through the verticies of the // cube. These can be calculated by copying the coordinates to // a Vector3f and normalizing. Vector3f norm[] = new Vector3f[8]; for (int i = 0; i < 8; i++) { norm[i] = new Vector3f(pts[i]); norm[i].normalize(); } IndexedQuadArray iqa = new IndexedQuadArray(8, GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.NORMALS, 24); iqa.setCoordinates(0, pts); iqa.setColors(0, colr); iqa.setNormals(0, norm); iqa.setCoordinateIndices(0, indices); iqa.setColorIndices(0, indices); iqa.setNormalIndices(0, indices); return new Shape3D(iqa, appearance); }
From source file:ExSound.java
private Shape3D buildBox(float width, float height, float depth, Appearance app) { float w2 = width / 2.0f; float h2 = height / 2.0f; float d2 = depth / 2.0f; float[] coordinates = new float[8 * 3]; int n = 0;//from www .j a va 2s . c om // Around the bottom of the box coordinates[n + 0] = -w2; coordinates[n + 1] = -h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = -h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = -h2; coordinates[n + 2] = -d2; n += 3; coordinates[n + 0] = -w2; coordinates[n + 1] = -h2; coordinates[n + 2] = -d2; n += 3; // Around the top of the box coordinates[n + 0] = -w2; coordinates[n + 1] = h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = h2; coordinates[n + 2] = d2; n += 3; coordinates[n + 0] = w2; coordinates[n + 1] = h2; coordinates[n + 2] = -d2; n += 3; coordinates[n + 0] = -w2; coordinates[n + 1] = h2; coordinates[n + 2] = -d2; n += 3; IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // vertex // count GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, coordinateIndices.length); quads.setCoordinates(0, coordinates); quads.setCoordinateIndices(0, coordinateIndices); quads.setNormals(0, normals); quads.setNormalIndices(0, normalIndices); quads.setTextureCoordinates(0, textureCoordinates); quads.setTextureCoordinateIndices(0, textureCoordinateIndices); Shape3D shape = new Shape3D(quads, app); return shape; }
From source file:ExLinearFog.java
private void addCylinder(float radius, float height, float y) { //// w w w . j a v a2 s . c o m // Compute coordinates, normals, and texture coordinates // around the top and bottom of a cylinder // float[] coordinates = new float[NSTEPS * 2 * 3]; // xyz float[] normals = new float[NSTEPS * 2 * 3]; // xyz vector float[] textureCoordinates = new float[NSTEPS * 2 * 2]; // st float angle = 0.0f; float deltaAngle = 2.0f * (float) Math.PI / ((float) NSTEPS - 1); float s = 0.0f; float deltaS = 1.0f / ((float) NSTEPS - 1); int n = 0; int tn = 0; float h2 = height / 2.0f; for (int i = 0; i < NSTEPS; i++) { // bottom normals[n + 0] = (float) Math.cos(angle); normals[n + 1] = 0.0f; normals[n + 2] = -(float) Math.sin(angle); coordinates[n + 0] = radius * normals[n + 0]; coordinates[n + 1] = -h2; coordinates[n + 2] = radius * normals[n + 2]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 0.0f; n += 3; tn += 2; // top normals[n + 0] = normals[n - 3]; normals[n + 1] = 0.0f; normals[n + 2] = normals[n - 1]; coordinates[n + 0] = coordinates[n - 3]; coordinates[n + 1] = h2; coordinates[n + 2] = coordinates[n - 1]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 1.0f; n += 3; tn += 2; angle += deltaAngle; s += deltaS; } // // Compute coordinate indexes, normal indexes, and texture // coordinate indexes awround the sides of a cylinder. // For this application, we don't need top or bottom, so // skip them. // int[] indexes = new int[NSTEPS * 4]; n = 0; int p = 0; // panel count for (int i = 0; i < NSTEPS - 1; i++) { indexes[n + 0] = p; // bottom left indexes[n + 1] = p + 2; // bottom right (next panel) indexes[n + 2] = p + 3; // top right (next panel) indexes[n + 3] = p + 1; // top left n += 4; p += 2; } indexes[n + 0] = p; // bottom left indexes[n + 1] = 0; // bottom right (next panel) indexes[n + 2] = 1; // top right (next panel) indexes[n + 3] = p + 1; // top left IndexedQuadArray quads = new IndexedQuadArray(coordinates.length / 3, // number // of // vertexes GeometryArray.COORDINATES | // format GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexes.length); // number // of // indexes quads.setCoordinates(0, coordinates); quads.setTextureCoordinates(0, textureCoordinates); quads.setNormals(0, normals); quads.setCoordinateIndices(0, indexes); quads.setTextureCoordinateIndices(0, indexes); quads.setNormalIndices(0, indexes); Shape3D shape = new Shape3D(quads, mainAppearance); Vector3f trans = new Vector3f(0.0f, y, 0.0f); Transform3D tr = new Transform3D(); tr.set(trans); // translate TransformGroup tg = new TransformGroup(tr); tg.addChild(shape); addChild(tg); }