| 12
 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
 
 |  
public void processStimulus (Enumeration criteria) {
 
        WakeupCriterion wakeup;
        AWTEvent[] event;
        int eventId;  
        while (criteria.hasMoreElements()) {
          wakeup = (WakeupCriterion) criteria.nextElement();
          if (wakeup instanceof WakeupOnAWTEvent) {
        //ici on enregistre tout les evenements qui ont eu lieu
        event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
        for (int i=0; i<event.length; i++) {     
          eventId = event[i].getID();
          if (eventId == MouseEvent.MOUSE_PRESSED) {
            //on recupere les coordonnees ou ca a pické sur le canvas 
            int x = ((MouseEvent)event[i]).getX();
            int y = ((MouseEvent)event[i]).getY();
            //et on dit au canvas : ca a pické ici,regarde si tu trouve des objets
            pickCanvas.setShapeLocation(x, y);
 
            Point3d eyePos = pickCanvas.getStartPosition ();
            double[] t =new double[3];
            double[] t2= new double[3];
             eyePos.get(t);
             t[2]=t[2]-7000;
 
           // pickResult = pickCanvas.pickAllSorted();
 
              canvas.getCenterEyeInImagePlate(eyePos);
 
              Point3d mousePos = new Point3d();
              canvas.getPixelLocationInImagePlate(x, y, mousePos);
 
              Transform3D transform3D = new Transform3D();
              canvas.getImagePlateToVworld(transform3D);
 
              transform3D.transform(eyePos);
              transform3D.transform(mousePos);
 
 
              Vector3d mouseVec;
              //if (parallel) {
                 Vector3d vect = new Vector3d(0.f, 0.f, 3.f);
              // }
              // else {
                  mouseVec = new Vector3d();
                  mouseVec.sub(mousePos, vect);
                  mouseVec.normalize();
             //  }
 
 
              pickRay.set(mousePos, mouseVec);
              sceneGraphPath = bg.pickAll(pickRay);
 
 
 
 
              if (sceneGraphPath != null) {
                  for (int j=0; j<sceneGraphPath.length; j++) {
                     if (sceneGraphPath[j] != null) {
                        Node node = sceneGraphPath[j].getObject();
                        Appearance appar2 = new Appearance();
                        System.out.println("Click detecté");
                     Appearance texture = new Appearance();
                     Material colorMat2= new Material();
                     colorMat2.setDiffuseColor(new Color3f(Color.yellow));
                     appar2.setMaterial(colorMat2);
 
                     Appearance appar = new Appearance();
                     Material colorMat= new Material();
                     colorMat.setDiffuseColor(new Color3f(Color.red));
                     appar.setMaterial(colorMat);
 
                    try{
                     Sphere cone = (Sphere) sceneGraphPath[j].getNode(0);
                     System.out.println("Recuperation objet");
                     String nom = cone.getName();
 
                     for (int g =0;g<25;g++)
                     {
                         if ( listep[g].getname().equals(nom)){
 
                             coordar=listep[g].getcoord();
 
 
                             if (listep[g].getappar().equals("appar")){
                                 if (nbselect<=2){
                                nbselect++;
                                if ( nbselect==2){
                                    canvas.setName(String.valueOf(listep[g].getcoord().x+1).concat(String.valueOf(listep[g].getcoord().y+1).concat(String.valueOf(listep[g].getcoord().z+1))));
 
                                 }
                                if ( nbselect==3){
 
                                    canvas.setName(canvas.getName().concat(String.valueOf(listep[g].getcoord().x+1).concat(String.valueOf(listep[g].getcoord().y+1).concat(String.valueOf(listep[g].getcoord().z+1)))));
                                     }
                                 listep[g].setappar("appar2");
                                 texture=appar2;
                                 }
                                 else{
                                     JOptionPane.showMessageDialog(canvas,"Vous avez deja selectionnez 2 points ", "Attention",JOptionPane.INFORMATION_MESSAGE);
                                     texture=appar;
                                 }
                                }
                             else{
                                 listep[g].setappar("appar");
                                 texture=appar;
                                 nbselect--;
 
                             }
 
                             cone.setAppearance(texture);
 
 
                         }
 
                     }
 
 
                     }
                    catch(ClassCastException e)
                    {
                         System.out.print("mauvais click");
                    }
 
                    break;
                   }
 
 
 
                     }
         }
        } 
       }
      } | 
Partager