Les primitives graphiques de Java 3D
/* 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 SimplePrimitive extends Applet {
public BranchGroup createSceneGraph(SimpleUniverse u) {
BranchGroup objRoot = new BranchGroup();
Appearance a = new Appearance();
ColoringAttributes ca = new ColoringAttributes();
a.setColoringAttributes(ca);
{ 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,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,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,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 SimplePrimitive() {
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 SimplePrimitive(),600,150);
}
}
Remarques,erreurs
nicolas.janey@univ-fcomte.fr