Mouse and camera management

Hi everybody,



I’ve been searching these forums for days about mouse input, mouse management, and camera.

Alas, I haven’t been able to find all of what I was seeking.



I precise that I de-activated the FlyByCam and use the “cam”. I did my own Listeners for this purpose. I now manage the camera movements via keyboard, and am able to rotate the camera using arrow keys and mouse.



So my questions are the following :

-Is there a mouse/cursor class in jME3 that would allow me to keep the cursor restrained, invisible in the window?

-When the program starts, I set cursor at the middle of the program’s window, via

[java]Mouse.setCursorPosition(this.settings.getWidth() / 2, this.settings.getHeight() / 2);[/java]

using LWJGL mouse class (the only one I found so far to move cursor).

The first time I rotate the camera using mouse, even a very little, it moves me 90° on the right, 90° on the top. After, everything is ok. If I use keyboard, this problem doesn’t show up. If I use the mouse after the keyboard, the problem shows up, if I haven’t already been using mouse.

For exemple :

mouse (bug) → keyboard (no bug) → mouse (no bug)…

keyboard (no bug) → mouse (bug) → keyboard (no bug) → mouse (no bug)…

I use a code that is taken from FlyByCam to rotate. Is there anything wrong with code ?

[java]private void rotate(float value, Vector3f axis)

{

Matrix3f mat = new Matrix3f();

mat.fromAngleNormalAxis(InputConfiguration.ACTUAL_CAMERA_ROTATION_SPEED * value, axis);



Vector3f up = this.camera.getUp();

Vector3f left = this.camera.getLeft();

Vector3f dir = this.camera.getDirection();



mat.mult(up, up);

mat.mult(left, left);

mat.mult(dir, dir);



Quaternion q = new Quaternion();

q.fromAxes(left, up, dir);

q.normalize();



this.camera.setAxes(q);

}[/java]

-Is there another way to access window dimensions without using settings.getXXXXX()?



Thanks in advance for answers.



N.B. : I’m not quite sure it’s the right place to talk about that, but I saw other mouse threads in this section.

Do not use the LWJGL Mouse class as its going to confuse jME3 regarding the mouse position. You can use InputManager.setCursorVisible(false) to make the mouse invisible and ensure it stays in the window

I’ve already

[java]InputManager.setCursorVisible(false) [/java]

but the cursor still shows up and can be brought outside the window.

If I don’t use LWJGL mouse, how can I access and set cursor position?

@lightmax said:
I've already
[java]InputManager.setCursorVisible(false) [/java]
but the cursor still shows up and can be brought outside the window.
If I don't use LWJGL mouse, how can I access and set cursor position?

What do you mean it doesn't work? It directly calls Mouse.setGrabbed(true). If it doesn't work then you have bigger problems to worry about.

If I do not call

[java]this.flyCam.setEnabled(false);[/java]

then the mouse is grabbed.

But if I call it, then even using setCursorVisible(false) does work to grab the cursor.

@lightmax said:
If I do not call
[java]this.flyCam.setEnabled(false);[/java]
then the mouse is grabbed.
But if I call it, then even using setCursorVisible(false) does work to grab the cursor.


I assume "does work" means "does not work"...

When do you call it?

“does not work”, indeed, sorry.



I call it here :

[java]public void simpleInitApp()

{

InputMapping inputMapping = new InputMapping(inputManager, cam);

inputMapping.createBasicMapping();



this.mainCamera = cam;

cam.setLocation(new Vector3f(0, 0, 100));

this.flyCam.setDragToRotate(true);

this.flyCam.setEnabled(false);

[/java]

No, I mean where do you call setCursorVisible(false)?



The default fly cam is initialized after simpleInitApp() and so will override any cursor settings you set in simpleInitApp().

Note: I’m still unclear on what you are trying to ultimately accomplish. Are you trying to get rid of fly cam and have your own?

I call it at the end of simpleInitApp()



For your note, you’re right.

If you want to completely get rid of flyCam then in simpleInit you can remove the FlyCamAppState.



stateManager.detach( stateManager.getState(FlyCamAppState.class) );

It now works perfectly, thanks to the two of you!



By the way, is the code I used to rotate the camera perfectly accurate?