Fixed an issue with the GLFW mouse input coordinates not being mapped correctly.
Renamed input classes to GlfwXXX.
This commit is contained in:
parent
352a532730
commit
971b9524bd
@ -45,9 +45,9 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
public class LwjglKeyInput implements KeyInput {
|
public class GlfwKeyInput implements KeyInput {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(LwjglKeyInput.class.getName());
|
private static final Logger logger = Logger.getLogger(GlfwKeyInput.class.getName());
|
||||||
|
|
||||||
private LwjglWindow context;
|
private LwjglWindow context;
|
||||||
private RawInputListener listener;
|
private RawInputListener listener;
|
||||||
@ -55,7 +55,7 @@ public class LwjglKeyInput implements KeyInput {
|
|||||||
private GLFWKeyCallback keyCallback;
|
private GLFWKeyCallback keyCallback;
|
||||||
private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>();
|
private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>();
|
||||||
|
|
||||||
public LwjglKeyInput(LwjglWindow context) {
|
public GlfwKeyInput(LwjglWindow context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
@ -50,9 +50,17 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
public class LwjglMouseInput implements MouseInput {
|
/**
|
||||||
|
* Captures mouse input using GLFW callbacks. It then temporarily stores these in event queues which are processed in the
|
||||||
|
* {@link #update()} method. Due to some of the GLFW button id's there is a conversion method in this class which will
|
||||||
|
* convert the GLFW left, middle and right mouse button to JME3 left, middle and right button codes.
|
||||||
|
*
|
||||||
|
* @author Daniel Johansson (dannyjo)
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public class GlfwMouseInput implements MouseInput {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(LwjglMouseInput.class.getName());
|
private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName());
|
||||||
|
|
||||||
private LwjglWindow context;
|
private LwjglWindow context;
|
||||||
private RawInputListener listener;
|
private RawInputListener listener;
|
||||||
@ -67,7 +75,7 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
private Queue<MouseMotionEvent> mouseMotionEvents = new LinkedList<MouseMotionEvent>();
|
private Queue<MouseMotionEvent> mouseMotionEvents = new LinkedList<MouseMotionEvent>();
|
||||||
private Queue<MouseButtonEvent> mouseButtonEvents = new LinkedList<MouseButtonEvent>();
|
private Queue<MouseButtonEvent> mouseButtonEvents = new LinkedList<MouseButtonEvent>();
|
||||||
|
|
||||||
public LwjglMouseInput(LwjglWindow context) {
|
public GlfwMouseInput(final LwjglWindow context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +86,7 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
int xDelta;
|
int xDelta;
|
||||||
int yDelta;
|
int yDelta;
|
||||||
int x = (int) Math.round(xpos);
|
int x = (int) Math.round(xpos);
|
||||||
int y = (int) Math.round(ypos);
|
int y = context.getSettings().getHeight() - (int) Math.round(ypos);
|
||||||
|
|
||||||
if (mouseX == 0) {
|
if (mouseX == 0) {
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
@ -94,7 +102,7 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
mouseY = y;
|
mouseY = y;
|
||||||
|
|
||||||
if (xDelta != 0 || yDelta != 0) {
|
if (xDelta != 0 || yDelta != 0) {
|
||||||
final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(x, y * -1, xDelta, yDelta * -1, mouseWheel, 0);
|
final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(x, y, xDelta, yDelta, mouseWheel, 0);
|
||||||
mouseMotionEvent.setTime(getInputTimeNanos());
|
mouseMotionEvent.setTime(getInputTimeNanos());
|
||||||
mouseMotionEvents.add(mouseMotionEvent);
|
mouseMotionEvents.add(mouseMotionEvent);
|
||||||
}
|
}
|
||||||
@ -115,7 +123,7 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
glfwSetMouseButtonCallback(context.getWindowHandle(), mouseButtonCallback = new GLFWMouseButtonCallback() {
|
glfwSetMouseButtonCallback(context.getWindowHandle(), mouseButtonCallback = new GLFWMouseButtonCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(final long window, final int button, final int action, final int mods) {
|
public void invoke(final long window, final int button, final int action, final int mods) {
|
||||||
final MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(button, action == GLFW_PRESS, mouseX, mouseY);
|
final MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(convertButton(button), action == GLFW_PRESS, mouseX, mouseY);
|
||||||
mouseButtonEvent.setTime(getInputTimeNanos());
|
mouseButtonEvent.setTime(getInputTimeNanos());
|
||||||
mouseButtonEvents.add(mouseButtonEvent);
|
mouseButtonEvents.add(mouseButtonEvent);
|
||||||
}
|
}
|
||||||
@ -131,7 +139,7 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getButtonCount() {
|
public int getButtonCount() {
|
||||||
return 2; // TODO: How to determine this?
|
return GLFW_MOUSE_BUTTON_LAST + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
@ -186,4 +194,23 @@ public class LwjglMouseInput implements MouseInput {
|
|||||||
glfwSetCursor(context.getWindowHandle(), cursor);
|
glfwSetCursor(context.getWindowHandle(), cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simply converts the GLFW button code to a JME button code. If there is no match it just returns the GLFW button
|
||||||
|
* code. Bare in mind GLFW supports 8 different mouse buttons.
|
||||||
|
*
|
||||||
|
* @param glfwButton the raw GLFW button index.
|
||||||
|
* @return the mapped {@link MouseInput} button id.
|
||||||
|
*/
|
||||||
|
private int convertButton(final int glfwButton) {
|
||||||
|
if (glfwButton == GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
return MouseInput.BUTTON_LEFT;
|
||||||
|
} else if(glfwButton == GLFW_MOUSE_BUTTON_MIDDLE) {
|
||||||
|
return MouseInput.BUTTON_MIDDLE;
|
||||||
|
} else if(glfwButton == GLFW_MOUSE_BUTTON_RIGHT) {
|
||||||
|
return MouseInput.BUTTON_RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return glfwButton;
|
||||||
|
}
|
||||||
}
|
}
|
@ -33,8 +33,8 @@
|
|||||||
package com.jme3.system.lwjgl;
|
package com.jme3.system.lwjgl;
|
||||||
|
|
||||||
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
||||||
import com.jme3.input.lwjgl.LwjglKeyInput;
|
import com.jme3.input.lwjgl.GlfwKeyInput;
|
||||||
import com.jme3.input.lwjgl.LwjglMouseInput;
|
import com.jme3.input.lwjgl.GlfwMouseInput;
|
||||||
import com.jme3.renderer.Renderer;
|
import com.jme3.renderer.Renderer;
|
||||||
import com.jme3.renderer.RendererException;
|
import com.jme3.renderer.RendererException;
|
||||||
import com.jme3.renderer.lwjgl.LwjglGL;
|
import com.jme3.renderer.lwjgl.LwjglGL;
|
||||||
@ -71,8 +71,8 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
|
|
||||||
protected AppSettings settings = new AppSettings(true);
|
protected AppSettings settings = new AppSettings(true);
|
||||||
protected Renderer renderer;
|
protected Renderer renderer;
|
||||||
protected LwjglKeyInput keyInput;
|
protected GlfwKeyInput keyInput;
|
||||||
protected LwjglMouseInput mouseInput;
|
protected GlfwMouseInput mouseInput;
|
||||||
protected GlfwJoystickInput joyInput;
|
protected GlfwJoystickInput joyInput;
|
||||||
protected Timer timer;
|
protected Timer timer;
|
||||||
protected SystemListener listener;
|
protected SystemListener listener;
|
||||||
@ -123,16 +123,15 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
if (JmeSystem.isLowPermissions()) {
|
if (JmeSystem.isLowPermissions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
||||||
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
||||||
}
|
}
|
||||||
if (settings.useJoysticks()) {
|
|
||||||
//NativeLibraryLoader.loadNativeLibrary("jinput", true);
|
|
||||||
//NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true);
|
|
||||||
}
|
|
||||||
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
||||||
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
|
NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,11 +235,7 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
createdLock.notifyAll();
|
createdLock.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (renderable.get()) {
|
initContextFirstTime();
|
||||||
initContextFirstTime();
|
|
||||||
//} else {
|
|
||||||
// assert getType() == Type.Canvas;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
|
@ -37,12 +37,11 @@ import com.jme3.input.KeyInput;
|
|||||||
import com.jme3.input.MouseInput;
|
import com.jme3.input.MouseInput;
|
||||||
import com.jme3.input.TouchInput;
|
import com.jme3.input.TouchInput;
|
||||||
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
||||||
import com.jme3.input.lwjgl.LwjglKeyInput;
|
import com.jme3.input.lwjgl.GlfwKeyInput;
|
||||||
import com.jme3.input.lwjgl.LwjglMouseInput;
|
import com.jme3.input.lwjgl.GlfwMouseInput;
|
||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
import com.jme3.system.JmeContext;
|
import com.jme3.system.JmeContext;
|
||||||
import com.jme3.system.JmeSystem;
|
import com.jme3.system.JmeSystem;
|
||||||
import org.lwjgl.PointerBuffer;
|
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
@ -256,7 +255,6 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|||||||
if (window != 0) {
|
if (window != 0) {
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
}
|
}
|
||||||
//glfwTerminate();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
listener.handleError("Failed to destroy context", ex);
|
listener.handleError("Failed to destroy context", ex);
|
||||||
}
|
}
|
||||||
@ -269,8 +267,10 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new Thread(this, THREAD_NAME).start();
|
new Thread(this, THREAD_NAME).start();
|
||||||
if (waitFor)
|
|
||||||
|
if (waitFor) {
|
||||||
waitFor(true);
|
waitFor(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -417,14 +417,14 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|||||||
|
|
||||||
public MouseInput getMouseInput() {
|
public MouseInput getMouseInput() {
|
||||||
if (mouseInput == null) {
|
if (mouseInput == null) {
|
||||||
mouseInput = new LwjglMouseInput(this);
|
mouseInput = new GlfwMouseInput(this);
|
||||||
}
|
}
|
||||||
return mouseInput;
|
return mouseInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyInput getKeyInput() {
|
public KeyInput getKeyInput() {
|
||||||
if (keyInput == null) {
|
if (keyInput == null) {
|
||||||
keyInput = new LwjglKeyInput(this);
|
keyInput = new GlfwKeyInput(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyInput;
|
return keyInput;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user