Need advisement on approach

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

If you are looking for persective in the lines Id go ahead and use real 3D objects.

If you walways want them “flat” on the screen, you coudl use one of the many HUD systems people have designe for Java3D…

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