Last active
October 16, 2015 13:28
-
-
Save svenstaro/00cfeae39c1a5eb6d398 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Camera { | |
glm::vec3 pos; | |
glm::vec3 dir; | |
glm::vec3 up; | |
float fov; | |
float near_plane_dist; | |
float far_plane_dist; | |
}; | |
m_camera = Camera{{0, 0, 0}, {0, 1, 0}, {0, 0, 1}, 45.f, 0.1f, 100.f}; | |
glm::mat4 projection_matrix = glm::perspective(m_camera.fov, aspect_ratio, m_camera.near_plane_dist, m_camera.far_plane_dist); | |
glm::mat4 view_matrix = glm::lookAt(m_camera.pos, m_camera.pos + m_camera.dir, m_camera.up); | |
glm::vec3 win_coords{w, h, 0}; | |
glm::mat4 model{1.0f}; | |
glm::vec4 viewport{0, 0, width, height}; | |
glm::vec3 object_coords = glm::unProject(win_coords, model * view_matrix, projection_matrix, viewport); | |
glm::vec3 color = intersect_scene(object_coords, m_camera.dir, 0); | |
std::cout << object_coords.x << " " << object_coords.y << " " << object_coords.z << std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment