Hi everybody!
I'm very interested in Java3d picking behaviors.
 
I want to move to a terrain point where a make a pick, but I pass through the terrain, like a liquid terrain.
How can I resolve this?
 
I'm trying to do it with this code;
 
 public void processStimulus(Enumeration e){
 
    /*The behavior is activated with mouse clicks
 
    WakeupCriterion mC = (WakeupCriterion)e.nextElement();
    AWTEvent[] Eventos = ((WakeupOnAWTEvent)mC).getAWTEvent();
    MouseEvent mE = (MouseEvent)Eventos[0];
 
   
    PickCanvas pC = new PickCanvas(canvas3d,transformGroup);
    pC.setMode(pC.GEOMETRY_INTERSECT_INFO);
    pC.setTolerance(5f);
    pC.setShapeLocation(mE);
 
 
  PickResult resultado = pC.pickClosest();
    if (resultado!=null){
          System.out.println("Sucess!!");
           PickIntersection pI = resultado.getIntersection(0);
          Point3d [] array = pI.getPrimitiveCoordinates();
           Transform3D trans = new Transform3D();
          miPrincipal.rotatorTG.getTransform(trans);
         miPrincipal.target = new Point3d(-array[0].x,-array[0].y,-array[0].z);// I go to the first point of the TriangleStripArray`s triangle where I made pick.
  }else{
      System.out.println("Failure!!");
    }
}
 
Target is a point3d (global property) of the main class.
I use a listener where I run the next code:
 
 
JButton target = new JButton("target");
 
    target.addActionListener(new ActionListener(){
 
      public void actionPerformed(ActionEvent e){
        miPrincipal is the main class
        if (miPrincipal.target==null) System.out.println("There isn�t any target");
        Transform3D t2 = new Transform3D();
        double x = miPrincipal.target.x;
        double y = miPrincipal.target.y;
        double z = miPrincipal.target.z;
 
        Matrix3f matriz = new Matrix3f();
        Vector3d vector = new Vector3d();
        rotatorTG is the main transformgroup
        miPrincipal.rotatorTG.getTransform(t2);
        t2.get(matriz,vector);
 
        double x0 = vector.x;
        double y0 = vector.y;
        double z0 = vector.z;
        System.out.println(x0+" "+y0+" "+z0);
 
        for (double i=0.0d;i<1.00d;i+=0.01d){
          This is the parametric line equation
           x0 = x0 + (i*(x-x0));
          y0 = y0 + (i*(y-y0));
          z0 = z0 + (i*(z-z0));
          System.out.println(i);
          t2.setTranslation(new Vector3d(x0,y0,z0));
          miPrincipal.rotatorTG.setTransform(t2);
          try{
            Thread.sleep(110);
          }catch(Exception exc){
            System.out.println("Error con el thread");
            exc.printStackTrace();
          }
        }
      }
      });

Reply via email to