I am capturing x,y mouseclicks on a Canvas3D and I want to see how they translate to x,y coordinates based on the coordinate system of a specific shape in the scene. I am able to convert the mouse coords to virtual world coords using a previously posted approach (pasted below), but I need the coords relative to the shape (which may be rotated,
translated, or zoomed in relation to the main virtual world).
Is this clearly described? Any ideas?
/**
* 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 thecanvas point
* provided.
*/
public Point3d getCanvasPtToVworldPt(int x, int y) {
// convert the canvas point to ImagePlate coords
Point3d VworldPt = new Point3d();
this.canvas.getPixelLocationInImagePlate(x, y, VworldPt);
// transform the point from an imageplate coordinate to a
Vworld
// coordinate
Transform3D imagePlateToVworld = new Transform3D();
this.canvas.getImagePlateToVworld(imagePlateToVworld);
imagePlateToVworld.transform(VworldPt);
Point3d centerEyePt = new Point3d();
this.canvas.getCenterEyeInImagePlate(centerEyePt);
imagePlateToVworld.transform(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;