import java.lang.Math.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.geometry.Box; import com.sun.j3d.utils.behaviors.mouse.* ; import javax.media.j3d.*; import javax.swing.* ; import javax.vecmath.*; public class TextureImage2 extends Applet { private java.net.URL texImage = null; BranchGroup objRoot; SimpleUniverse universe; private int nbLatt = 10; private int nbLong = 20; private int nbP; Color3f objEmissive = new Color3f(0.0f, 0.0f, 0.0f); Color3f objAmbient = new Color3f(0.0f, 0.0f, 0.0f); Color3f objDiffuse = new Color3f(1.0f, 1.0f, 1.0f); Color3f objSpecular = new Color3f(0.0f, 0.0f, 0.0f); float objShininess = 1; // Set up the global lights Color3f lColor1 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); private float[] mkPoints() { float[] v = new float[nbP*3]; int i,j,n; float pi = (float) 3.1415927; float incrLong = 2*pi/nbLong; float incrLatt = pi/nbLatt; n=0; float la = -pi/2; for( i=0; i 0) { try { url = new java.net.URL("file:" + args[0]); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } else { // the path to the image for an application try { url = new java.net.URL("file:./earth.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } new MainFrame(new TextureImage2(url), 256, 256); } /** * Positionne la camera de maniere a pouvoir voir la totalite de la scene */ public void viewAll() { BoundingSphere mybounds = (BoundingSphere) objRoot.getBounds() ; double t[] = new double[3] ; Point3d center=new Point3d() ; mybounds.getCenter(center) ; center.get(t) ; // on positionne la camera de facon a voir la sphere TransformGroup cameraPosition = universe.getViewingPlatform(). getViewPlatformTransform() ; Transform3D trans = new Transform3D() ; trans.setTranslation(new Vector3f((float)t[0], (float)t[1], (float)t[2]+(float) mybounds.getRadius()*3)); cameraPosition.setTransform(trans) ; } }