-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse.java
More file actions
60 lines (51 loc) · 1.6 KB
/
Copy pathMouse.java
File metadata and controls
60 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
ahbejarano
Camera wrapper class.
*/
package geetransit.minecraft05.engine;
import org.joml.Vector2f;
import static org.lwjgl.glfw.GLFW.*;
public class Mouse {
private final Vector2f current;
private final Vector2f movement;
private Vector2f previous;
private boolean inside = false;
private boolean left = false;
private boolean right = false;
public Mouse() {
this.current = new Vector2f(-1, -1);
this.movement = new Vector2f();
this.previous = new Vector2f(0, 0);
}
public void init(Window window) {
glfwSetCursorPosCallback(window.getHandle(), (handle, x, y) -> {
this.current.x = (float) x;
this.current.y = (float) y;
});
glfwSetCursorEnterCallback(window.getHandle(), (handle, entered) -> {
this.inside = entered;
});
glfwSetMouseButtonCallback(window.getHandle(), (handle, button, action, mode) -> {
if (button == GLFW_MOUSE_BUTTON_1) this.left = (action == GLFW_PRESS);
if (button == GLFW_MOUSE_BUTTON_2) this.right = (action == GLFW_PRESS);
});
}
public Vector2f getMovement() { return this.movement; }
public Vector2f getCurrent() { return this.current; }
public boolean isInside() { return this.inside; }
public boolean isLeft() { return this.left; }
public boolean isRight() { return this.right; }
public void input(Window window) {
this.current.sub(this.previous, this.movement);
this.movement.div(window.getTargetUps() * window.getElapsedTime());
this.previous.set(this.current);
}
public String toString() {
return String.format(
"<%s movement=%s current=%s>",
this.getClass().getSimpleName(),
this.getMovement(),
this.getCurrent()
);
}
}