mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
add screen to world to camera
This commit is contained in:
parent
e64c68d942
commit
6aa7e3899e
@ -181,6 +181,19 @@ std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
||||
return planes;
|
||||
}
|
||||
|
||||
// example use:
|
||||
// const glm::vec4 screen {
|
||||
// (
|
||||
// glm::vec2{mouse_pos.x, window_size.y - mouse_pos.y}
|
||||
// / (glm::vec2{window_size.x, window_size.y} * 0.5f)
|
||||
// )
|
||||
// - glm::vec2{1.f, 1.f}
|
||||
// , 1.f, 1.f
|
||||
// };
|
||||
glm::vec4 Camera3D::screenToWorld(const glm::vec4& screen) const {
|
||||
return glm::inverse(getViewProjection()) * screen;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T dot34(glm::vec<3, T> lhs, glm::vec<4, T> rhs) {
|
||||
return glm::dot(lhs, glm::vec<3, T>(rhs)) + rhs.w;
|
||||
|
@ -49,6 +49,10 @@ namespace MM::OpenGL {
|
||||
|
||||
// call updateView beforehand, does not cache
|
||||
std::array<glm::vec4, 6> getFrustumPlanes(void) const;
|
||||
|
||||
// uses getViewProjection(), does not cache
|
||||
// screen has to be in NDC, xy -> [-1, 1]
|
||||
glm::vec4 screenToWorld(const glm::vec4& screen) const;
|
||||
};
|
||||
|
||||
// test if aabb in frustum
|
||||
|
Loading…
Reference in New Issue
Block a user