Best way to do a "hover" mouse picking?

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:


public class TileSelectionBehavior extends PickMouseBehavior{
	
	private DebugPanel debug;
	private GamePanel game;
	private ArrayList<Button2D> button2D;
		
	//orientation of selection vector
	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) {
		
		// testing button2D from top to bottom
		// for screen hierarchy
		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()){
						//within a button bound
						game.clicked2D(b2D.getId());
						return;
					}
				}
			}
		//return;
		}
		}
		
		//3D picking
		pickCanvas.setShapeLocation(xpos,ypos);
		
		Point3d eyePos = pickCanvas.getStartPosition();  //viewer location
		
		PickResult pickResult = null;
		pickResult = pickCanvas.pickClosest();
						
		if (pickResult != null){
			
			//pickResultInfo(pickResult);
			if (mevent.getButton() == mevent.BUTTON1){		//left click
				if (debug != null){
					debug.clickedTile(pickResult);
				}else if (game != null){
					game.clickedTile(pickResult);
				}
			}else if (mevent.getButton() == mevent.BUTTON3){ //right click
				if (debug != null){
					//debug.clickedTile(pickResult);
				}else if (game != null){
					game.clickedRTile(pickResult);
				}
			}
		}
	}

}

You can use WakeupOnAWTEvent to wake up on mouse moved or dragged. Or you can use WakeupOnElapsedFrames(0) to wake up every frame.

Wow, thanks a lot.

I really thought i would have been harder than that. :slight_smile:

I’m curious, why not get a MouseMotionListener involved?

That would work too.