Intersection Question

My team and I are having some problems with intersections.  It probably stems from the fact that we are incredibly new to this, however we have poked around on the forums a bit and were not able to find a solution that worked for our program.

We essentially have a Quad (it's actually a double array of quads, but basically looks like one), and we have 'extended' it to get us the top left, top right, bottom left and bottom right corners.  These coordinates are returned as 'world coordinates'.  When the mouse is pressed down, we want to find the point that intersects with the plane of the quad (note that the point doesn't, and in this case probably won't, touch the quad itself).

The following in the code we are using to calculate the intersection:

        Plane plane = new Plane();

        plane.setPlanePoints(topLeft, topRight, bottomLeft);

        Vector3f rayOrigin = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 0);

        Vector3f rayDirection = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 1);

        Ray ray = new Ray(rayOrigin, rayDirection);

        Vector3f intersectionPosition = new Vector3f();

        ray.intersectsWherePlane(plane, intersectionPosition);

The problem with this is that when we move around the Quad, if we click at nearly the same point on the plane, we get entirely different results.  Sometimes the X of the intersectionPosition will be +20, other times -16.

The question is…what are we doing wrong that is making it so that when the camera moves, our point picking is unreliable?

Thanks so much for the help!


i had a simmilar issue with picking.

My Code is

screenPosition.x = MouseInput.get().getXAbsolute();
screenPosition.y = MouseInput.get().getYAbsolute();
DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPosition, 1f, clickStartPos);



The line


solved my problem. I took it from line #268, it worked and i wasnt thinking anymore about it...

Also normalizing the ray could help, but im not shure.