Hello,
I need a way to get my program to do the mouse picking while the mouse is hovering over something else. It needs to be done, well... always, all the time. This is for my 3D map, which is composed of tiles, and i'd like the tile under the cursor to be highlighted in some way.
Currently, the picking only works when the mouse is clicked, left or right button, how do i change this?
I guess it would probably be really cpu-intensive to do it all the time, what's the best approach?
Here's my picking code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| public class TileSelectionBehavior extends PickMouseBehavior{ private DebugPanel debug; private GamePanel game; private ArrayList<Button2D> button2D; private static final Vector3d SELVEC = new Vector3d(0.0, 0.0, 1.0); public TileSelectionBehavior( Canvas3D canvas, BranchGroup root, Bounds bounds, DebugPanel debug ){ super(canvas, root, bounds); setSchedulingBounds(bounds); this.debug = debug; this.game = null; pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO); } public TileSelectionBehavior( Canvas3D canvas, BranchGroup root, Bounds bounds, GamePanel game, ArrayList<Button2D> button2D){ super(canvas, root, bounds); setSchedulingBounds(bounds); this.game = game; this.debug = null; this.button2D = button2D; pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO); }
public void updateScene(int xpos, int ypos) { if (debug == null){ if (button2D.size() > 0 ){ for(int i = 0; i < button2D.size(); i++){ Button2D b2D = button2D.get(i); if (xpos > b2D.getPosX() & xpos < b2D.getPosX() + b2D.getWidth()){ if (ypos > b2D.getPosY() & ypos < b2D.getPosY()+ b2D.getHeight()){ game.clicked2D(b2D.getId()); return; } } } } } pickCanvas.setShapeLocation(xpos,ypos); Point3d eyePos = pickCanvas.getStartPosition(); PickResult pickResult = null; pickResult = pickCanvas.pickClosest(); if (pickResult != null){ if (mevent.getButton() == mevent.BUTTON1){ if (debug != null){ debug.clickedTile(pickResult); }else if (game != null){ game.clickedTile(pickResult); } }else if (mevent.getButton() == mevent.BUTTON3){ if (debug != null){ }else if (game != null){ game.clickedRTile(pickResult); } } } }
} |