1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
import java.awt.Component;
import javax.swing.JApplet;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Cube3 extends JPanel{
private static final double DEG_TO_RAD = 0.017453292;
public static void Cube3(){
//Creation Univers utilise par defaut un viewer existant
SimpleUniverse univers = new SimpleUniverse();
//Definition systeme de coordonnees et point de vue
univers.getViewingPlatform().setNominalViewingTransform();
//Creation de la scene 3d
BranchGroup scene = createSceneGraph();
univers.addBranchGraph(scene);
}
public static BranchGroup createSceneGraph(){
//creation de la branche
BranchGroup objRoot=new BranchGroup();
//creation du cube
ColorCube cube = new ColorCube(0.3);
// ----------- PREMIERE TRANSFORMATION ---------
//on cree le groupe de transfomation pour rotation dynamique
TransformGroup objrotate1= new TransformGroup();
//on autorise la transformationde l'objet rotation dynamique
objrotate1.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);
//on defini l'animation de l'objet :
Alpha rotAlpha = new Alpha(-1,4000);
//Rotation
RotationInterpolator rotInt = new RotationInterpolator (rotAlpha,objrotate1);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),2.0);
rotInt.setSchedulingBounds(bounds);
//------------ FIN PREMIERE TRANSFORMATON -----------
objrotate1.addChild(rotInt);
objrotate1.addChild(cube);
//objrotate1.addChild(objrotate2);
objRoot.addChild(objrotate1);
//------- couleur de fond-----------
Background back = new Background(1.0f,1.0f,1.0f);
back.setApplicationBounds(new BoundingSphere());
objRoot.addChild(back);
return(objRoot);
}
public static void ferme(){
SimpleUniverse univers = new SimpleUniverse();
univers.cleanup();
}
|
Partager