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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
| package action;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.pickfast.PickCanvas;
import com.sun.j3d.utils.pickfast.PickTool;
import com.sun.j3d.utils.picking.PickResult;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Cursor;
import javax.swing.*;
public class Action extends JFrame implements ActionListener,MouseListener
{private SimplePickBehaviour mb=null;
PickResult result;
public int actif1=1,actif2=1,actif3=1;
static CreateLivre cl;
static CreateBiblio cb;
ScaleInterpolator interpol;
BranchGroup root;
BranchGroup behaviorBranch,behaviorBranch1;
BranchGroup scene;
Action modele;
private PickCanvas pickCanvas;
boolean animationOn =false;
boolean animationOn1 =false;
Canvas3D canvas3D;
Transform3D trans;
SimpleUniverse simpleU;
private Group livres;
Alpha myAlpha;
JButton recherche,guide;
TransformGroup transformGroup2;
TransformGroup objSpin;
PositionPathInterpolator interpol1;
JTextField t1;
Image logo=Toolkit.getDefaultToolkit().getImage("C:/Documents and Settings/Administrateur/Mes documents/NetBeansProjects/Action/src/copie.png");
// Menu popup pour afficher un menu contextuel
Color3f color2 = new Color3f (1.0f, 0.0f, 0.0f);
ColoringAttributes color2ca = new ColoringAttributes (color2, 1);
private CustomKeyNavigatorBehavior keyNavigatorBehavior = null;
//BufferedImage img;
public Action() {
this.setLayout(new BorderLayout());
JPanel p1=new JPanel();
// getContentPane().add(p1,BorderLayout.NORTH);
//ModifMousse mm=new ModifMousse(p1,"iconX.png",new Point(15,15));
recherche=new JButton("Recherche");
recherche.addActionListener(this);
guide=new JButton("Visite guidé");
guide.addActionListener(this);
t1=new JTextField(60);
t1.setText("Programmation orientée objet java");
p1.add(recherche);
p1.add(t1);
p1.add(guide);
canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
canvas3D.addMouseListener(this);
this.add(canvas3D, BorderLayout.CENTER);
add("North",p1);
simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
scene = createSceneTree(simpleU,canvas3D);
scene.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
scene.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
createInterpolators();
createInterpolators1();
startInterpolator();
startInterpolator1();
scene.compile();
simpleU.addBranchGraph(scene);
// pickCanvas = new PickCanvas(canvas3D, scene);
//pickCanvas.setMode(PickTool..GEOMETRY_INTERSECT_INFO);
pickCanvas.setTolerance(4.0f);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public BranchGroup createSceneTree (SimpleUniverse su,Canvas3D canvas)
{// Racine de l'arbre des objets représentés dans la scène 3D
root = new BranchGroup ();
mb=new SimplePickBehaviour(canvas3D,root,new BoundingSphere(new Point3d(), 100),modele);
root.addChild(mb);
root.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
root.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
objSpin=new TransformGroup();
// mb=new MouseBehaviorss(objSpin);
// permet de modifier l'objet pendant l'execution
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// on cre un fonction de rotation au cours du temps
// ScaleInterpolator interpol=new ScaleInterpolator(myAlpha,objSpin,trans,0.5f,1.2f);
/////////////////////////
TransformGroup tg = su.getViewingPlatform().getViewPlatformTransform();
keyNavigatorBehavior = new CustomKeyNavigatorBehavior(tg);
// Champ d'action du clavier
keyNavigatorBehavior.setSpeedFactor(0.10f);
keyNavigatorBehavior.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000));
root.addChild(keyNavigatorBehavior);
cb=new CreateBiblio(canvas,su);
Group biblio = cb.creerBiblio(canvas, root,su);
cl=new CreateLivre(canvas3D,simpleU);
livres = cl.creerlivre(canvas3D, root);
Transform3D transform = new Transform3D ();
transform.setScale(0.2);
Transform3D scale = new Transform3D ();
scale.setScale (1.1);
transform.mul (scale);
trans=new Transform3D();
trans.setTranslation(new Vector3f(0.0f,0.0f,-3.0f));
objSpin = new TransformGroup(trans);
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
TransformGroup transformGroup = new TransformGroup (scale);
transformGroup2 = new TransformGroup (transform);
transformGroup.addChild (biblio);
transformGroup2.addChild (livres);
//root.addChild(transformGroup);
//root.addChild(transformGroup2);
objSpin.addChild (transformGroup);
objSpin.addChild (transformGroup2);
setCursor(Cursor.HAND_CURSOR);
root.addChild(objSpin);
return root;}
private void createInterpolators(){
behaviorBranch=new BranchGroup();
myAlpha=new Alpha(1,18000);
interpol=new ScaleInterpolator(myAlpha,objSpin,trans,0.0f,1.2f);
BoundingSphere bounds=new BoundingSphere();
interpol.setSchedulingBounds(bounds);
behaviorBranch.addChild( interpol);
objSpin.addChild(behaviorBranch);
}
private void createInterpolators1() {
behaviorBranch1=new BranchGroup();
// on cre un fonction de rotation au cours du temps
Alpha transAlpha=new Alpha(1,11000);
// on cre notre chemin: une matrice de 3 Point3f: point de dpart, point d'arrive,
// puis retour au point de dpart pour permettre de boucler
Point3f[] chemin=new Point3f[3];
chemin[0]=new Point3f(0.6f,0.0f,0.0f);
chemin[1]=new Point3f(-0.6f,0.0f,0.0f);
chemin[2]=new Point3f(0.6f,0.0f,0.0f);
// on cre une matrice de float qui sert faire correspondre
// chaque point dans l'espace un point dans l'chelle du temps qui s'tend de 0 1
float[] timePosition={0.0f,0.50f,1.0f};
interpol1=new PositionPathInterpolator(transAlpha,cb.objSpin,trans,timePosition,chemin);
// on dfinit la zone sur laquelle va s'appliquer le chemin
BoundingSphere bounds = new BoundingSphere(new Point3d(), 200);
interpol1.setSchedulingBounds(bounds);
cb.objSpin.addChild(interpol1);
cb.objSpin.addChild(behaviorBranch1);
}
public void startInterpolator() {
if (animationOn) {
interpol.setEnable(true);
}
else {
interpol.setEnable(false);
}
}
public void startInterpolator1() {
if (animationOn1) {
interpol1.setEnable(true);
}
else {
interpol1.setEnable(false);
}
}
public void actionPerformed(ActionEvent e ) {
JButton source =(JButton) e.getSource();
if (source==recherche){
try { animationOn = true;
animationOn1 = true;
startInterpolator();
startInterpolator1();
}
catch (Exception e44) {
System.err.println("Exceptionwoooooooooooooh " + e);
}
}
else{
if(source==guide){
VisiteGuidé vg=new VisiteGuidé();
vg.setVisible(true);
vg.setSize(500, 500);
vg.setLocation(300,50);
try {
vg.start();
} catch (Exception ex) {
System.out.print("woooooh");
}
}
}
}
public void mouseClicked (MouseEvent e){
}
if(e.getButton() == MouseEvent.BUTTON2){
if(cl.pp.getPickable() && actif1==1){
InfoSite infs=new InfoSite(1,"C:/Documents and Settings/Administrateur/Mes documents/NetBeansProjects/Versionff/src/miniature/1m.jpg","src/rouge.jpg");
Object ss=cl.pp.getUserData();
System.out.print(ss);
infs.setVisible(true);
infs.setSize(1900, 750);
actif1=0;actif2=1;
}
else{
if(cl.pp1.getPickable() && actif2==1){
InfoSite infs=new InfoSite(2,"src/miniature/2.jpg","src/rouge.jpg");
infs.setVisible(true);
infs.setSize(1900, 750);actif1=0;actif2=0;
}
else{
if(cl.pp2.getPickable() && actif3==1){
InfoSite infs=new InfoSite(47,"src/miniature/47.jpg","src/orange.jpg");
infs.setVisible(true);
infs.setSize(1900, 750);
actif1=1;actif2=1;actif3=0;
}
}
}
}
public void mouseReleased (MouseEvent e){}
public void mouseEntered (MouseEvent e){}
public void mouseExited (MouseEvent e){}
public void mousePressed (MouseEvent e){}
@SuppressWarnings("static-access")
public static void main(String[] args) {
Frame frame = new Action();
frame.setVisible(true);
frame.setSize(1900, 750);
}
} |
Partager