List of usage examples for javax.media.j3d LineStripArray LineStripArray
public LineStripArray(int vertexCount, int vertexFormat, int stripVertexCounts[])
From source file:BackgroundApp.java
public BranchGroup createBackGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); PointArray starGeom1 = new PointArray(7, PointArray.COORDINATES); Appearance starAppear1 = new Appearance(); starGeom1.setCoordinate(0, new Point3f(0.79483311f, -0.58810995f, 0.14955615f)); starGeom1.setCoordinate(1, new Point3f(0.44430932f, -0.55736839f, -0.70137505f)); starGeom1.setCoordinate(2, new Point3f(0.94901367f, -0.30404968f, 0.08322775f)); starGeom1.setCoordinate(3, new Point3f(0.68060123f, -0.43044807f, 0.59287173f)); starGeom1.setCoordinate(4, new Point3f(-0.11641672f, 0.47273532f, 0.87348049f)); starGeom1.setCoordinate(5, new Point3f(-0.10399289f, -0.98059412f, 0.16619437f)); starGeom1.setCoordinate(6, new Point3f(0.08024400f, -0.96944100f, -0.23182900f)); PointAttributes point1 = new PointAttributes(4.0f, false); starAppear1.setPointAttributes(point1); objRoot.addChild(new Shape3D(starGeom1, starAppear1)); PointArray starGeom2 = new PointArray(18, PointArray.COORDINATES); starGeom2.setCoordinate(0, new Point3f(0.050844f, -0.992329f, 0.112678f)); starGeom2.setCoordinate(1, new Point3f(-0.063091f, -0.997672f, 0.025869f)); starGeom2.setCoordinate(2, new Point3f(0.096706f, -0.980384f, 0.171736f)); starGeom2.setCoordinate(3, new Point3f(-0.562384f, 0.073568f, 0.823595f)); starGeom2.setCoordinate(4, new Point3f(-0.863904f, 0.059045f, 0.500180f)); starGeom2.setCoordinate(5, new Point3f(-0.727033f, 0.304149f, 0.615559f)); starGeom2.setCoordinate(6, new Point3f(-0.724850f, 0.535590f, 0.433281f)); starGeom2.setCoordinate(7, new Point3f(0.185904f, -0.976907f, -0.105311f)); starGeom2.setCoordinate(8, new Point3f(0.738028f, -0.531886f, -0.415221f)); starGeom2.setCoordinate(9, new Point3f(-0.402152f, 0.392690f, -0.827085f)); starGeom2.setCoordinate(10, new Point3f(-0.020020f, -0.999468f, -0.025724f)); starGeom2.setCoordinate(11, new Point3f(-0.384103f, -0.887075f, 0.256050f)); starGeom2.setCoordinate(12, new Point3f(-0.224464f, -0.968946f, -0.103720f)); starGeom2.setCoordinate(13, new Point3f(-0.828880f, -0.397932f, -0.393203f)); starGeom2.setCoordinate(14, new Point3f(-0.010557f, -0.998653f, 0.050797f)); starGeom2.setCoordinate(15, new Point3f(-0.282122f, 0.258380f, -0.923930f)); starGeom2.setCoordinate(16, new Point3f(-0.941342f, -0.030364f, 0.336082f)); starGeom2.setCoordinate(17, new Point3f(0.00057f, -0.99651f, -0.08344f)); Appearance starAppear2 = new Appearance(); PointAttributes point2 = new PointAttributes(2.0f, false); starAppear2.setPointAttributes(point2); objRoot.addChild(new Shape3D(starGeom2, starAppear2)); PointArray starGeom3 = new PointArray(20, PointArray.COORDINATES); starGeom3.setCoordinate(0, new Point3f(0.07292f, -0.98862f, -0.13153f)); starGeom3.setCoordinate(1, new Point3f(0.23133f, -0.87605f, -0.42309f)); starGeom3.setCoordinate(2, new Point3f(-0.08215f, -0.64657f, 0.75840f)); starGeom3.setCoordinate(3, new Point3f(-0.84545f, 0.53398f, 0.00691f)); starGeom3.setCoordinate(4, new Point3f(-0.49365f, -0.83645f, -0.23795f)); starGeom3.setCoordinate(5, new Point3f(0.06883f, -0.99319f, -0.09396f)); starGeom3.setCoordinate(6, new Point3f(0.87582f, -0.40662f, 0.25997f)); starGeom3.setCoordinate(7, new Point3f(-0.09095f, -0.99555f, 0.02467f)); starGeom3.setCoordinate(8, new Point3f(0.45306f, -0.81575f, -0.35955f)); starGeom3.setCoordinate(9, new Point3f(0.17669f, -0.97939f, 0.09776f)); starGeom3.setCoordinate(10, new Point3f(0.27421f, -0.83963f, 0.46884f)); starGeom3.setCoordinate(11, new Point3f(0.32703f, -0.94013f, -0.09584f)); starGeom3.setCoordinate(12, new Point3f(-0.01615f, -0.99798f, -0.06132f)); starGeom3.setCoordinate(13, new Point3f(-0.76665f, 0.45998f, -0.44791f)); starGeom3.setCoordinate(14, new Point3f(-0.91025f, -0.07102f, 0.40791f)); starGeom3.setCoordinate(15, new Point3f(-0.00240f, -0.97104f, -0.23887f)); starGeom3.setCoordinate(16, new Point3f(0.91936f, -0.39244f, 0.02740f)); starGeom3.setCoordinate(17, new Point3f(0.18290f, -0.97993f, 0.07920f)); starGeom3.setCoordinate(18, new Point3f(-0.48755f, 0.61592f, 0.61884f)); starGeom3.setCoordinate(19, new Point3f(-0.89375f, 0.36087f, -0.26626f)); objRoot.addChild(new Shape3D(starGeom3)); int[] stripCount = { 10 }; LineStripArray orion = new LineStripArray(10, LineStripArray.COORDINATES, stripCount); orion.setCoordinate(0, new Point3f(0.978330f, -0.033900f, 0.204426f)); orion.setCoordinate(1, new Point3f(0.968007f, -0.167860f, 0.186506f)); orion.setCoordinate(2, new Point3f(0.981477f, -0.142660f, 0.127873f)); orion.setCoordinate(3, new Point3f(0.983764f, -0.005220f, 0.179391f)); orion.setCoordinate(4, new Point3f(0.981112f, 0.110597f, 0.158705f)); orion.setCoordinate(5, new Point3f(0.967377f, 0.172516f, 0.185523f)); orion.setCoordinate(6, new Point3f(0.961385f, 0.128845f, 0.243183f)); orion.setCoordinate(7, new Point3f(0.978330f, -0.033900f, 0.204426f)); orion.setCoordinate(8, new Point3f(0.981293f, -0.020980f, 0.191375f)); orion.setCoordinate(9, new Point3f(0.983764f, -0.005220f, 0.179391f)); objRoot.addChild(new Shape3D(orion)); objRoot.compile();// w w w.java 2s . com return objRoot; }
From source file:ViewProj.java
public BranchGroup createVWorldViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); objRoot.addChild(objTrans);//from w ww . j a v a 2 s. c om // get the eye point, field of view and clip distances float fov = (float) view.getFieldOfView(); // figure out the angle factors to find points along the edges // of the FOV // X = fovSpreadX * (Y - eyeVW.y) + eyeVW.x; float fovSpreadX = (float) Math.tan(fov / 2); // Z = fovSpreadZ * (X - eyeVW.x) + eyeVW.z; float fovSpreadZ = 1.0f / fovSpreadX; //System.out.println("fovSpreadX = " + fovSpreadX); //System.out.println("fovSpreadZ = " + fovSpreadZ); Transform3D vpTransform = new Transform3D(); viewingPlatform.getViewPlatformTransform().getTransform(vpTransform); Vector3f vpTranslation = new Vector3f(); vpTransform.get(vpTranslation); eyePtVW.set(vpTranslation); eyePtVW.negate(); // get the eye point in our 2D coord system. Point3f eyePt = new Point3f(0.0f, eyePtVW.z, 0.1f); float frontClipDist = (float) view.getFrontClipDistance(); float backClipDist = (float) view.getBackClipDistance(); // set up the clip plane lines Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(frontClipDist * fovSpreadX, eyePtVW.z + frontClipDist, 0.1f); cpPoints[1] = new Point3f(cpPoints[0]); cpPoints[1].x *= -1; Point3f backLeft = new Point3f(-backClipDist * fovSpreadX, eyePtVW.z + backClipDist, 0.1f); cpPoints[2] = backLeft; Point3f backRight = new Point3f(backLeft); backRight.x *= -1; cpPoints[3] = backRight; cpPoints[4] = cpPoints[0]; //for (int i = 0; i < 4; i++) { // System.out.println("cpPoints[" + i + "] = " + cpPoints[i]); //} int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // get the limits of the space float minY = eyePt.y; float maxY = backLeft.y; float minX = backLeft.x; float maxX = backRight.x; // figure out the X and Y extents and offsets float deltaX = maxX - minX; float deltaY = maxY - minY; float offsetX = -(maxX + minX) / 2.0f; float offsetY = -(maxY + minY) / 2.0f; float gridSize = Math.max(deltaX, deltaY); // scale the grid slightly to give a border around the edge gridSize *= 1.1f; //System.out.println("offsetX = " + offsetX); //System.out.println("offsetY = " + offsetY); // Scale the view to fit -1 to 1 Transform3D trans = new Transform3D(); trans.set(new Vector3f(offsetX, offsetY, 0.0f), 2.0f / gridSize); objTrans.setTransform(trans); // figure out a grid step that is a multiple of 10 which keeps the // number of steps less than 30. float gridStep = 1.0f; while ((gridSize / gridStep) > 30.0) { gridStep *= 10; } int gridNumSteps = (int) Math.ceil(gridSize / gridStep) + 1; // allocate the grid points array, four points for each step (x and y) // with a couple extra points for the extra grid points added // below int gridNumPoints = 4 * (gridNumSteps + 4); Point3f[] gridPts = new Point3f[gridNumPoints]; for (int i = 0; i < gridNumPoints; i++) { gridPts[i] = new Point3f(); } // find the grid limits. Add a step on each side to make sure // the grid is larger than the view float gridMinY = gridStepFloor(minY, gridStep) - gridStep; float gridMaxY = gridStepCeil(maxY, gridStep) + gridStep; float gridMinX = gridStepFloor(minX, gridStep) - gridStep; float gridMaxX = gridStepCeil(maxX, gridStep) + gridStep; //System.out.println("gridMinY = " + gridMinY); //System.out.println("gridMaxY = " + gridMaxY); //System.out.println("gridMinX = " + gridMinX); //System.out.println("gridMaxX = " + gridMaxX); // set up the background grid Appearance bgApp = new Appearance(); ColoringAttributes bgCa = new ColoringAttributes(); bgCa.setColor(grey); LineAttributes bgLa = new LineAttributes(); bgApp.setColoringAttributes(bgCa); // clear out the clip grid point list numClipGridPts = 0; // set up the vertical lines int numPts = 0; for (float x = gridMinX; x <= gridMaxX; x += gridStep) { gridPts[numPts].x = x; gridPts[numPts].y = gridMinY; gridPts[numPts].z = -0.2f; gridPts[numPts + 1].x = x; gridPts[numPts + 1].y = gridMaxY; gridPts[numPts + 1].z = -0.2f; numPts += 2; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipZ = fovSpreadZ * Math.abs(x - eyePtVW.x); if (clipZ < frontClipDist) { // clip to front clip plane clipZ = frontClipDist; } if (clipZ < backClipDist) { // clip to back clip plane // line is not clipped clipGridPtsVW[numClipGridPts].x = x; clipGridPtsVW[numClipGridPts].y = clipZ + eyePtVW.z; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = x; clipGridPtsVW[numClipGridPts + 1].y = backClipDist + eyePtVW.z; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray vertLa = new LineArray(numPts, LineArray.COORDINATES); vertLa.setCoordinates(0, gridPts, 0, numPts); Shape3D vertShape = new Shape3D(vertLa, bgApp); objTrans.addChild(vertShape); // set up the horizontal lines numPts = 0; for (float y = gridMinY; y <= gridMaxY; y += gridStep) { gridPts[numPts].x = gridMinX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; gridPts[numPts].x = gridMaxX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipDist = (y - eyePtVW.z); if ((clipDist > frontClipDist) && (clipDist < backClipDist)) { float clipX = fovSpreadX * clipDist; clipGridPtsVW[numClipGridPts].x = -clipX; clipGridPtsVW[numClipGridPts].y = y; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = clipX; clipGridPtsVW[numClipGridPts + 1].y = y; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray horizLa = new LineArray(numPts, LineArray.COORDINATES); horizLa.setCoordinates(0, gridPts, 0, numPts); Shape3D horizShape = new Shape3D(horizLa, bgApp); objTrans.addChild(horizShape); // draw the clipped grid. if (numClipGridPts > 0) { LineArray clipLa = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLa.setCoordinates(0, clipGridPtsVW, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipGridLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLa, clipGridApp); objTrans.addChild(clipShape); } // set up the coordinate system Appearance coordSysApp = new Appearance(); LineAttributes coordSysLa = new LineAttributes(); coordSysLa.setLineWidth(3.0f); coordSysApp.setLineAttributes(coordSysLa); ColoringAttributes coordSysCa = new ColoringAttributes(grey, ColoringAttributes.SHADE_FLAT); coordSysApp.setColoringAttributes(coordSysCa); Point3f[] coordSysPts = new Point3f[4]; coordSysPts[0] = new Point3f(gridMinX, 0, -0.5f); coordSysPts[1] = new Point3f(gridMaxX, 0, -0.5f); coordSysPts[2] = new Point3f(0, gridMinY, -0.5f); coordSysPts[3] = new Point3f(0, gridMaxY, -0.5f); LineArray coordSysLines = new LineArray(4, LineArray.COORDINATES); coordSysLines.setCoordinates(0, coordSysPts); Shape3D coordSysShape = new Shape3D(coordSysLines, coordSysApp); objTrans.addChild(coordSysShape); // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); int step = 360 / (numCirclePts - 1); for (int deg = 0; deg < 360; deg += step) { double angle = Math.toRadians(deg); circlePtsVW[deg / 10].x = sphereRadius * (float) Math.sin(angle); circlePtsVW[deg / 10].y = sphereRadius * (float) Math.cos(angle); circlePtsVW[deg / 10].z = -0.3f; } circlePtsVW[numCirclePts - 1].set(circlePtsVW[0]); int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsVW); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
From source file:GeomInfoApp.java
public BranchGroup createSceneGraph(boolean wireFrame) { int total = 0; System.out.println("\n --- geometry debug information --- \n"); float[] coordinateData = null; coordinateData = createCoordinateData(); int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ****** // int[] stripCount = {17,17,17}; // ****** for (int i = 0; i < stripCount.length; i++) { System.out.println("stripCount[" + i + "] = " + stripCount[i]); total += stripCount[i];//from w ww . ja v a 2 s . c o m } if (total != coordinateData.length / 3) { System.out.println(" coordinateData vertex count: " + coordinateData.length / 3); System.out.println("stripCount total vertex count: " + total); } GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(coordinateData); gi.setStripCounts(stripCount); Triangulator tr = new Triangulator(); // Triangulator tr = new Triangulator(1); System.out.println("begin triangulation"); tr.triangulate(gi); System.out.println(" END triangulation"); gi.recomputeIndices(); NormalGenerator ng = new NormalGenerator(); ng.generateNormals(gi); gi.recomputeIndices(); Stripifier st = new Stripifier(); st.stripify(gi); gi.recomputeIndices(); Shape3D part = new Shape3D(); if (wireFrame == true) part.setAppearance(createWireFrameAppearance()); else part.setAppearance(createMaterialAppearance()); part.setGeometry(gi.getGeometryArray()); ///////////////////////////// BranchGroup contentRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentRoot.addChild(objSpin); objSpin.addChild(part); //////////////////////// LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //***** // LineStripArray lineArray = new LineStripArray(51, // LineArray.COORDINATES, stripCount); //***** lineArray.setCoordinates(0, coordinateData); Appearance blueColorAppearance = new Appearance(); ColoringAttributes blueColoring = new ColoringAttributes(); blueColoring.setColor(0.0f, 0.0f, 1.0f); blueColorAppearance.setColoringAttributes(blueColoring); LineAttributes lineAttrib = new LineAttributes(); lineAttrib.setLineWidth(2.0f); blueColorAppearance.setLineAttributes(lineAttrib); objSpin.addChild(new Shape3D(lineArray, blueColorAppearance)); Alpha rotationAlpha = new Alpha(-1, 16000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 1 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f)); lightD.setInfluencingBounds(bounds); contentRoot.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); contentRoot.addChild(lightA); Background background = new Background(); background.setColor(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); contentRoot.addChild(background); // Let Java 3D perform optimizations on this scene graph. // contentRoot.compile(); return contentRoot; }
From source file:AppearanceExplorer.java
Shape3D createLineStripArray() { int[] stripLengths = new int[2]; stripLengths[0] = 3;/* w w w .jav a2s . c om*/ stripLengths[1] = 2; Point3f pnt[] = new Point3f[5]; // first line 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); // second line pnt[3] = new Point3f(0.5f, 0.5f, 0.0f); pnt[4] = new Point3f(-0.5f, -0.5f, 0.0f); LineStripArray lsa = new LineStripArray(5, GeometryArray.COORDINATES, stripLengths); lsa.setCoordinates(0, pnt); return new Shape3D(lsa, appearance); }
From source file:ViewProj.java
public BranchGroup createProjViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); Transform3D scale = new Transform3D(); scale.set(0.9);//from www .ja va 2 s .com objTrans.setTransform(scale); objRoot.addChild(objTrans); // create the clip limits line Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(-1, -1, 0.1f); cpPoints[1] = new Point3f(1, -1, 0.1f); cpPoints[2] = new Point3f(1, 1, 0.1f); cpPoints[3] = new Point3f(-1, 1, 0.1f); cpPoints[4] = cpPoints[0]; int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); LineAttributes cpLa = new LineAttributes(); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // transform and render the clip grid points updateProjTrans(); if (numClipGridPts > 0) { // transform the clipGridPts for (int i = 0; i < numClipGridPts; i++) { projectPoint(clipGridPtsVW[i], clipGridPtsProj[i]); } LineArray clipLn = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLn.setCoordinates(0, clipGridPtsProj, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLn, clipGridApp); objTrans.addChild(clipShape); } // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); // transform the circlePts for (int i = 0; i < numCirclePts; i++) { projectPoint(circlePtsVW[i], circlePtsProj[i]); } int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsProj); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }