|
oops, I answered directly, maybe other people are interested
as well=> this is a very common question
-----Original Message-----
From: Olivier fillon <[EMAIL PROTECTED]> To: Shinji Tanaka <[EMAIL PROTECTED]> Date: Wednesday, April 05, 2000 7:32 AM Subject: Re: [JAVA3D] get position in 3D World from mouse cursor Hi,
a copy of an earlier message I sent which should help you
out :
>>>>>
There are whole set of method to do this:
in the following, I use the code to give the x/y position of my mouse pointer in a bird eye view of the scene This should give you some ideas to follow ####################333 >From your mouse event: /** * Takes the x and y coordinates from the provided mouse event and * determines the corresponding point in the virtual world. * * @param evt The Mouse Event for which the point is desired * @return Point3d a virtual world point corresponding to the Mouse Event's * x and y coordinates on the canvas. */ public Point3d getCanvasPtToVworldPt(MouseEvent e) { return getCanvasPtToVworldPt(e.getX(), e.getY()); } with /** * determines a corresponding virtual world point given a canvas point. * * @param Point3d the point on the canvas * @return Point3d a virtual world point corresponding to the canvas point * provided. */ public Point3d getCanvasPtToVworldPt(int x, int y) { // convert the canvas point to ImagePlate coords getPixelLocationInImagePlate(x, y, VworldPt); // transform the point from an imageplate coordinate to a Vworld // coordinate getImagePlateToVworld(imagePlateToVworld); imagePlateToVworld.transform(VworldPt); getCenterEyeInImagePlate(centerEyePt); imagePlateToVworld.transform(centerEyePt); //Logging.trace(10, "Center eye pt VW " + centerEyePt); //now compute the z=0 value in the centereye to VworldPt pt //centerEyePt_VworldPt = alpha *centerEyePt_planePt with planePt.z=0 double alpha = 0.0; if ( VworldPt.z != centerEyePt.z ) { alpha = centerEyePt.z /(VworldPt.z - centerEyePt.z); } Point3d planePt = new Point3d( centerEyePt.x - alpha *(VworldPt.x - centerEyePt.x), centerEyePt.y - alpha *(VworldPt.y - centerEyePt.y), 0.0); return planePt; } ############### Please note that I do not care about the z value here Another way is to pick the point (see FAQ/archive) and so directly get the xyz picked upon Olivier Fillon Minestar Project [EMAIL PROTECTED] Mincom Limited Ph.+61-7-3303-3344 61 Wyandra Street Fax+61-7-3303-3232 Teneriffe Qld. 4005. Australia Company home page: http://www.mincom.com/ Personal home page: http://www.powerup.com.au/~fillon --- A word from our sponsor --- This transmission is for the intended addressee only and is confidential information. If you have received this transmission in error, please delete it and notify the sender. The contents of this E-mail are the opinion of the writer only and are not endorsed by Mincom Limited unless expressly stated otherwise. --
|
- [JAVA3D] get position in 3D World from mouse cursor Shinji Tanaka
- Olivier fillon
