Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  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 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;
2  Java Game APIs & Engines / Java 3D / Re: Need advisement on approach on: 2006-02-05 01: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 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.

James
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (13 views)
2014-12-27 04:03:04

TheDudeFromCI (17 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (86 views)
2014-12-05 12:39:02

SHC (97 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
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
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!