Java Reference
In-Depth Information
Figures 12 and 13 give the important code segment demonstrating how fog can be used
in Java 3D. Specifically, after getting appropriate user inputs, a constructor for fog, which
may be linear or exponential in nature, is invoked in either line 34 or 35 in Figure 13.
Linear fog uses a blending factor given by
backDistan
ce
DistanceFr
omViewPort
f
=
linear
backDistan
ce
frontDista
nce
,
where frontDistance is the distance at which objects will start to be obscured by the fog,
and backDistance is the distance at which objects will become fully obscured. Linear fog
has the advantage that it is easier to render, but the effect may however be not so natural.
Figure 13. Second code segment for fogdemo.java
27. Alpha alp=new Alpha(-1,5000); // create the animation path
28. Transform3D zaxis=new Transform3D(); zaxis.rotZ(Math.PI/2f);
29. float knot[]={0f,1f}; Point3f pos[]={new Point3f(0f,1.5f,0f),new Point3f(0f,1.5f,-400f)};
30. PositionPathInterpolator ppi=new PositionPathInterpolator(alp,tvg,zaxis,knot,pos);
31. tvg.addChild(ppi); ppi.setSchedulingBounds(new BoundingSphere(new Point3d(),600.0));
32.
33. Fog fogb=null; // create fog and its back clip distance
34. if (FogMode==2) fogb=new ExponentialFog(0f,0f,1f,density);
35. if (FogMode==1) fogb=new LinearFog(0f,0f,1f,fogfront,fogback);
36. Clip clip=new Clip(backClip);
37. clip.setApplicationBounds(new BoundingSphere(new Point3d(),backClip));
38. tvg.addChild(clip);
39. if (fogb!=null){
40. fogb.setInfluencingBounds(new BoundingSphere(new Point3d(),fogdist));
41. tvg.addChild(fogb); }
42.
43. View view=simpleu.getViewer().getView(); // modify view branch
44. view.setBackClipDistance(300.0f); view.setFrontClipDistance(0.1); view.attachViewPlatform(vp);
45. BranchGroup brg=new BranchGroup();
46. brg.addChild(tvg);
47.
48. BranchGroup bgs=new BranchGroup(); // create the scene graph
49. bgs.addChild(new shape()); bgs.addChild(building(buildings));
50. DirectionalLight lit =new DirectionalLight(new Color3f( 0.5f, 1.0f, 0.5f),new Vector3f( -2f,-2f,0f));
51. lit.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));
52. bgs.addChild(lit);
53. lit = new DirectionalLight(new Color3f( 0.5f, 0.5f, 1.0f),new Vector3f( 2f,-2f,0f));
54. lit.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));
55. bgs.addChild(lit);
56. Background bg=new Background(new Color3f(0f,0f,1f));
57. bgs.addChild(bg);
58. bg.setApplicationBounds(new BoundingSphere(new Point3d(),1500.0));
59. bgs.compile(); }
Search WWH ::




Custom Search