37 lines
844 B
C++
37 lines
844 B
C++
//
|
|
// Created by sebastian on 07.02.26.
|
|
//
|
|
|
|
#ifndef MOUSEPICKER_H
|
|
#define MOUSEPICKER_H
|
|
#include "glm/mat4x4.hpp"
|
|
#include "glm/vec3.hpp"
|
|
|
|
class Camera;
|
|
|
|
class MousePicker {
|
|
private:
|
|
glm::vec3 currentRay = glm::vec3(0.0f);
|
|
glm::mat4 projectionMatrix;
|
|
glm::mat4 viewMatrix;
|
|
|
|
glm::vec3 calculateMouseRay();
|
|
|
|
static glm::vec2 getNormalizedDeviceCoords(float mouseX, float mouseY);
|
|
[[nodiscard]] glm::vec4 toEyeSpace(glm::vec4 clipCoords) const;
|
|
[[nodiscard]] glm::vec3 toWorldSpace(glm::vec4 eyeCoords) const;
|
|
|
|
public:
|
|
MousePicker(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) : projectionMatrix(projectionMatrix), viewMatrix(viewMatrix) {};
|
|
|
|
[[nodiscard]] glm::vec3 getCurrentRay() const {
|
|
return currentRay;
|
|
}
|
|
|
|
void update(const Camera& camera);
|
|
};
|
|
|
|
|
|
|
|
#endif //MOUSEPICKER_H
|