How to implement mouseover in 3d world

I wonder how to implement something like mouseover effects in the 3d world (not the GUI).
For example make some geometry glow when the mouse pointer is entering its bounds and stop the glow when mosuepointer leaves its bounds.
From the top of my head this would mean shooting a picking ray from the mousecurser each update loop and analyse the results, or at least every time the mouse moves.
But wouldnt that be very costly ? Not sure how much memory and processing power a ray uses, but i imagine that shooting a ray each update loop is something you should try to prevent ?
Maybe i’m wrong and it is not realy an issue, thats why i am asking.

Has anyone done something like this allready or knows best practice to implement somehting like this ?

Please watch first half minute of

Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f); Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f); direction.subtractLocal(origin).normalizeLocal();
	Ray ray = new Ray(origin, direction);
	CollisionResults results = new CollisionResults();
	sceneNode.collideWith(ray, results);
	return results;
It is quite fast - early rejection by bounds works quite well. I have user info on each geometry to allow quickly locate my app structure for that colission. After that, to do actual higlight, I use if ( g.getMaterial().getMaterialDef().getMaterialParam("GlowColor") != null ) { g.getMaterial().setColor("GlowColor", markColor); } recursively on each geometry in my model hierarchy. For the actual selection effect after click (models become more visible) I just add ambient light to it Node mainNode = visModel.getMainNode(); ambient = new AmbientLight(); ambient.setColor(new ColorRGBA(1,1,1,1)); mainNode.addLight(ambient); and of curse remove it after something else is selected.

Edit: java tags seems to be not working anymore?

1 Like

Thanks a lot, if it isn’t a big problem doing this each update loop i probably would have gone the way you describe.
Just wanted to make sure i don’t do anything stupid here :wink:
Altho maybe it is even better to listen to mouse movement and shoot the ray there, this is probably a lot less then each update, but on the downside something wont be highlighted if it moves below the mouse curser on its own accord. Have to play arround with it, but your examples helped me a lot.

Ray collisions aren’t very expensive and it is standard to run them every frame. Of course that can depend on how many objects you have in your scene graph. I generally add all spatials that are pickable to a single node. It weeds out all the other stuff.