Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (606) 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 797 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

You cannot reply to this message, because it is very, very old.

 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (37 views) 2015-03-13 17:50:16 Olo (43 views) 2015-03-13 17:47:07 ClaasJG (56 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (47 views) 2015-03-05 14:36:23
 basil_ 22x BurntPizza 21x LiquidNitrogen 21x KevinWorkman 20x EgonOlsen 17x theagentd 16x Roquen 16x princec 11x Varkas 10x 65K 10x SHC 9x Riven 9x Ashedragon 8x lcass 7x teletubo 7x Ecumene 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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