Noobie Mouse Question

Noob warning…

Hey all, I’m trying to use the mouse with LWJGL.
It seems to me that the only way to interact with
mouse event is by pulling.

I was wondering if there’s a way to do it from a
“Event” perspective. I guess I can always make
a thread that keeps pulling at it. ::slight_smile: Just wanted
to make sure I’m not reinventing the wheel for
no good reason.

Also, are any calls in org.lwjgl.input.Mouse blocking
call?

Thanks in advance,
Much appriciated.

[quote] Hey all, I’m trying to use the mouse with LWJGL.
It seems to me that the only way to interact with
mouse event is by pulling.
[/quote]
Indeed, as it should be in a game :slight_smile:

The event perspective is not needed in a game, and should be avoided. The reason for this is that a Game should be doing active rendering. That is:
1 - read input
2 - make changes in game
3 - render game
4 - synchronize with refreshrate (or some other value)
5 - goto 1

However, if you were to want such an event mechanism, you would have to do it in a secondary thread, which posted the relevant events.

No calls in Mouse are blocking, indeed in the whole API (afaik) - though they are synchronous in nature!

haha, I see,
I was just hopping for something that blocks…
Cause I’m lazy… and that makes the other thread
pulling it easier.

This whole mouse thing confuses me.
Just checking my understanding of this.

The Mouse actually has nothing todo with the
windows mouse cursor right?

Since I tried mapping the offset and the Mouse. position
and it seems to be off from time to time.
Especially when the cursor leaves the area of the
frame.

So I guess my questions are:

A) Is there a way to use the windows cursor as
the mouse cursor in the program?
Is there a way to restrict the mouse cursor from leaving
the frame area.

B) If answer to A is no, then I’m assuming I’ll have to generate my own openGL mouse cursor, is there some
example code I can look at which makes use of the setNativeCursor(Cursor cursor) function?

Thanks again.

A) yes native cursor should be enabled by default (dunno if you use some kind of framework, where it is disabled)

But you can render your own and translate it to the mouse coords. you

You can also restrict the mouse. You

Know that center of screen is 0.0

You know your resolution. Then you can calculate, the restrictions.

maxX = width/2
minX = -width/2
maxY = height/2
minY = -height/2

When I say restrict the mouse, I mean restrict the
windows native cursor, so it doesn’t mouse outside
the bounds of the frame.

I don’t see any functions in org.lwjgl.input.Mouse which
will allow me to do that.

Hang on - there are 3 types of cursors in LWJGL.
1 - System cursor, the ordinary cursor you always see.
2 - Native cursor, one set with the setNativeCursor method
3 - The Hidden, OpenGL rendered cursor (not really a cursor)

You have absolute control over 3, 1 & 2 lives their own life, they can be moved outside and generally you can’t restrict anything.

Use 1 when you don’t need any cursor control whatsoever.
Use 2 when you want a highperformance cursor that responds well, even though framerate is doing 1 FPS. OR if you need cursor animation.
Use 3 when you want to render something weird or have absolute control over its position. 3 is enabled by grapping the cursor.

Hmm… I think I get it better now…

But I’m not sure what you mean by
"Use 1 when you don’t need any cursor control whatsoever. "

k, here’s more detail to my problem.
I want to do 3D picking, and it seems that when
I call Mouse.getX() and Mouse.getY(), it doesn’t
return me the real position of the System cursor.

I guess what I want is what’s in the HWCursorTest.java
file. I’ve just been blind.

I noticed that HWCursorTest is NOT listed as one of
the demos in the READ me file of the lwjgl package.

I have the lwjgl-win32-0.9 package.
Having stumbled across it, I think its what I’m looking for.

How ever, I’m still hoping if there’s a way to just use the
native cursor…

and all the flips in the code is confusing the hell
outta me…

I guess I should brush up on NIO

EDIT: is the HWCursorTest suppose to have an
animated cursor? I can’t seem to get that to work in
the demo…

[quote]I want to do 3D picking, and it seems that when I call Mouse.getX() and Mouse.getY(), it doesn’t
return me the real position of the System cursor.
[/quote]
Correct. The problem is that we get the motion from Direct X, and the system cursor doesn’t always agree to that position (?) - it should be in the general area though. So for picking I would probably use option 3, render your own cursor. Just call setGrabbed(true); to hide the sytem cursor.

[quote]I noticed that HWCursorTest is NOT listed as one of
the demos in the READ me file of the lwjgl package.
[/quote]
Yeah, the documentation is about as in sync as the system cursor - it’s in the general area too ;D

[quote]EDIT: is the HWCursorTest suppose to have an
animated cursor? I can’t seem to get that to work in
the demo…
[/quote]
Yes it should have…
You need to click the mouse buttons (1-3) and change modes using keys N / M. I just tried it and had limited success - so I will just verify it later today.

Is there a way to read in PNG or BMP files into the
IntArray image format used for mouse cursor creation?

I haven’t had much experience working with
reading image files and their formats and what not.

The only example code would be the texture loading
functions. But that loads images into byteBuffer,
not an IntBuffer. How do I convert from 1 format to
the other?

As well, what do I set as the transparent colour for
the coursor image?

0x00 or 0xff ??