Strange pick issue


Today I'm trying to mouse-pick some objects. After searching through this forum and the jME examples I managed to get these two  versions of code:

   private void processPick() {
       int mouse_x = MouseInput.get().getXAbsolute();
       int mouse_y = MouseInput.get().getYAbsolute();
       Vector2f screenPos = new Vector2f(mouse_x, mouse_y);
       Vector3f startPoint = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 0);
       // Get the world location of that X,Y value - far
       Vector3f endPoint = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 1);
       Ray ray = new Ray(startPoint, endPoint.subtract(startPoint));
       TrianglePickResults results =  new TrianglePickResults();
       vehicles.findPick(ray, results);
       if(results.getNumber() > 0) {
          System.out.println("NUMBER: "+results.getNumber()+" OBJ: "+results.getPickData(0).getTargetMesh().getName());

And number two:

   private void processPick2() {
       Vector2f screenPos = new Vector2f();
       //Get the position that the mouse is pointing to
      screenPos.set(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());
      // Get the world location of that X,Y value
      Vector3f worldCoords = display.getWorldCoordinates(screenPos, 1.0f);
      // Create a ray starting from the camera, and going in the direction
        // of the mouse's location
        final Ray mouseRay = new Ray(cam.getLocation(), worldCoords
        TrianglePickResults results = new TrianglePickResults();
       if(results.getNumber() > 0) {
          System.out.println("NUMBER: "+results.getNumber()+" OBJ: "+results.getPickData(0).getTargetMesh().getName());

In both examples, the field vehicles is a Node which contains an Entity with a simple Box as Spatial.

In the first version, my vehicle is selected practically every time. I have to move my cursor to the other side of the map in order to be able to make a pick without hitting my object.
In the second version, I nearly can't pick my object. Sometimes, if I place the cursor far above the actual geometry I'm able to pick it, but this is not a constant event.

Maybe it's good to know that I'm currently using lex' strategicHandler in my application. I don't really know if it's affecting the way of picking something. If I compare the absolute x and y values of my mouse to those I'm getting from some jME example pick (therefore without strategicHandler), I can't notice much difference.. (+/-  30-60)

Thanking you in anticipation

I struggled for a long time with that sort of problem, but after a while I think I cracked it. Here are some tips :

  • Use the second of your two approaches - by far the best picking example is TestTrianglePick imo - so I always do it that way. (Especially if you want to get the pick intersection point!)

  • Make sure your pickable spatials have bounding volumes - so setModelBound(new BoundingBox()) on your box and then updateModelBound()

Fingers crossed that will help. There might be an issue with the strategic handler's mouse - I haven't used it for a while but make sure that the coordinates you are getting back from this bit

screenPos.set(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());

look sensible as well.

Thank you for your response… Unfortunately your tips didn't change too much in my case…  :frowning:

I haven't got a sense for what are sensible mouse position values… My screen is set to 1920x1200. If I look at the value of MouseInput.get().getXAbsolute() I got something about 0 in the upper left corner and something about 1920 for the upper right corner. This looks really good.

MouseInput.get().getYAbsolute() doesn't give that appropriate values. If i check the mouses y position just after startup (so it sticks in the absolute center of my screen) i get something about 340-360 for the y value. I'm not that into it to rate these values, the only thing I can spot is that 340 isn't barely the 1200/2…

Otherwise, reading out these values in some proper working example like TestTrianglePick doesn't give me other values anyway…

I just tried that one out with a more common and simple scene. I figured out that picking works almost every time if the camera is very close to the  object. As soon as I'm moving away a bit picking fails.

I'm currently using the code number two, as shown in the first post.


Well… It's 4:34 AM now, and finally I got a half-decent solution for this problem.

The problem appears only in combination with a software mouse of the strategicHandler package.

Setting MouseInput.get().setCursorVisible(true) works, but leads to unsuspected behavior of the strategicHandler module.

Hitting numpad.ENTER  twice in order to enable and disable the hardware/software mouse switch works at times…

I found that thread:

According to this I got the following code:

      MouseManager mouseManager = new MouseManager(CombinedMouse.get());

      strategicHandler = new StrategicHandler(
            cam, mouseManager, heightMap);
      input = strategicHandler;
         display.getWidth()/2, display.getHeight()/2);

If somebody has a better or prettier solution or a different approach please let me know-
But at least it works for now.


I just found a counterexample. Mouse picking still doesn't work. Now I'm not even sure if it has got to do with strategicHandler.

Please, please some help, ideas whatever.    :(

Still no suggestions? :frowning:

Finally I think I've got it. Quite strange issue. There are a certain, few things which have to be considered in order to use strategicHandler. I won't list them here as I'm not certain in each point and I don't have the time to check them out individually right now.

After all it works for me at the moment.