Projection en perspective ou projection parallèle

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

SimpleOrthoPersp.java

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

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
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 SimpleOrthoPersp extends Applet implements MouseListener {

  private View view;
  private boolean mode = true;

  public BranchGroup createSceneGraph(SimpleUniverse u) {
    BranchGroup objRoot = new BranchGroup();
    BoundingSphere bounds;
    bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
    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);
    Color3f lcoulal = new Color3f(0.3F,0.3F,0.1F);
    AmbientLight al = new AmbientLight(lcoulal);
    al.setInfluencingBounds(bounds);
    objRoot.addChild(al);
    { TransformGroup objTrans = new TransformGroup();
      objRoot.addChild(objTrans);
      Transform3D t1 = new Transform3D();
      t1.setTranslation(new Vector3d(0.0,0.1,0.9)) ;
      Transform3D t2 = new Transform3D();
      t1.setRotation(new AxisAngle4d(1.0,1.0,0.0,Math.PI/5.0)) ;
      t1.mul(t2) ;
      objTrans.setTransform(t1);
      Appearance a = new Appearance();
      Material m = new Material();
      m.setDiffuseColor(0.9f,0.8f,0.4f);
      m.setAmbientColor(0.6f,0.0f,0.6f);
      a.setMaterial(m);
      objTrans.addChild(new Box(0.1F,0.25F,0.50F,a)); }
    objRoot.compile();
    return objRoot;
    }

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

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

  public void mouseClicked(MouseEvent e) {
    } 

  public void mouseEntered(MouseEvent e) {
    }

  public void mouseExited(MouseEvent e) {
    }

  public void mousePressed(MouseEvent e) {
    mode = !mode;
    if ( mode )
      view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
      else
      view.setProjectionPolicy(View.PARALLEL_PROJECTION);
    }

  public void mouseReleased(MouseEvent e) {
    }
  }

RETOUR

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