Hi,

I'm trying to find the intersection point from a mouse pick
without using the SimpleUniverse classes. Does anybody
know of such example code.

The code I'm using seems to work so that the x and y
coordinates are roughly correct, while the z coordinate is
way off.

Am I doing something wrong, or have I missed something
fundamental?

My picking code:

  public void handleSelect(int x, int y)
  {
    PickShape ray = createPickShape(x, y);
    SceneGraphPath[] path = this.root.pickAll(ray);

    if ( path != null )
    {
      System.out.println("Picked " + path.length + " object(s)");

      Node obj[] = new Node[path.length];

      for ( int i = 0; i < path.length; i++)
      {
        obj[i] = path[i].getObject();

        System.out.println("Found obj[" + i + "] = " + obj[i]);

        if ( obj[i] instanceof Shape3D )
        {
          Shape3D shape = (Shape3D) obj[i];

          double[] dist = new double[1];
          boolean found = shape.intersect(path[i], ray, dist);

          System.out.println(" - Picked Shape3D, distance = " +
                                    dist[0] + ", found = " + found);

          Geometry geom = shape.getGeometry();

          if ( found == true )
          {
            Point3d point = new Point3d();
            Point3d origin = new Point3d();
            canvas.getPixelLocationInImagePlate(x, y, origin);
            Vector3d direction = createDirection(x, y);

            Point3d scalePoint = new Point3d();
            Point3d intersection = new Point3d();

            System.out.println("Origin = " + origin);
            System.out.println("Direction = " + direction);

            scalePoint.scaleAdd(dist[0], direction, origin);

            Transform3D transform = new Transform3D();
            shape.getLocalToVworld(transform);
            transform.invert();

            System.out.println("Scaled point = " + scalePoint);

            transform.transform(scalePoint, intersection);

            System.out.println("Intersection point = " + intersection);
          }
        }
      }
    }
    else
    {
      System.out.println("No object selected!");
    }
  }

  private PickShape createPickShape(int x, int y)
  {
    Point3d eyePosition = new Point3d();
    Point3d mousePosition = new Point3d();

    canvas.getCenterEyeInImagePlate(eyePosition);
    canvas.getPixelLocationInImagePlate(x, y, mousePosition);

    Transform3D motion = new Transform3D();
    canvas.getImagePlateToVworld(motion);
    motion.transform(eyePosition);
    motion.transform(mousePosition);

    Vector3d direction = new Vector3d();
    direction.sub(mousePosition, eyePosition);
    direction.normalize();

    double radius = 0.05;
    return (PickShape)new PickCylinderRay(eyePosition, direction, radius);
  }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to