fix: mouse picking

This commit is contained in:
2025-05-16 11:36:24 +02:00
parent 3d544eb5ff
commit be6d8c35ba
2 changed files with 9 additions and 11 deletions

View File

@@ -232,10 +232,10 @@ public class DDDView extends GameAdaptator implements GameListener {
} }
public void run() { public void run() {
this.window.addRegularTask((delta) -> { // this.window.addRegularTask((delta) -> {
final float angle = 1f; // final float angle = 1f;
this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta); // this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
}); // });
this.window.run(); this.window.run();
// free OpenGL resources // free OpenGL resources

View File

@@ -203,11 +203,8 @@ public class Window implements Closeable {
} }
} }
private void checkCursor(int windowWidth, int windowHeight) { private void checkCursor(float cursorPosX, float cursorPosY, int windowWidth, int windowHeight) {
double x[] = new double[1]; Vector2f cursorPos = this.cam.getCursorWorldFloorPos(new Vector2f(cursorPosX, cursorPosY), windowWidth,
double y[] = new double[1];
glfwGetCursorPos(this.window, x, y);
Vector2f cursorPos = this.cam.getCursorWorldFloorPos(new Vector2f((float) x[0], (float) y[0]), windowWidth,
windowHeight); windowHeight);
Coordinate selectedCell = DDDPlacement.vectorToCoordinates(cursorPos); Coordinate selectedCell = DDDPlacement.vectorToCoordinates(cursorPos);
if (this.lastCell == null) { if (this.lastCell == null) {
@@ -236,6 +233,9 @@ public class Window implements Closeable {
ImGui.begin("Hello"); ImGui.begin("Hello");
ImGui.button("test"); ImGui.button("test");
ImVec2 mousePos = ImGui.getIO().getMousePos();
ImVec2 framePos = ImGui.getCursorScreenPos();
checkCursor(mousePos.x - framePos.x, 800 - (mousePos.y - framePos.y), 800, 800);
ImGui.image(1, new ImVec2(800, 800)); ImGui.image(1, new ImVec2(800, 800));
ImGui.end(); ImGui.end();
} }
@@ -281,8 +281,6 @@ public class Window implements Closeable {
// invoked during this call. // invoked during this call.
glfwPollEvents(); glfwPollEvents();
checkCursor(width[0], height[0]);
executeTasks(deltaTime); executeTasks(deltaTime);
glfwGetWindowSize(window, width, height); glfwGetWindowSize(window, width, height);