SCM
October 21, 2008, 10:55pm
1
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();
pr.clear();
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?
thx
nymon
October 21, 2008, 11:17pm
2
Do your boxes have bounding boxes? BoundingPickResults relies on bounding volumes.
SCM
October 21, 2008, 11:19pm
3
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());
source1.updateModelBound();
source1.setRenderState(ms);
boxesContainer.add(j, source1);
authorsContainer.add(j, sources.elementAt(i).getAuthor(j));
boxNode.attachChild(source1);
}
}
}
nymon
October 22, 2008, 12:01am
4
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.
SCM
October 22, 2008, 4:47pm
5
<yes that is already part of my code ;
SCM
October 22, 2008, 8:16am
6
yes i tried a lot of different examples but i never got any result
dhdd
October 22, 2008, 8:19am
7
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(),
worldCoords.subtractLocal(standardGame.getCamera().getLocation()));
SCM
October 22, 2008, 9:08am
8
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?
thx
SCM
October 22, 2008, 11:16am
9
ok this problem is also solved… i was a naming problem in the boxes method
dhdd
October 22, 2008, 11:28am
10
activate mipmapping for the floor. it will be much prettier then
dhdd
October 22, 2008, 12:26pm
12
texture.setMinificationFilter(Texture.MinificationFilter.Trilinear);
voila
SCM
October 22, 2008, 12:31pm
13
trhx. and that doesn't interfere with
Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR, Texture.FM_LINEAR);
or something like that?
dhdd
October 22, 2008, 1:29pm
14
ok you are still using jme 1.0:
Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
nymon
October 22, 2008, 4:50pm
15
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.
SCM
October 22, 2008, 4:56pm
16
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.
nymon
October 22, 2008, 4:59pm
17
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.
SCM
October 22, 2008, 5:26pm
18
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?
nymon
October 22, 2008, 6:06pm
19
Well, I might be wrong then!
dhdd
October 23, 2008, 6:25am
20
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 ;)