Programmation des lumières

</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

SimpleLight.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.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class SimpleLight extends Applet {

  public BranchGroup createSceneGraph(SimpleUniverse u) {
    BranchGroup objRoot = new BranchGroup();
    BoundingSphere largeBounds;
    largeBounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
    BoundingSphere smallBounds;
    smallBounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),0.4);
    { Vector3f ldir = new Vector3f(1.0F,1.0F,-1.0F);
      Color3f lcouldl = new Color3f(1.0F,0.0F,0.0F);
      DirectionalLight dl = new DirectionalLight(lcouldl,ldir);
      dl.setInfluencingBounds(smallBounds);
      objRoot.addChild(dl); }
    { Color3f lcoulal = new Color3f(0.2F,0.2F,0.1F);
      AmbientLight al = new AmbientLight(lcoulal);
      al.setInfluencingBounds(largeBounds);
      objRoot.addChild(al); }
    { Point3f lpos = new Point3f(0.5F,0.0F,0.0F);
      Point3f laten = new Point3f(1.0F,1.0F,1.0F);
      Color3f lcoulpl = new Color3f(0.0F,1.0F,0.0F);
      PointLight pl = new PointLight(lcoulpl,lpos,laten);
      pl.setInfluencingBounds(largeBounds);
      objRoot.addChild(pl); }
    { Point3f lpos = new Point3f(1.0F,-0.05F,0.1F);
      Point3f laten = new Point3f(1.0F,0.0F,0.0F);
      Color3f lcoulspl = new Color3f(0.0F,0.0F,1.0F);
      Vector3f ldir = new Vector3f(-1.0F,0.0F,0.0F);
      SpotLight spl = new SpotLight(lcoulspl,lpos,laten,ldir,0.06F,0.0F);
      spl.setInfluencingBounds(largeBounds);
      objRoot.addChild(spl); }
    Appearance a = new Appearance();
    Material m = new Material();
    m.setDiffuseColor(1.0f,1.0f,1.0f);
    m.setSpecularColor(1.0f,1.0f,1.0f);
    m.setAmbientColor(1.0f,1.0f,1.0f);
    m.setShininess(25.0f);
    a.setMaterial(m);
    { TransformGroup objTrans = new TransformGroup();
      objRoot.addChild(objTrans);
      Transform3D t1 = new Transform3D();
      t1.setTranslation(new Vector3d(-0.7,0.0,0.0)) ;
      Transform3D t2 = new Transform3D();
      t1.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
      t1.mul(t2) ;
      objTrans.setTransform(t1);
      objTrans.addChild(new Sphere(0.18F,1,100,a)); }
    { TransformGroup objTrans = new TransformGroup();
      objRoot.addChild(objTrans);
      Transform3D t1 = new Transform3D();
      t1.setTranslation(new Vector3d(-0.25,0.0,0.0)) ;
      Transform3D t2 = new Transform3D();
      t1.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
      t1.mul(t2) ;
      objTrans.setTransform(t1);
      objTrans.addChild(new Cone(0.14F,0.28F,1,100,100,a)); }
    { TransformGroup objTrans = new TransformGroup();
      objRoot.addChild(objTrans);
      Transform3D t1 = new Transform3D();
      t1.setTranslation(new Vector3d(0.25,0.0,0.0)) ;
      Transform3D t2 = new Transform3D();
      t1.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
      t1.mul(t2) ;
      objTrans.setTransform(t1);
      objTrans.addChild(new Cylinder(0.14F,0.28F,1,100,100,a)); }
    { TransformGroup objTrans = new TransformGroup();
      objRoot.addChild(objTrans);
      Transform3D t1 = new Transform3D();
      t1.setTranslation(new Vector3d(0.7,0.0,0.0)) ;
      Transform3D t2 = new Transform3D();
      t1.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
      t1.mul(t2) ;
      objTrans.setTransform(t1);
      objTrans.addChild(new Box(0.05F,0.13F,0.22F,a)); }
    objRoot.compile();
    return objRoot;
    }

  public SimpleLight() {
    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 SimpleLight(),600,150);
    }
  }

RETOUR

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