Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java 3D / Mapping mouse x,y to local world x,y equivalents
|
on: 2006-02-10 17: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;
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 3D / Re: Need advisement on approach
|
on: 2006-02-05 02:18:14
|
|
Jeff,
Thanks for the quick reply, perspective is what I'm going for. Now I'm having some difficulty mapping the mouse location to the coordinates of the transform group that contains my graph shapes. Below is the code I found that does a good job of mapping mouse coordinates to a point in the virtual world.
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);
//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; }
I have tested this and it works pretty well. Unfortunately this isn't enough. I need to get the coordinates relative to the graph shape (which I have inside a transform object that can be rotated, zoomed, etc.). I thought it would simply be a matter of applying the Transform3D of the graph's transformgroup to the point returned from the method above. This doesn't work out as I expected. Any ideas on how to take that point and convert it from being relative to the overall virtual universe, to relative to the transform group that I am focused on?
This didn't work: Transform3D t = new Transform3D(); this.transformGroup.getTransform(t); t.transform(planePt);
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 3D / Need advisement on approach
|
on: 2006-02-04 21:08:12
|
|
I am creating a program that generates and displays 3 dimensional graphs. I have the basics completed and the graph gets created, rotated, zoom, etc.
I want to add a crosshair feature so that one can analyze the specific data points with more detail. As the mouse moves across the canvas, two lines would form an intersection. One of the lines is parrallel to the X-axis, the other Z. On the side, I would dispaly the X&Z values as well as the Y value that is the result of the function with inputs X&Z. Hopefully this explaination is pretty straight-forward.
There are two approaches I can think of.
1. Represent the lines as shapes in the 3D graph and create a custom behavior that translates them as the mouse moves. I'm a bit concerned about the performance impact of constantly translating the lines. I also want these to stretch across the entire canvas, so I guess I would need to grow them as the person zoomed out? 2. Figure out how to overlay the lines on the canvas using Java2D. This would bring some complexity as the underly graph was rotated and zoomed, since I would need to draw the lines at the correct angles.
Please advise, and if you can point to example code that would be much appreciated.
James
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|