Gestion d'un LOD
/* 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.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class SimpleLOD extends Applet {
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);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
{ MouseZoom behavior = new MouseZoom(objTrans);
objTrans.addChild(behavior);
behavior.setSchedulingBounds(bounds); }
{ MouseRotate behavior = new MouseRotate(objTrans);
objTrans.addChild(behavior);
behavior.setSchedulingBounds(bounds); }
Switch sw = new Switch();
sw.setCapability(Switch.ALLOW_SWITCH_READ);
sw.setCapability(Switch.ALLOW_SWITCH_WRITE);
sw.setWhichChild(0);
objTrans.addChild(sw);
{ 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);
sw.addChild(new Box(0.25F,0.38F,0.58F,a)); }
{ Appearance a = new Appearance();
Material m = new Material();
a.setMaterial(m);
sw.addChild(new Sphere(0.88F,1,100,a)); }
{ Appearance a = new Appearance();
Material m = new Material();
m.setDiffuseColor(0.1f,0.1f,0.9f);
m.setSpecularColor(1.0f,0.0f,0.0f);
m.setAmbientColor(0.9f,0.9f,0.9f);
m.setShininess(25.0f);
a.setMaterial(m);
sw.addChild(new Cylinder(1.5F,2.7F,1,100,100,a)); }
{ Appearance a = new Appearance();
Material m = new Material();
m.setDiffuseColor(0.5f,1.0f,0.2f);
m.setAmbientColor(0.5f,0.6f,0.8f);
a.setMaterial(m);
sw.addChild(new Cone(2.55F,4.95F,1,100,100,a)); }
float[] distances = new float[3];
distances[0] = 3.0f;
distances[1] = 6.0f;
distances[2] = 9.0f;
DistanceLOD lod = new DistanceLOD(distances);
lod.addSwitch(sw);
lod.setSchedulingBounds(bounds);
objTrans.addChild(lod);
objRoot.compile();
return objRoot;
}
public SimpleLOD() {
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 SimpleLOD(),250,250);
}
}
Remarques,erreurs
nicolas.janey@univ-fcomte.fr