A. Murat Tanyer wrote:

>Hi Roger;
>
>In the Java3D discussion list I realised that someone advised using
>CanvasPick as it does not need SimpleUniverse class. However, I am not sure
>about this. Is that solves my problem? Have you got any example to pick
>objects using "core javax.media.j3d.ViewPlatform class"?
>
>What I actually want is picking multiple objects by using mouse (such as
>clicking and opening windoes by mouse and selecting the elements inside)
>but
>cannot find any example to do this.
>

I'm not sure I understand exactly what you want to do. The code below
will give you
all objects that intersects with the PickShape. This is just pseudo
code, so don't expect
it to compile right away ...

To select all shapes, do:

    BranchGroup root; // Your root branchgroup
    PickShape ray = createPickShape(x, y);
    SceneGraphPath[] path = this.root.pickAll(ray);

where createPickShape is created as:

  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);
  }

And to see if the PickShape really intersects use:

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



Hope this is what you needed ...

Regards,

Roger Berggen

===========================================================================
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