Hi Guillermo,

You have to transform the mouse coords into vworld coords. you can do it
like this:

                //cursor position
                Point3d imagePoint = new Point3d();
                canvas3d.getPixelLocationInImagePlate(mouseX, mouseY,
imagePoint);

                //transform coords into vworld
                Transform3D trans = new Transform3D();
                canvas3d.getImagePlateToVworld(trans);
                trans.transform(imagePoint);

If you are interrested in the coordinates your mouse pointer has on the
surface of the geometry, you need a pickray starting from your eyes through
the mouse pointer to your geometry (normally -z direction).
You can do it for example this way:

                //eye position
                Point3d eyePos = new Point3d();
                canvas3d.getCenterEyeInImagePlate(eyePos);

                //cursor position
                //mouseX, mouseY are the coords from the mouse event
                Point3d imagePoint = new Point3d();
                canvas3d.getPixelLocationInImagePlate(mouseX, mouseY,
imagePoint);

                //transform points
                Transform3D trans = new Transform3D();
                canvas3d.getImagePlateToVworld(trans);
                trans.transform(eyePos);
                trans.transform(imagePoint);
                Vector3d pickDir = new Vector3d();
                pickDir.sub(imagePoint, eyePos);
                PickRay pickRay = new PickRay();
                pickRay.set(eyePos, pickDir);

Next, you need the distance to the geometry. You have to test for
intersection. Class Shape3D provides method
intersect(SceneGraphPath path, PickRay pickRay, double[] dist) to do this.


Gernot Veith
[EMAIL PROTECTED]
http://www.janet.de


> -----Original Message-----
> From: Guillermo E. Gutierrez [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 17, 1999 8:19 PM
> To: [EMAIL PROTECTED]
> Subject: Getting 3d coords from mouse click.
>
>
> Hello,
>
> I'm trying to get the 3d (world or scene--it doesn't matter)
> coordinates from a (mouse) picking operation.  For example: I have a
> ColorCube located at the origin.  I'm looking at it down the x axis.
> When I click on the center of the face I'm looking at, I want to get a
> Point3D with x=1, y=0, and z=0.  Is there some easy built-in way to do
> this (via PickObject, for example), or do I have to manually get the
> object that I picked and do all the math?  Put another way, I want the
> 3d coordinates of the mouse when I click on any geometry.  (Obviously,
> it's impossible to tell depth when clicking on empty space.)
>
> Thanks.
> -guillermo
> [EMAIL PROTECTED]
> Software Engineer, Visualization IR&D
> Harris Corporation
>
>

Reply via email to