Une scène vide avec un fond

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

SimpleBackground.class

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

SimpleBackground2.class

RETOUR

SimpleBackground.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 SimpleBackground 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);
    { Background bg = new Background(new Color3f(0.5f,0.5f,0.5f)) ;
      bg.setApplicationBounds(largeBounds) ;
      objRoot.addChild(bg); }
    objRoot.compile();
    return objRoot;
    }

  public SimpleBackground() {
    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 SimpleBackground(),450,250);
    }
  }

href="Simple.java">SimpleBackground2.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 com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.net.*;
import java.awt.image.*;

public class SimpleBackground2 extends Applet {

  static boolean applet = true ;
  private String base ;

  private Texture chercheTexture(String s) {
    if ( applet ) {
      try {
        String adresse = base+s ;
        URL u1 = new URL(adresse);
        return(new TextureLoader(u1,this).getTexture()) ; }
      catch (MalformedURLException e) { return(new Texture2D());} }
      else
      return(new TextureLoader(s,this).getTexture());
    }

  public BranchGroup createSceneGraph(SimpleUniverse u) {
    BranchGroup objRoot = new BranchGroup();
  BoundingSphere largeBounds;
  largeBounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
    { Texture t = chercheTexture("Parquet.jpg");
      ImageComponent2D ic2D =(ImageComponent2D) t.getImage(0);
      Background bg = new Background(ic2D) ;
      bg.setApplicationBounds(largeBounds) ;
      objRoot.addChild(bg); }
    objRoot.compile();
    return objRoot;
    }

  public void lanceJava3D() {
    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 void init() {
    if ( applet ) {
      URL url = this.getCodeBase();
      base = url.toString();
      lanceJava3D(); }
    }

  public SimpleBackground2() {
    if ( !applet ) {
      lanceJava3D(); }
    }

  public static void main(String[] args) {
    applet = false ;
    new MainFrame(new SimpleBackground2(),450,200);
    }
  }

RETOUR

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