Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need advisement on approach  (Read 1299 times)
0 Members and 1 Guest are viewing this topic.
Offline jleone

Junior Newbie

« Posted 2006-02-04 20: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.

Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2006-02-04 23:59:32 »

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...

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!
Offline jleone

Junior Newbie

« Reply #2 - Posted 2006-02-05 01:18:14 »


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

        Point3d centerEyePt = new Point3d();

        //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),
        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();
Pages: [1]
  ignore  |  Print  

EgonOlsen (42 views)
2018-06-10 19:43:48

EgonOlsen (22 views)
2018-06-10 19:43:44

EgonOlsen (43 views)
2018-06-10 19:43:20

DesertCoockie (197 views)
2018-05-13 18:23:11

nelsongames (124 views)
2018-04-24 18:15:36

nelsongames (123 views)
2018-04-24 18:14:32

ivj94 (863 views)
2018-03-24 14:47:39

ivj94 (124 views)
2018-03-24 14:46:31

ivj94 (768 views)
2018-03-24 14:43:53

Solater (140 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!