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() {
this.window.addRegularTask((delta) -> {
final float angle = 1f;
this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
});
// this.window.addRegularTask((delta) -> {
// final float angle = 1f;
// this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
// });
this.window.run();
// free OpenGL resources

View File

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