Example of an FPS camera

I have trouble making sense of this statement.

1 Like


This will grow with time: (-69352.0, -234.0)

1 Like

I’m pretty sure you are mistaken. When the cursor is disabled, InputManager is constantly resetting the cursor position as I recall.

1 Like

These are real numbers, I moved the mouse for 1 minute.

1 Like

Yeah, I’m looking at the code and you’re right. Part of a larger problem I guess.

Still, I guess it comes up rarely that a user would turn one direction significantly more often than another unless the game is clamping input. JME should probably provide a way to reset the internal counters in that case.

1 Like

Last time I meet this problem, I tried to correct the mouse position with a fake cursor appstate. It works fine for me.

private Camera cam;
private Vector2f position;

public void initialize(Application app) {
	cam = app.getCamera();
	position = new Vector2f();

	// ...

private RawInputListener inputListener = new RawInputListener() {
	private float x;
	private float y;
	public void onMouseMotionEvent(MouseMotionEvent evt) {
		// get current position
		x = evt.getX();
		y = evt.getY();

		// keep them in screen space
		x = FastMath.clamp(x, 0, cam.getWidth());
		y = FastMath.clamp(y, 0, cam.getHeight());

		position.x = x;
		position.y = y;
	public void beginInput() {}
	public void endInput() {}
	public void onJoyAxisEvent(JoyAxisEvent evt) {}
	public void onJoyButtonEvent(JoyButtonEvent evt) {}
	public void onMouseButtonEvent(MouseButtonEvent evt) {}
	public void onKeyEvent(KeyInputEvent evt) {}
	public void onTouchEvent(TouchEvent evt) {}

public Vector2f getPosition() {
	return position;

It can also get deltaX & deltaY from MouseMotionEvent

int dx = evt.getDX();
int dy = evt.getDY();

I think you can move camera with those values. Just ignore what inputManager.getCursorPosition() provides you.


Yes, in fact most camera movement stuff does exactly that… just uses the DX/DY.

1 Like

Luxurious for resetting mouse positions. It remains to write another code for the four mouse axes based on the listeners. And you can compare the number of lines with the assembler.

1 Like

Turns out, posting snarky comments is way more constructive way of learning something, than to RTFM.


If you think that you are smarter when pointing to documentation, you are mistaken.
Paul He claimed that the coordinates are reset, then suddenly it was not so.

1 Like

Let’s focus on the problem.

I think if you want a FPS camera with sensitivity, the easiest way is extends the FlyByCamera and add a sensitivity field to it. Override rotateCamera() method and apply sensitivity in it.

1 Like

Thank you, but I learned this. In my opinion, there are many unnecessary actions.

1 Like

I was mistaken. It happens. In the 25+ years that I’ve been developing software professionally, I have used a lot of graphics frameworks. Some of them reset the coordinates and some don’t. So I looked in the code and found out I was wrong.

The reason it doesn’t matter to any of the rest of our camera implementations is because we are using the delta X and delta Y and never use the accumulated cursor position because it’s ridiculous to do so.

I already posted an FPS camera implementation that has the ability control sensitivity (even separate for each type of input). It has no issues with frame rate, etc…

Since it seems like you are making a client/server application then this all matters even less.

In case it’s useful, here is a decent background on network architecture for real time games:

Some of those concepts have been implemented in this framework:

With working examples…

Here for non-entity-system version:

And here for the superior entity-system version:

It’s not exactly an FPS but the ideas are directly related.


Sometimes you need to see sarcasm.

This is the message that assembler will have the same number of rows and jME3, than say OpenGL -SetCursorPos (X, Y). :wink:

1 Like

I’ve updated the code, now it works well. Except for increasing mouse values ​​X Y :confused:

1 Like

…which ultimately don’t matter because you shouldn’t be using them.

1 Like

And why should not I use them? Is it a function for statistics of mouse movement?


I hint that this is a useless thing in jME3

1 Like

getCursorPosition() is useful for getting the cursor position on the screen when the cursor is enabled. Note how many times I used the word “cursor” in that sentence.

For tracking non-cursor mouse movement it is totally useless… and you are likely the only one really trying to do it.

Register a listener. That listener will be notified about deltaX and deltaY every frame there is movement. You don’t need cursor position unless you want to know the position of the cursor.

Edit: blah blah… which is in my camera example… blah blah… repeating myself…blah blah.

1 Like

???Well, what to use to set the cursor to the desired position, I’ll add for clarity, when it will be displayed???

Maybe by force of thought this is done.

1 Like

Are you trying to create an FPS camera or not? Seems weird to display the mouse cursor in an FPS camera.

And when the cursor is displayed on screen then [quote=“AdiDOS, post:30, topic:38689”]
Except for increasing mouse values ​​X Y

is not an issue because the cursor position is clamped to the window/screen.

1 Like