Listening to mouse input

GLFW documentation on Mouse Input

Java and Kotlin don’t support pointers, so you need to create a buffer to read the mouse position (StackOverflow post)

val positionX = BufferUtils.createDoubleBuffer(1)
val positionY = BufferUtils.createDoubleBuffer(1)
 
glfwGetCursorPos(window, positionX, positionY)

Mouse Picking with Ray Casting

Article by Anton Gerdelan on Mouse Picking with Ray Casting.

Tutorial on Model-View-Projection matrices in OpenGL

As a reference, code I wrote many years ago in C++:

auto Camera::calculateClickRay(int x, int y, glm::vec3& point, glm::vec3& direction) -> void {
    // Y coord is inverted in OpenGL
    int transformedY = m_windowHeight - y;
    // Transform coordinates to world space
    glm::vec3 nearPoint = glm::unProject(glm::vec3(x, transformedY, 0.0f),
                                         m_viewMatrix,
                                         m_projectionMatrix,
                                         glm::vec4(0.0, 0.0, m_windowWidth, m_windowHeight));
    // Transform coordinates of far off point to calculate direction
    glm::vec3 farPoint = glm::unProject(glm::vec3(x, transformedY, 1.0f),
                                        m_viewMatrix,
                                        m_projectionMatrix,
                                        glm::vec4(0.0, 0.0, m_windowWidth, m_windowHeight));
    point     = nearPoint;
    direction = farPoint - nearPoint;
}

JOML has unprojectRay (documentation)

Camera movement

opengl-tutorial on Keyboard and Mouse