Ortho and Mouse

Another thread about Mice led me to look at how we display a mouse in general. It turns out that we were doing it with and Ortho mode set from the lower left corner. This was all done manually in the renderer and had to be set up in a certain fashion to guarantee it was on top. So, to fix all these shortcomings, I’ve ported Mouse to use the render queue. This means the ortho mode of render queue needed to use setOrtho instead of setOrthoCenter. If you are using ortho render queue, please note this new coordinate system.

Also, guurk, I love your GUI stuff, it’s now using the ortho queue to guarentee the mouse is on top… I also added a way to UIButton to pass in image file names that are not grabbed via a class loader. Sorry to step on toes but I needed it for our game.

btw, Mouse now extends Quad and also has a hotspot. Currently this is set to the upper left of the image, but you can change it if you want (for example, if you want a left handed house…)

Why is hotspot a vector3f not a vector2f? What is the correct way to set and get where on the screen the mouse is pointing? Also when my tutorial code now renders with the display.getRenderer.draw(mouse) it shows nothing on the screen at all.

It’s 3f because the underlying vector for translation is 3f, so was easiest. We could make it 2f, no big.

To find out where the mouse is pointing, use:


Not sure what you mean about setting where it is pointing…?

As for your tutorial code, do you mean HelloMousePick? That seems to work fine for me.

Oh, I see what you are saying about the draw thing in HelloMousePick. At the moment, the best way to render something (anything) is via calling onDraw on it. So yeah, doing it the other way won’t work. If you absolutely want to draw that way, add your mouse to a Node and call renderer.draw(node) instead. This will work because when a Node goes to draw it’s children, it calls child.onDraw(renderer). (Thus it is the same as doing it that way yourself.)

Currently this is set to the upper left of the image

In my code, if I don't set a hotspot, then my cursor's icon has to be at the lower left for the click to work. What do you mean by upper left of the image?

I mean what you’d expect for any mouse. If you had something like drawn to the screen:



The hotspot would be where the H is. (please excuse the programmer art.) This is setup by default.

Try TestUI and pay attention to where the mouse is when the rollovers activate to see this in action.

That’s what I thought you ment by hotspot but it’s not working for me like that

    // This is called every frame.  Do changing of values here.
    protected void simpleUpdate(){
        // Get the mouse input device from the jME mouse
        MouseInput thisMouse=am.getMouseInput();
        // Is button 0 down?  Button 0 is left click
        if (thisMouse.isButtonDown(0)){
            Vector2f screenPos=new Vector2f();
            // Get the position that the mouse is pointing
            // Get the world location of that X,Y value
            Vector3f worldCoords=display.getWorldCoordinates(screenPos,0);
            // Create a ray starting from the camera, and going in the direction of the mouse's location
            Ray mouseRay=new Ray(cam.getLocation(),worldCoords.subtractLocal(cam.getLocation()));
            // Does the mouse's ray intersect the box's world bounds?
            if (Intersection.intersection(mouseRay, b.getWorldBound()))

If you play around with TestMousePick you'll see it's registering a pick whenever the bottom left of the cursor is on the cube. I don't change the hotspot at all, so it should be using the default?

I still have to add image height… acording to what you said I shouldn’t. WHy?

Ah, the answer is that the offset was tested with the UIObject code which was pushing up an extra height, all fixed now.

PS: I notice your mouse is always sitting by itself… Why not add it to the root node? Then no need to render it seperately.

I want my mouse on top of everything. What’s the correct way to insure that it’s always on top?

Mouse takes care of that already as of yesterday. It uses the ORTHO queue and has it’s ZOrder set to ensure it will always be on top.

Thanks renanse… you do good work!

There are no toes being stepped on, but maybe a few needing to be kissed. :slight_smile:

LOL, if you want your toes wet, I suggest a bath instead. :wink: hehe, j/k. Happy to lend a hand where I can.