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

 Riven (16 views) 2015-07-03 11:22:16 deepthought (43 views) 2015-06-30 15:39:44 deepthought (47 views) 2015-06-30 15:39:09 deepthought (57 views) 2015-06-30 15:36:52 Za\'Anzabar (27 views) 2015-06-29 05:44:54 TritonDreyja (43 views) 2015-06-24 17:10:40 CopyableCougar4 (43 views) 2015-06-23 00:34:45 BurntPizza (46 views) 2015-06-21 20:36:46 cookiecompiler (88 views) 2015-06-11 15:42:53 cookiecompiler (51 views) 2015-06-11 15:41:14
 princec 31x wessles 23x BurntPizza 19x opiop65 18x CopyableCougar4 18x Riven 15x nsigma 15x EgonOlsen 14x theagentd 14x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x sunburn 11x ags1 11x DavidBVal 10x Archive 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How 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:14
 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