List of usage examples for javax.media.j3d PointLight setPosition
public void setPosition(float x, float y, float z)
From source file:LightScopeApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); TransformGroup tableTG = new TransformGroup(); TransformGroup lampTG = new TransformGroup(); TransformGroup litBoxTG = new TransformGroup(); TransformGroup unLitBoxTG = new TransformGroup(); scene.addChild(tableTG);/* w w w.ja va2 s. com*/ tableTG.addChild(lampTG); tableTG.addChild(litBoxTG); tableTG.addChild(unLitBoxTG); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.0f, 1.0f, 0.0f); Color3f green = new Color3f(0.0f, 0.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Vector3f transVector = new Vector3f(); Transform3D transTransform = new Transform3D(); transVector.set(0.0f, -0.4f, 0.5f); transTransform.setTranslation(transVector); tableTG.setTransform(transTransform); transVector.set(-0.4f, 0.001f, 0.1f); transTransform.setTranslation(transVector); lampTG.setTransform(transTransform); transVector.set(-0.2f, 0.1f, 0.2f); transTransform.setTranslation(transVector); litBoxTG.setTransform(transTransform); transVector.set(0.3f, 0.1f, -0.4f); transTransform.setTranslation(transVector); unLitBoxTG.setTransform(transTransform); Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f)); tablePlane.setAppearance(createMaterialAppearance(white)); tableTG.addChild(tablePlane); litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red))); Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f), new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f)); shadowPlane.setAppearance(createMaterialAppearance(black)); litBoxTG.addChild(shadowPlane); Appearance redGlowMat = createMaterialAppearance(red); // redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f); unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat)); Shape3D lamp = createLampShape(); Appearance lampAppearance = createMaterialAppearance(blue); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setBackFaceNormalFlip(true); lampAppearance.setPolygonAttributes(polyAttrib); lamp.setAppearance(lampAppearance); lampTG.addChild(lamp); PointLight lampLight = new PointLight(); lampLight.setPosition(0.1f, 0.5f, -0.1f); lampLight.setInfluencingBounds(new BoundingSphere()); lampTG.addChild(lampLight); Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f)); litPlane.setAppearance(createMaterialAppearance(white)); lampTG.addChild(litPlane); lampLight.addScope(lampTG); lampLight.addScope(litBoxTG); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f)); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD1.setDirection(lightDir); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); lightDir.set(1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD2.setDirection(lightDir); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }