Gestion d'un brouillard

</COMMENT> alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." Your browser is completely ignoring the &lt;APPLET&gt; tag!

RETOUR

SimpleFog.java

/* Auteur: Nicolas JANEY         */
/* nicolas.janey@univ-fcomte.fr  */
/* Novembre 2001                 */

import java.applet.Applet;
import java.awt.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class SimpleFog extends Applet {

  public BranchGroup createSceneGraph(SimpleUniverse u) {
    BranchGroup objRoot = new BranchGroup();
    BoundingSphere bounds;
    bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
    { Background bg = new Background(new Color3f(0.5f,0.5f,0.5f)) ;
      bg.setApplicationBounds(bounds) ;
      objRoot.addChild(bg); }
    { LinearFog lf = new LinearFog(0.5f,0.5f,0.5f);
      lf.setFrontDistance(1.2);
      lf.setBackDistance(1.9);
      lf.setInfluencingBounds(bounds);
      objRoot.addChild(lf); }
    { Vector3f ldir = new Vector3f(1.0F,1.0F,-1.0F);
      Color3f lcouldl = new Color3f(1.0F,1.0F,1.0F);
      DirectionalLight dl = new DirectionalLight(lcouldl,ldir);
      dl.setInfluencingBounds(bounds);
      objRoot.addChild(dl); }
    TransformGroup objTrans0 = new TransformGroup();
    Transform3D t3D = new Transform3D();
    t3D.rotY(1.57);
    objTrans0.setTransform(t3D);
    objRoot.addChild(objTrans0);
    TransformGroup objTrans = new TransformGroup();
    objTrans0.addChild(objTrans);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D trans = new Transform3D();
    Alpha transAlpha;
    transAlpha = new Alpha(-1,
                           Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE,
                           0,0,
                           2000,0,0,
                           2000,0,0);
    PositionInterpolator translator;
    translator = new PositionInterpolator(
                  transAlpha,
                  objTrans,trans,
                  0.0f,-1.0f);
    translator.setSchedulingBounds(bounds);
    objTrans.addChild(translator);
    Appearance a = new Appearance();
    Material m = new Material();
    m.setDiffuseColor(0.9f,0.3f,0.3f);    
    a.setMaterial(m);
    objTrans.addChild(new Sphere(0.4F,1,70,a));
    objRoot.compile();
    return objRoot;
    }

  public SimpleFog() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config;
    config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center",c);
    SimpleUniverse u = new SimpleUniverse(c);
    BranchGroup scene = createSceneGraph(u);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
    }

  public static void main(String[] args) {
    new MainFrame(new SimpleFog(),300,250);
    }
  }

RETOUR

Remarques,erreurs
nicolas.janey@univ-fcomte.fr