Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Mapping mouse x,y to local world x,y equivalents  (Read 1213 times) 0 Members and 1 Guest are viewing this topic.
jleone

Junior Newbie

 « Posted 2006-02-10 16:59:47 »

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;
Jeff

JGO Coder

Got any cats?

 « Reply #1 - Posted 2006-02-11 01:55:18 »

hmm.

If I am understanding you correctly I would getLocalToVWorld on the shape node and take the inverse.

But I dont knwo how you plan to map 2d coordinates into a 3D coordinate system.  Your missing one coord.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
 ignore  |  Print

 DesertCoockie (22 views) 2018-05-13 18:23:11 nelsongames (74 views) 2018-04-24 18:15:36 nelsongames (68 views) 2018-04-24 18:14:32 ivj94 (751 views) 2018-03-24 14:47:39 ivj94 (81 views) 2018-03-24 14:46:31 ivj94 (605 views) 2018-03-24 14:43:53 Solater (97 views) 2018-03-17 05:04:08 nelsongames (178 views) 2018-03-05 17:56:34 Gornova (388 views) 2018-03-02 22:15:33 buddyBro (1048 views) 2018-02-28 16:59:18
 princec 18x philfrei 12x SkyAphid 12x NuclearPixels 11x ByerN 10x FabulousFellini 7x Guerra2442 6x cylab 6x orange451 5x VaTTeRGeR 4x KaiHH 4x 65K 4x ags1 4x orangepascal 4x murarz208 4x Riven 4x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org