Always visible mouse cursor

Started by elias4444, August 12, 2005, 18:32:24

Previous topic - Next topic

elias4444

I was wondering if anyone might know the solution to this problem:

How do you draw a mouse cursor and make sure that it's always visible (and not hiding inside an object who's z-value happens to be closer to the viewer). I'm using a perspective view for the game, so I'm trying to draw the cursor at z-plane that matches the screen width and height.

Any ideas?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Orangy Tang

Easiest would be to draw it last, but with depth testing disabled. Or you could use gluProject to find it's screen position and draw it there.

elias4444

=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

One little problem now - detecting if the mouse cursor has collided with an object. I'm trying to use gluUnproject or gluProject, but apparently the function no longer uses doubles (it's now using float arrays instead). Does anyone have a sample of how to do this? I've searched the boards and only found pieces. I keep getting all sorts of exceptions and errors as I try to manipulate the buffers.

I may have figured out the float arrays fine, as the error is actually focused on the GL11.glGetInteger(GL11.GL_VIEWPORT, viewport) line of my code where viewport = ByteBuffer.allocateDirect(4*4).order(ByteOrder.nativeOrder()).asIntBuffer();. I get an "IllegalArgumentException".

I've also tried viewport = BufferUtils.createIntBuffer(4*4), but get a different error focused on the gluUnProject command line where I use viewport.array().

Any help would be greatly appreciated.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Fool Running

I'm not sure about all of your problems, but IntBuffer.array() is made to return the array that the buffer is backed by (Which direct buffers don't have).
I think you want to get() with an array of the correct size.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

napier

I have a demo at
http://potatoland.com/code/gl/lwjgl_demoScene.zip that converts mouse coords to 3D space, to make an object in the scene follow the mouse.  The same logic can be used to see if the mouse is near or over an object in the scene.

For project/unproject functions go here http://potatoland.com/code/gl/GLApp.java and look for:
   void project
   void unproject

These functions call others to get the modelview matrix, projection matrix and viewport.

BTW you can also just switch to ortho mode to slap a cursor on top of a scene (  http://potatoland.com/code/gl/lwjgl_demoOrtho.zip ).  This makes it easy to exactly match the cursor to the mouse screen position.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

elias4444

Thanks everyone. Turns out, I wasn't setting the FloatBuffer large enough for the viewport. Once I changed that, it all started working great.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com