List of usage examples for javax.media.j3d BranchGroup compile
public void compile()
From source file:Gouraud.java
/** * init Methoden fur die Darstellung als Applet Es muss also kein extra * Konstruktor definert werden//ww w . ja v a2 s. co m */ public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas3D = new Canvas3D(config); add("Center", canvas3D); BranchGroup szene = macheSzene(); szene.compile(); universe = new SimpleUniverse(canvas3D); universe.getViewingPlatform().setNominalViewingTransform(); universe.addBranchGraph(szene); }
From source file:Drag.java
/** * Create the scenegraph for this program. *///w w w . j av a2 s . co m public BranchGroup createSceneGraph() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.7f, 0.7f, 0.7f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4); objScale.setTransform(t3d); branchGroup.addChild(objScale); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); objScale.addChild(boundingLeaf); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); objScale.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); objScale.addChild(dirLight); // Create the red appearance node Material redMaterial = new Material(ambientRed, black, red, specular, 75.0f); redMaterial.setLightingEnable(true); Appearance redAppearance = new Appearance(); redAppearance.setMaterial(redMaterial); // Create the white appearance node Material whiteMaterial = new Material(ambient, black, diffuse, specular, 75.0f); whiteMaterial.setLightingEnable(true); Appearance whiteAppearance = new Appearance(); whiteAppearance.setMaterial(whiteMaterial); // Create the transform node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.addChild(new Cube(redAppearance).getChild()); // transformGroup.addChild(new Corners(whiteAppearance).getChild()); objScale.addChild(transformGroup); // Create the drag behavior node MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(transformGroup); transformGroup.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(); behavior2.setTransformGroup(transformGroup); transformGroup.addChild(behavior2); behavior2.setSchedulingBounds(bounds); // Create the zoom behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(transformGroup); transformGroup.addChild(behavior3); behavior3.setSchedulingBounds(bounds); // Let Java 3D perform optimizations on this scene graph. branchGroup.compile(); return branchGroup; }
From source file:InterleavedTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);/*from w w w .j a v a 2s . c om*/ transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); // load textures TextureAttributes texAttr1 = new TextureAttributes(); texAttr1.setTextureMode(TextureAttributes.DECAL); TextureAttributes texAttr2 = new TextureAttributes(); texAttr2.setTextureMode(TextureAttributes.MODULATE); TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); if (tex == null) return null; tex1 = tex.getTexture(); tex = new TextureLoader(texImage2, new String("RGB"), this); if (tex == null) return null; tex2 = tex.getTexture(); textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ModelClipTest2.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);//from w w w. j av a 2 s . c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Shine it with two colored lights. Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f); Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f); Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); AmbientLight lgt0 = new AmbientLight(true, lColor2); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt0.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt0); objScale.addChild(lgt1); objScale.addChild(lgt2); // Create a Transformgroup for the geometry TransformGroup objRot = new TransformGroup(); Transform3D t3d1 = new Transform3D(); AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f); t3d1.setRotation(rot1); objRot.setTransform(t3d1); objScale.addChild(objRot); //Create a cylinder PolygonAttributes attr = new PolygonAttributes(); attr.setCullFace(PolygonAttributes.CULL_NONE); Appearance ap = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); ap.setMaterial(mat); ap.setPolygonAttributes(attr); Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap); objRot.addChild(CylinderObj); //Create a box Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap); objRot.addChild(BoxObj); // This Transformgroup is used by the mouse manipulators to // move the model clip planes. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRot.addChild(objTrans); // Create the rotate behavior node MouseRotate behavior = new MouseRotate(objTrans); objTrans.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(objTrans); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn); mc.setEnable(1, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:InterleavedNIOBuffer.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);// w ww . ja v a 2 s .c o m transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); // load textures TextureAttributes texAttr1 = new TextureAttributes(); texAttr1.setTextureMode(TextureAttributes.DECAL); TextureAttributes texAttr2 = new TextureAttributes(); texAttr2.setTextureMode(TextureAttributes.MODULATE); TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); if (tex == null) return null; tex1 = tex.getTexture(); tex = new TextureLoader(texImage2, new String("RGB"), this); if (tex == null) return null; tex2 = tex.getTexture(); textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); createInterleavedBuffers(); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:TickTockCollision.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);//from w w w . ja v a 2 s. c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create a pair of transform group nodes and initialize them to // identity. Enable the TRANSFORM_WRITE capability so that // our behaviors can modify them at runtime. Add them to the // root of the subgraph. TransformGroup objTrans1 = new TransformGroup(); objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans1); TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans1.addChild(objTrans2); // Create the positioning and scaling transform group node. Transform3D t = new Transform3D(); t.set(0.3, new Vector3d(0.0, -1.5, 0.0)); TransformGroup objTrans3 = new TransformGroup(t); objTrans2.addChild(objTrans3); // Create a simple shape leaf node, add it to the scene graph. objTrans3.addChild(new ColorCube()); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis1 = new Transform3D(); yAxis1.rotX(Math.PI / 2.0); Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500, 200, 5000, 2500, 200); RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1, -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f); tickTock.setSchedulingBounds(bounds); objTrans2.addChild(tickTock); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis2 = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Now create a pair of rectangular boxes, each with a collision // detection behavior attached. The behavior will highlight the // object when it is in a state of collision. Group box1 = createBox(0.3, new Vector3d(-1.3, 0.0, 0.0)); Group box2 = createBox(0.3, new Vector3d(1.3, 0.0, 0.0)); objScale.addChild(box1); objScale.addChild(box2); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:PickTest.java
public BranchGroup createSceneGraph(Canvas3D canvas) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(1.0);//w ww . j av a 2s. co m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; int numRows = 4, numCols = 4; for (int i = 0; i < numRows; i++) { double ypos = (double) (i - numRows / 2) * 0.45 + 0.25; for (int j = 0; j < numCols; j++) { double xpos = (double) (j - numCols / 2) * 0.45 + 0.25; objScale.addChild(createObject(i * numCols + j, 0.1, xpos, ypos)); } } BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Add a light. Color3f lColor = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt = new DirectionalLight(lColor, lDir); lgt.setInfluencingBounds(bounds); objRoot.addChild(lgt); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 1000, 500, 4000, 1000, 500); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objRoot.addChild(mBeh); behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior1); behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior2); behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:PolygonOffset.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);//from w ww.ja v a 2 s . c om // Create a Sphere. We will display this as both wireframe and // solid to make a hidden line display // wireframe Appearance wireApp = new Appearance(); ColoringAttributes wireCa = new ColoringAttributes(); wireCa.setColor(black); wireApp.setColoringAttributes(wireCa); wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f); wireApp.setPolygonAttributes(wirePa); Sphere outWireSphere = new Sphere(sphereRadius, 0, 15, wireApp); objTrans.addChild(outWireSphere); // solid ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT); Appearance outSolid = new Appearance(); outSolid.setColoringAttributes(outCa); solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f); solidPa.setPolygonOffsetFactor(dynamicOffset); solidPa.setPolygonOffset(staticOffset); solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); outSolid.setPolygonAttributes(solidPa); Sphere outSolidSphere = new Sphere(sphereRadius, 0, 15, outSolid); objTrans.addChild(outSolidSphere); innerTG = new TransformGroup(); innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); scale = new Transform3D(); updateInnerScale(); objTrans.addChild(innerTG); // Create a smaller sphere to go inside. This sphere has a different // tesselation and color Sphere inWireSphere = new Sphere(sphereRadius, 0, 10, wireApp); innerTG.addChild(inWireSphere); // inside solid ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); Appearance inSolid = new Appearance(); inSolid.setColoringAttributes(inCa); inSolid.setPolygonAttributes(solidPa); Sphere inSolidSphere = new Sphere(sphereRadius, 0, 10, inSolid); innerTG.addChild(inSolidSphere); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // set up a white background Background bgWhite = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bgWhite.setApplicationBounds(bounds); objTrans.addChild(bgWhite); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
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();//from w w w . j a v a2s. c o m 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: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);//ww w.ja va 2 s. co 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); }