Trouble with mousepicking

hi all

i have a node boxNode which contains a lot of boxes. know i want to test if my mouse picks on one of the boxes. that's why i use this code:

public class CP_ToolTip {
   private Node boxNode;
   public CP_ToolTip(Node boxNode) {
      this.boxNode = boxNode;
   public void findResults() {
      Vector2f screenPos = new Vector2f();
      screenPos.set(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());
      Vector3f worldCoords = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 0);
      Vector3f worldCoords2 = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 1);
      Ray ray = new Ray(worldCoords, worldCoords2.subtractLocal(worldCoords).normalizeLocal());
      PickResults pr = new BoundingPickResults();
      boxNode.findPick(ray, pr);
      for (int i = 0; i < pr.getNumber(); i++) {
         System.out.println("Results: " + "n");
         String s = pr.getPickData(i).getTargetMesh().getName();
         System.out.println(s + "n");

but unfortuneatley it never finds any result... why that? im using a chasing camera and a thirdpersoncontroller.. any hints?

Do your boxes have bounding boxes? BoundingPickResults relies on bounding volumes.

yes they have. thats how i initialize the boxes:

for (int j = 0; j < revisions; j++) {
            Box source1 = new Box("source1".concat(Integer.toString(i)), new Vector3f(x,((((2*j)+1)*BOX_STEP)),z), BOX_X, BOX_STEP, BOX_Z);
            source1.setModelBound(new BoundingBox());
            boxesContainer.add(j, source1);
            authorsContainer.add(j, sources.elementAt(i).getAuthor(j));

Have you compared your setup to the mouse picking examples? I don't have them in front of me but maybe you can spot something that will make the difference.

<yes that is already part of my code ;:slight_smile:

yes i tried a lot of different examples but i never got any result :frowning:

i do it like that and it works:

Vector3f worldCoords = standardGame.getDisplay().getWorldCoordinates(new Vector2f(x, y), 0);
Ray mouseray = new Ray(standardGame.getCamera().getLocation(),

thx a lot! with this piece of code its working quite well.

but there is a problem left. as you can see in the screenshot i draw some boxes on the top of each other. all this boxes are numbered from 0 to n. if i mousepick on one of the boxes it returns the correct number, but if i click on another box on the some “pillar” it just returns the same number. if i then go to other pillars i works fine for the first box, but wrong for all others. any ideas?


ok this problem is also solved… i was a naming problem in the boxes method :wink:

activate mipmapping for the floor. it will be much prettier then  :wink:

whats that? :smiley:



trhx. and that doesn't interfere with

Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR, Texture.FM_LINEAR);

or something like that?

ok you are still using jme 1.0:

Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);

Also, remember that the pick results are not in any specified order. You may click on a pillar and get two results (the pillar and the floor behind it) and there is no guarantee that the closer object is returned first in the list. Just a heads up.

yes thats why i only check the use node and use checkdistance. then i get the first object from the pickresults. that should be the closest pillar.

The check distance only means it will calculate the distance of the pick point from the camera, not sort the results. The sorting is still left as an exercise for you. So just grabbing the first will not always return the closest.

hmm the javadoc says

these pick results will order the data by distance from the origin of the ray.

i thought this means the shortest box is first in the rsult list?

Well, I might be wrong then!

SCM said:

<yes that is already part of my code ;:)

no its not, you've got Texture.MM_LINEAR, i wrote Texture.MM_LINEAR_LINEAR  ;)