Exemple de classe
utilisant Java3D
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2001 */
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Hello2 extends Applet {
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup objTrans = new TransformGroup();
objRoot.addChild(objTrans);
Transform3D t = new Transform3D();
t.setRotation(new AxisAngle4d(1.0,1.0,0.0,
Math.PI/5.0)) ;
objTrans.setTransform(t);
objTrans.addChild(new ColorCube(0.4));
objRoot.compile();
return objRoot;
}
public Hello2() {
setLayout(new BorderLayout());
GraphicsConfiguration config;
config = SimpleUniverse
.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center",c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
ViewingPlatform vp = u.getViewingPlatform();
vp.setNominalViewingTransform();
u.addBranchGraph(scene);
}
public static void main(String[] args) {
new MainFrame(new Hello2(),256,256);
}
}
Remarques,erreurs
nicolas.janey@univ-fcomte.fr